Skip to contentSkip to conversation

close_range01: Drop CAP_SYS_ADMIN

PATCH New Richard Palethorpe 2 participants 4 messages Feb 16, 2021

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 close_range01: Drop CAP_SYS_ADMIN

---

V2: Try Closing the path file descriptor at the end if it was opened
to prevent hitting the FD limit with -i

 testcases/kernel/syscalls/close_range/close_range01.c | 4 ++++
 1 file changed, 4 insertions(+)
testcases/kernel/syscalls/close_range/close_range01.c +4 -0
index f4be60bb3..56def2426 100644
@@ -197,6 +197,10 @@ static struct tst_test test = {
 	.all_filesystems = 1,
 	.needs_root = 1,
 	.test = run,
+	.caps = (struct tst_cap []) {
+		TST_CAP(TST_CAP_DROP, CAP_SYS_ADMIN),
+		{}
+	},
 	.taint_check = TST_TAINT_W | TST_TAINT_D,
 	.setup = setup,
 	.tags = (const struct tst_tag[]) {
Signature · 1 line
2.30.0
#1 lore raw

PATCH v2 2/2 close_range02: Add simpler test and Check invalid params

This adds some coverage for invalid parameters and a min fd above or on the limits. There is also some overlap with close_range01, but this test is simpler and has less requirements.

---

V2: Try Closing the path file descriptor at the end if it was opened
to prevent hitting the FD limit with -i

This does not include a check for EMFILE during unsharing because it only happens if the _system's_ maximum file count is reduced after clone and before unshare. This should probably go into a separate test. Also it seems like a corner case which is not likely to happen in practice and can not be done without CAP_SYS_ADMIN AFAICT.

More tests could be added, but I think we can leave it to the fuzzers to find where coverage is lacking now that we have the basics. Also Cyrils and I discussed creating generic data copying tests which copy data between various types of FD (file system files, pipes, sockets, etc.) using various system calls (e.g (vm)splice, send/recvmsg, write) and these could also use close_range() in addtion to close(). I think that would be more productive than adding just to close_range.

 runtest/syscalls                              |   1 +
 .../kernel/syscalls/close_range/.gitignore    |   1 +
 .../syscalls/close_range/close_range02.c      | 116 ++++++++++++++++++
 3 files changed, 118 insertions(+)
 create mode 100644 testcases/kernel/syscalls/close_range/close_range02.c
runtest/syscalls +1 -0
index c71f2b371..ae47a6d5e 100644
@@ -121,6 +121,7 @@ close02 close02
 close08 close08
 
 close_range01 close_range01
+close_range02 close_range02
 
 confstr01 confstr01
 
testcases/kernel/syscalls/close_range/.gitignore +1 -0
index dddc1b7f8..4b8bab442 100644
@@ -1 +1,2 @@
 close_range01
+close_range02
\ No newline at end of file
testcases/kernel/syscalls/close_range/close_range02.c new file +116 -0

116 lines not on this page · raw message

Signature · 1 line
2.30.0
#2 lore raw

PATCH v2 2/2 close_range02: Add simpler test and Check invalid params

Hi Richard,

Quoted 10 lines

This adds some coverage for invalid parameters and a min fd above or on the limits. There is also some overlap with close_range01, but this test is simpler and has less requirements.

---

V2: Try Closing the path file descriptor at the end if it was opened
to prevent hitting the FD limit with -i

Thanks! And yes, using close_range() is much better than plain close().

Waiting little longer for feedback before merging.

Kind regards,
Petr

#3 lore raw

PATCH v2 2/2 close_range02: Add simpler test and Check invalid params

In reply to Richard Palethorpe

Hi Richie,

testcases/kernel/syscalls/close_range/close_range02.c line 108

Quoted 5 lines
testcases/kernel/syscalls/close_range/close_range02.c new file +4 -0
+	if (fd > -1) {
+		TST_EXP_PASS_SILENT(close_range(fd, fd, 0),
+				    "close_range(%d, %d, 0)", fd, fd);
 
+		fd = -1;

Removed this line and patchset merged.

Thanks!

Kind regards,
Petr