open16: allow restricted O_CREAT of FIFOs and regular files
A message that is not in the archive (sent off-list or not yet received): https://patchwork.ozlabs.org/project/ltp/patch/[email protected]/
v10 cover open16: allow restricted O_CREAT of FIFOs and regular files
v9->v10:
- Update comments for tst_get_free_uid
- Update logic of tst_get_free_uid
Wei Gao (2):
lib: New library function tst_get_free_uid
open16: allow restricted O_CREAT of FIFOs and regular files
include/tst_uid.h | 27 ++++- lib/tst_uid.c | 28 +++++ runtest/syscalls | 1 + testcases/kernel/syscalls/open/.gitignore | 1 + testcases/kernel/syscalls/open/open16.c | 134 ++++++++++++++++++++++ 5 files changed, 187 insertions(+), 4 deletions(-) create mode 100644 testcases/kernel/syscalls/open/open16.c
Signature · 5 lines
2.54.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v10 1/2 lib: New library function tst_get_free_uid
Add tst_get_free_uid() to dynamically find unused UIDs for tests.
Some tests need a completely unassigned, unused UID. This is used by open16 to verify restricted O_CREAT in sticky directories by running as a sandboxed user with no file ownership or privileges.
--- include/tst_uid.h | 27 +++++++++++++++++++++++---- lib/tst_uid.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 4 deletions(-)
include/tst_uid.h +23 -4
@@ -7,10 +7,29 @@#include <sys/types.h> -/* -* Find unassigned gid. The skip argument can be used to ignore e.g. the main -* group of a specific user in case it's not listed in the group file. If you -* do not need to skip any specific gid, simply set it to 0. +/** +* tst_get_free_uid() - Find a UID not assigned to any user. +* @skip: UID value to skip (pass 0 to skip none). +* +* Scans the password database for the first unused UID starting +* from 1, skipping @skip. Calls tst_brk(TBROK) if no free UID +* is found or a lookup error occurs. +* +* Return: An unused uid_t value. +*/ +uid_t tst_get_free_uid_ (const char *file,const int lineno,uid_t skip); +#define tst_get_free_uid (skip) tst_get_free_uid_(__FILE__, __LINE__, (skip)) + +/** +* tst_get_free_gid() - Find a GID not assigned to any group. +* @skip: GID value to skip (pass 0 to skip none). +* +* Scans the group database for the first unused GID starting from 1, +* skipping @skip. The @skip argument can be used to ignore e.g. the main +* group of a specific user in case it's not listed in the group file. +* Calls tst_brk(TBROK) if no free GID is found or a lookup error occurs. +* +* Return: An unused gid_t value. */ gid_t tst_get_free_gid_ (const char *file,const int lineno,gid_t skip);#define tst_get_free_gid (skip) tst_get_free_gid_(__FILE__, __LINE__, (skip))
lib/tst_uid.c +28 -0
@@ -5,6 +5,7 @@#include <sys/types.h> #include <grp.h> +#include <pwd.h> #include <errno.h> #define TST_NO_DEFAULT_MAIN
@@ -12,6 +13,33 @@#include "tst_uid.h" #define MAX_GID 32767 +#define MAX_UID 32767 + +uid_t tst_get_free_uid_ (const char *file,const int lineno,uid_t skip) +{ +uid_t ret; + +for (ret =1 ; ret <MAX_UID ; ret++) { +if (ret == skip) +continue ; + + errno =0 ; +if (getpwuid (ret)) +continue ; + +if (errno ==0 || errno ==ENOENT || errno ==ESRCH ) { +tst_res_ (file, lineno,TINFO |TERRNO , +"Found unused UID %d" , (int )ret); +return ret; + } + +tst_brk_ (file, lineno,TBROK |TERRNO ,"User ID lookup failed" ); +return (uid_t)-1 ; + } + +tst_brk_ (file, lineno,TBROK ,"No free user ID found" ); +return (uid_t)-1 ; +}gid_t tst_get_free_gid_ (const char *file,const int lineno,gid_t skip) {
Signature · 5 lines
2.54.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] lib: New library function tst_get_free_uid
Hi Wei,
Quoted 1 line · Wei Gao
lib: New library function
tst_get_free_uid
--- [PATCH 1/2] ---
Quoted 3 lines
+/**
+ *tst_get_free_uid()- Find a UID not assigned to any user.
+ * @skip: UID value to skip (pass 0 to skip none).
The summary line says tst_get_free_uid() but the symbol being declared is tst_get_free_uid_(). linuxdoc requires the summary name to match the symbol exactly, so it would fail to associate this /** block with the implementation.
Should this be "tst_get_free_uid_() - ..." to match the symbol, or is the intent to document the macro tst_get_free_uid() instead?
Same issue applies to the modified tst_get_free_gid() summary below.
Quoted 1 line
+uid_t
tst_get_free_uid_(const char *file, const int lineno, uid_t skip);
The function has three parameters but the kernel-doc block only documents @skip. linuxdoc expects an @name: entry for every parameter in declaration order. @file and @lineno are missing.
Same gap in the modified tst_get_free_gid_() block.
lib/tst_uid.c line 33
Quoted 4 lines
lib/tst_uid.c +4
-0+if (errno ==0 || errno ==ENOENT || errno ==ESRCH ) { +tst_res_ (file, lineno,TINFO |TERRNO , +"Found unused UID %d" , (int )ret); +return ret;
When getpwuid() returns NULL with errno set to ENOENT or ESRCH, TERRNO appends the errno string to the message, producing output like:
"Found unused UID 5: No such file or directory". The function succeeded, so the error string is misleading. Should TERRNO be dropped here, or should it be conditionally omitted when errno indicates "not found"?
--- [PATCH 2/2] ---
Review
Quoted 6 lines
(quoted diff) +6
-0+Add LTP coverage for kernel commit 30aba6656f61 (Linux 4.19), which +introduced protection against spoofing attacks via O_CREAT of FIFOs and +regular files in world-writable sticky directories. + +This commit adds test cases to verify these security restrictions for +opening FIFOs and regular files in world-writable sticky directories.
tcase[2] uses dir_mode=0030|SVTX (group-writable sticky, level 2), which the commit body doesn't mention. The test's own doc block describes both "world-writable (level 1) or group-writable (level 2)" correctly — does the body need updating to match?
Verdict - Needs revision
---
Note:
The agent can sometimes produce false positives although often its findings are genuine. If you find issues with the review, please comment this email or ignore the suggestions.
Regards,
LTP AI Reviewer
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
v11 cover open16: allow restricted O_CREAT of FIFOs and regular files
In reply to Wei Gao via ltpv10->v11:
* tst_uid.h: Moved kernel-doc comments above the macros to fix parser warnings.
* tst_uid.c: Removed TERRNO from tst_get_free_gid_ success path to avoid misleading output.
* open16: Added group-writable sticky directories to the commit message to match the test.
Wei Gao (2):
lib: New library function tst_get_free_uid
open16: allow restricted O_CREAT of FIFOs and regular files
include/tst_uid.h | 29 ++++- lib/tst_uid.c | 30 ++++- runtest/syscalls | 1 + testcases/kernel/syscalls/open/.gitignore | 1 + testcases/kernel/syscalls/open/open16.c | 135 ++++++++++++++++++++++ 5 files changed, 191 insertions(+), 5 deletions(-) create mode 100644 testcases/kernel/syscalls/open/open16.c
Signature · 5 lines
2.54.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v11 1/2 lib: New library function tst_get_free_uid
Add tst_get_free_uid() to dynamically find unused UIDs for tests.
Some tests need a completely unassigned, unused UID. This is used by open16 to verify restricted O_CREAT in sticky directories by running as a sandboxed user with no file ownership or privileges.
--- include/tst_uid.h | 29 +++++++++++++++++++++++++---- lib/tst_uid.c | 30 +++++++++++++++++++++++++++++- 2 files changed, 54 insertions(+), 5 deletions(-)
include/tst_uid.h +25 -4
@@ -7,12 +7,33 @@#include <sys/types.h> -/* -* Find unassigned gid. The skip argument can be used to ignore e.g. the main -* group of a specific user in case it's not listed in the group file. If you -* do not need to skip any specific gid, simply set it to 0. +uid_t tst_get_free_uid_ (const char *file,const int lineno,uid_t skip); + +/** +* tst_get_free_uid() - Find a UID not assigned to any user. +* @skip: UID value to skip (pass 0 to skip none). +* +* Scans the password database for the first unused UID starting +* from 1, skipping @skip. Calls tst_brk(TBROK) if no free UID +* is found or a lookup error occurs. +* +* Return: An unused uid_t value. */ +#define tst_get_free_uid (skip) tst_get_free_uid_(__FILE__, __LINE__, (skip)) +gid_t tst_get_free_gid_ (const char *file,const int lineno,gid_t skip); + +/** +* tst_get_free_gid() - Find a GID not assigned to any group. +* @skip: GID value to skip (pass 0 to skip none). +* +* Scans the group database for the first unused GID starting from 1, +* skipping @skip. The @skip argument can be used to ignore e.g. the main +* group of a specific user in case it's not listed in the group file. +* Calls tst_brk(TBROK) if no free GID is found or a lookup error occurs. +* +* Return: An unused gid_t value. +*/ #define tst_get_free_gid (skip) tst_get_free_gid_(__FILE__, __LINE__, (skip))/*
lib/tst_uid.c +29 -1
@@ -5,6 +5,7 @@#include <sys/types.h> #include <grp.h> +#include <pwd.h> #include <errno.h> #define TST_NO_DEFAULT_MAIN
@@ -12,6 +13,33 @@#include "tst_uid.h" #define MAX_GID 32767 +#define MAX_UID 32767 + +uid_t tst_get_free_uid_ (const char *file,const int lineno,uid_t skip) +{ +uid_t ret; + +for (ret =1 ; ret <MAX_UID ; ret++) { +if (ret == skip) +continue ; + + errno =0 ; +if (getpwuid (ret)) +continue ; + +if (errno ==0 || errno ==ENOENT || errno ==ESRCH ) { +tst_res_ (file, lineno,TINFO , +"Found unused UID %d" , (int )ret); +return ret; + } + +tst_brk_ (file, lineno,TBROK |TERRNO ,"User ID lookup failed" ); +return (uid_t)-1 ; + } + +tst_brk_ (file, lineno,TBROK ,"No free user ID found" ); +return (uid_t)-1 ; +}gid_t tst_get_free_gid_ (const char *file,const int lineno,gid_t skip) {
@@ -24,7 +52,7 @@ gid_t tst_get_free_gid_(const char *file, const int lineno, gid_t skip)continue ;if (errno ==0 || errno ==ENOENT || errno ==ESRCH ) { -tst_res_ (file, lineno,TINFO |TERRNO , +tst_res_ (file, lineno,TINFO ,"Found unused GID %d" , (int )ret);return ret; }
Signature · 5 lines
2.54.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] lib: New library function tst_get_free_uid
Hi Wei,
Quoted 1 line · Wei Gao
lib: New library function
tst_get_free_uid
--- [PATCH 1/2] ---
lib/tst_uid.c gid_t tst_get_free_gid_(const char *file, const int lineno, gid_t skip) · line 56
Quoted 3 lines
lib/tst_uid.c +1
-1-tst_res_ (file, lineno,TINFO |TERRNO , +tst_res_ (file, lineno,TINFO ,"Found unused GID %d" , (int )ret);
This hunk is a fix to the existing tst_get_free_gid_() success path -- removing | TERRNO so errno is not printed when a free GID is found.
That is a reasonable fix on its own, but it has no relationship to the new tst_get_free_uid() API that the commit message describes. The commit message does not mention it.
Could these be split into two patches?
1/3 lib/tst_uid: Remove spurious TERRNO from tst_get_free_gid success path 2/3 lib: New library function tst_get_free_uid 3/3 open16: allow restricted O_CREAT of FIFOs and regular files
Verdict - Needs revision
---
Note:
The agent can sometimes produce false positives although often its findings are genuine. If you find issues with the review, please comment this email or ignore the suggestions.
Regards,
LTP AI Reviewer
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v11 2/2 open16: allow restricted O_CREAT of FIFOs and regular files
In reply to Wei Gao via ltpAdd LTP coverage for kernel commit 30aba6656f61 (Linux 4.19), which introduced protection against spoofing attacks via O_CREAT of FIFOs and regular files in world-writable or group-writable sticky directories.
This commit adds test cases to verify these security restrictions (Level 1 and Level 2 protections) for opening FIFOs and regular files in world-writable or group-writable sticky directories when the file is not owned by the opener.
--- runtest/syscalls | 1 + testcases/kernel/syscalls/open/.gitignore | 1 + testcases/kernel/syscalls/open/open16.c | 135 ++++++++++++++++++++++ 3 files changed, 137 insertions(+) create mode 100644 testcases/kernel/syscalls/open/open16.c
runtest/syscalls +1 -0
@@ -1008,6 +1008,7 @@ open12 open12 open13 open13 open14 open14 open15 open15 +open16 open16 openat01 openat01 openat02 openat02
testcases/kernel/syscalls/open/.gitignore +1 -0
@@ -13,3 +13,4 @@ /open13 /open14 /open15 +/open16
testcases/kernel/syscalls/open/open16.c new file +135 -0
135 lines not on this page · raw message
Signature · 5 lines
2.54.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Wei,
can you please send the patch-set in a new thread, instead of replying to the old version? we are having a really long thread in the lore instance and it's getting diffciult to read.
https://lore.kernel.org/ltp/[email protected]/
Thanks,
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Andrea
Ok, I will send it in a new thread.
Thanks.
Gao Wei
Quoted 14 lines · Andrea Cervesato
Hi Wei,
can you please send the patch-set in a new thread, instead of replying to the old version? we are having a really long thread in the lore instance and it's getting diffciult to read.
https://lore.kernel.org/ltp/[email protected]/
Thanks,
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v10 2/2 open16: allow restricted O_CREAT of FIFOs and regular files
In reply to Wei Gao via ltpAdd LTP coverage for kernel commit 30aba6656f61 (Linux 4.19), which introduced protection against spoofing attacks via O_CREAT of FIFOs and regular files in world-writable sticky directories.
This commit adds test cases to verify these security restrictions for opening FIFOs and regular files in world-writable sticky directories.
--- runtest/syscalls | 1 + testcases/kernel/syscalls/open/.gitignore | 1 + testcases/kernel/syscalls/open/open16.c | 134 ++++++++++++++++++++++ 3 files changed, 136 insertions(+) create mode 100644 testcases/kernel/syscalls/open/open16.c
runtest/syscalls +1 -0
@@ -1008,6 +1008,7 @@ open12 open12 open13 open13 open14 open14 open15 open15 +open16 open16 openat01 openat01 openat02 openat02
testcases/kernel/syscalls/open/.gitignore +1 -0
@@ -13,3 +13,4 @@ /open13 /open14 /open15 +/open16
testcases/kernel/syscalls/open/open16.c new file +134 -0
134 lines not on this page · raw message
Signature · 5 lines
2.54.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp