Skip to content

Commit 624ddc6

Browse files
committed
net/pasta: control inbound traffic
1 parent 425c871 commit 624ddc6

File tree

7 files changed

+29
-18
lines changed

7 files changed

+29
-18
lines changed

cmdline.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,8 @@ std::unique_ptr<nsjconf_t> parseArgs(int argc, char* argv[]) {
535535
nsjconf->iface_vs_mo = "private";
536536
nsjconf->disable_tsc = false;
537537
nsjconf->forward_signals = false;
538-
nsjconf->use_pasta = false;
538+
nsjconf->user_net.use_pasta = false;
539+
nsjconf->user_net.inbound = false;
539540
nsjconf->user_net.ip = "10.0.0.2";
540541
nsjconf->user_net.mask = "255.255.255.0";
541542
nsjconf->user_net.gw = "10.0.0.1";
@@ -757,7 +758,7 @@ std::unique_ptr<nsjconf_t> parseArgs(int argc, char* argv[]) {
757758
addEnv(nsjconf.get(), optarg);
758759
break;
759760
case 0x709:
760-
nsjconf->use_pasta = true;
761+
nsjconf->user_net.use_pasta = true;
761762
break;
762763
case 'u': {
763764
std::vector<std::string> subopts = util::strSplit(optarg, ':');

config.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,8 @@ static bool parseInternal(nsjconf_t* nsjconf, const nsjail::NsJailConfig& njc) {
285285
nsjconf->forward_signals = njc.forward_signals();
286286

287287
if (njc.has_user_net()) {
288-
nsjconf->use_pasta = njc.user_net().enable();
288+
nsjconf->user_net.use_pasta = njc.user_net().enable();
289+
nsjconf->user_net.inbound = njc.user_net().inbound();
289290
nsjconf->user_net.ip = njc.user_net().ip();
290291
nsjconf->user_net.mask = njc.user_net().mask();
291292
nsjconf->user_net.gw = njc.user_net().gw();

config.proto

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -277,13 +277,14 @@ message NsJailConfig {
277277

278278
message UserNet {
279279
optional bool enable = 1 [default = false];
280-
optional string ip = 2 [default = "10.0.0.2"];
281-
optional string mask = 3 [default = "255.255.255.0"];
282-
optional string gw = 4 [default = "10.0.0.1"];
283-
optional string ip6 = 5 [default = "fc00::2"];
284-
optional string mask6 = 6 [default = "64"];
285-
optional string gw6 = 7 [default = "fc00::1"];
286-
optional string ns_iface = 8 [default = "eth0"];
280+
optional bool inbound = 2 [default = false];
281+
optional string ip = 3 [default = "10.0.0.2"];
282+
optional string mask = 4 [default = "255.255.255.0"];
283+
optional string gw = 5 [default = "10.0.0.1"];
284+
optional string ip6 = 6 [default = "fc00::2"];
285+
optional string mask6 = 7 [default = "64"];
286+
optional string gw6 = 8 [default = "fc00::1"];
287+
optional string ns_iface = 9 [default = "eth0"];
287288
}
288289
optional UserNet user_net = 96;
289290
}

configs/bash-with-fake-geteuid.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ clone_newcgroup: true
6363

6464
user_net {
6565
enable: true
66+
inbound: true
6667
}
6768

6869
uidmap {

configs/znc-with-net.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ rlimit_nofile: 128
3030
clone_newnet: true
3131
user_net {
3232
enable: true
33+
inbound: true
3334
}
3435

3536
mount {

net.cc

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,14 @@ static bool spawnPasta(nsjconf_t* nsjconf, int pid) {
191191
argv.push_back("-f");
192192
argv.push_back("-q");
193193

194-
if (!nsjconf->user_net.ip.empty()) {
194+
if (!nsjconf->user_net.inbound) {
195+
argv.push_back("-t");
196+
argv.push_back("none");
197+
}
198+
199+
if (nsjconf->user_net.ip.empty()) {
200+
argv.push_back("-6");
201+
} else {
195202
argv.push_back("-a");
196203
argv.push_back(nsjconf->user_net.ip.c_str());
197204
if (!nsjconf->user_net.mask.empty()) {
@@ -204,7 +211,9 @@ static bool spawnPasta(nsjconf_t* nsjconf, int pid) {
204211
}
205212
}
206213

207-
if (!nsjconf->user_net.ip6.empty()) {
214+
if (nsjconf->user_net.ip6.empty()) {
215+
argv.push_back("-4");
216+
} else {
208217
argv.push_back("-a");
209218
argv.push_back(nsjconf->user_net.ip6.c_str());
210219

@@ -214,10 +223,6 @@ static bool spawnPasta(nsjconf_t* nsjconf, int pid) {
214223
}
215224
}
216225

217-
if (nsjconf->user_net.ip6.empty()) {
218-
argv.push_back("-4");
219-
}
220-
221226
if (!nsjconf->user_net.nsiface.empty()) {
222227
argv.push_back("-I");
223228
argv.push_back(nsjconf->user_net.nsiface.c_str());
@@ -253,7 +258,7 @@ static bool spawnPasta(nsjconf_t* nsjconf, int pid) {
253258
}
254259

255260
bool initNsFromParent(nsjconf_t* nsjconf, int pid) {
256-
if (nsjconf->use_pasta) {
261+
if (nsjconf->user_net.use_pasta) {
257262
if (!nsjconf->clone_newnet) {
258263
LOG_E("Support for User-Mode Networking requested (pasta) but CLONE_NEWNET "
259264
"is not enabled");

nsjail.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,9 @@ struct nsjconf_t {
148148
std::string iface_vs_mo;
149149
bool disable_tsc;
150150
bool forward_signals;
151-
bool use_pasta;
152151
struct {
152+
bool use_pasta;
153+
bool inbound;
153154
std::string ip;
154155
std::string mask;
155156
std::string gw;

0 commit comments

Comments
 (0)