Skip to content

Commit 5cb17aa

Browse files
committed
Merge branch 'master' of https://github.com/google/nsjail
2 parents d5981cc + f6df076 commit 5cb17aa

File tree

3 files changed

+35
-8
lines changed

3 files changed

+35
-8
lines changed

Makefile

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,30 @@ install: $(BIN)
132132
install -m 755 -d $(DESTDIR)$(MANDIR)
133133
install -m 644 nsjail.1 $(DESTDIR)$(MANDIR)
134134

135+
define run_test
136+
@echo "Testing: $(1) (expecting exit code $(2))"; \
137+
($(1)); ret=$$?; \
138+
if [ "$$ret" -ne "$(2)" ]; then \
139+
echo "❌ FAIL: '$(1)' returned $$ret, expected $(2)"; \
140+
exit 1; \
141+
else \
142+
echo "✅ PASS: '$(1)' returned $$ret"; \
143+
fi
144+
endef
145+
146+
.PHONY: test
147+
test: $(BIN)
148+
$(call run_test, ./nsjail -q -Mo --rw --chroot / --user 99999 --group 99999 -- /bin/bash -c 'touch $(HOME)/nsjail_test && exit 77', 77)
149+
$(call run_test, ./nsjail -q -Mo --chroot / --user 99999 --group 99999 -- /bin/bash -c 'touch $(HOME)/nsjail_test || exit 77', 77)
150+
$(call run_test, rm -f $(HOME)/nsjail_test, 0)
151+
$(call run_test, ./nsjail --config configs/bash-with-fake-geteuid.cfg -q -t 1, 137)
152+
$(call run_test, ./nsjail --config configs/bash-with-fake-geteuid.json -q -t 1, 137)
153+
$(call run_test, ./nsjail --config configs/static-busybox-with-execveat.cfg -q -t 1, 137)
154+
$(call run_test, ./nsjail --config configs/home-documents-with-xorg-no-net.cfg -q -- /bin/true, 0)
155+
$(call run_test, ./nsjail --config configs/home-documents-with-xorg-no-net.cfg -q -- /bin/false, 1)
156+
$(call run_test, ./nsjail --config configs/firefox-with-net-wayland.cfg -q -t 3, 137)
157+
$(call run_test, ./nsjail --config configs/chromium-with-net-wayland.cfg -q -t 3, 137)
158+
135159
# Dependencies (Generated by makedepend)
136160
# DO NOT DELETE THIS LINE -- make depend depends on it.
137161

@@ -150,7 +174,7 @@ mnt.o: mnt.h nsjail.h config.pb.h logs.h macros.h mnt_legacy.h mnt_newapi.h
150174
mnt.o: subproc.h util.h
151175
mnt_legacy.o: mnt_legacy.h mnt.h nsjail.h config.pb.h logs.h macros.h util.h
152176
mnt_newapi.o: mnt_newapi.h mnt.h nsjail.h config.pb.h logs.h util.h
153-
net.o: net.h nsjail.h config.pb.h logs.h util.h
177+
net.o: net.h nsjail.h config.pb.h logs.h macros.h util.h
154178
nsjail.o: nsjail.h config.pb.h cgroup2.h cmdline.h logs.h macros.h net.h
155179
nsjail.o: sandbox.h subproc.h util.h
156180
pid.o: pid.h nsjail.h config.pb.h logs.h subproc.h

mnt_legacy.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -333,9 +333,9 @@ std::unique_ptr<std::string> buildMountTree(nsj_t* nsj, std::vector<mnt::mount_t
333333
}
334334

335335
if (!nsj->is_root_rw) {
336-
if (mount(destdir->c_str(), destdir->c_str(), nullptr, MS_REMOUNT | MS_RDONLY,
337-
nullptr) == -1) {
338-
PLOG_E("mount('%s', MS_REMOUNT|MS_RDONLY)", destdir->c_str());
336+
if (mount(destdir->c_str(), destdir->c_str(), nullptr,
337+
MS_REMOUNT | MS_BIND | MS_RDONLY, nullptr) == -1) {
338+
PLOG_E("mount('%s', MS_REMOUNT|MS_BIND|MS_RDONLY)", destdir->c_str());
339339
return nullptr;
340340
}
341341
}

net.cc

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include <arpa/inet.h>
2525
#include <errno.h>
2626
#include <fcntl.h>
27-
#include <linux/prctl.h>
2827
#include <net/if.h>
2928
#include <net/route.h>
3029
#include <netinet/in.h>
@@ -49,16 +48,20 @@
4948
#include <string>
5049

5150
#include "logs.h"
51+
#include "macros.h"
5252
#include "util.h"
5353

54+
#define STR_(x) #x
55+
#define STR(x) STR_(x)
56+
5457
/* Embed pasta inside this binary */
5558
__asm__("\n"
5659
" .section .rodata\n"
5760
" .local pasta_start\n"
5861
" .local pasta_end\n"
5962
"pasta_start:\n"
6063
#if defined(PASTA_BIN_PATH)
61-
" .incbin \"" PASTA_BIN_PATH "\"\n"
64+
" .incbin " STR(PASTA_BIN_PATH) "\n"
6265
#endif // defined(PASTA_BIN_PATH)
6366
"pasta_end:\n"
6467
"\n");
@@ -70,8 +73,8 @@ static int getPastaFd() {
7073
extern uint8_t* pasta_start;
7174
extern uint8_t* pasta_end;
7275
ptrdiff_t len = (uintptr_t)&pasta_end - (uintptr_t)&pasta_start;
73-
if (len <= 8) { /* Some reasonably safe value accounting for alignment */
74-
LOG_D("'pasta' is not embedded in this file");
76+
if (len <= 16) { /* Some reasonably safe value accounting for alignment */
77+
LOG_D("'pasta' is not embedded in this file, len=%td (<=16)", len);
7578
return -1;
7679
}
7780

0 commit comments

Comments
 (0)