open16: allow restricted O_CREAT of FIFOs and regular files
v15 cover open16: allow restricted O_CREAT of FIFOs and regular files
v14->v15:
- Update comments format base AI review
Wei Gao (3):
lib/tst_uid: Remove spurious TERRNO from tst_get_free_gid success path
lib: New library function tst_get_free_uid
open16: allow restricted O_CREAT of FIFOs and regular files
include/tst_path_defs.h | 2 + include/tst_uid.h | 14 +++ lib/tst_uid.c | 30 ++++- runtest/syscalls | 1 + testcases/kernel/syscalls/open/.gitignore | 1 + testcases/kernel/syscalls/open/open16.c | 143 ++++++++++++++++++++++ 6 files changed, 190 insertions(+), 1 deletion(-) create mode 100644 testcases/kernel/syscalls/open/open16.c
Signature · 5 lines
2.55.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v15 1/3 lib/tst_uid: Remove spurious TERRNO from tst_get_free_gid success path
tst_get_free_gid_() prints the found GID when it succeeds, but it incorrectly includes TERRNO in tst_res_(). This prints whatever value happens to be in errno (often 0 or a stale value) which is confusing in a success path.
Remove the spurious TERRNO flag from the tst_res_() success message.
--- lib/tst_uid.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/tst_uid.c +1 -1
@@ -24,7 +24,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.55.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] lib/tst_uid: Remove spurious TERRNO from tst_get_free_gid success path
Hi Wei,
Quoted 1 line · Wei Gao
lib/tst_uid: Remove spurious TERRNO fromtst_get_free_gidsuccess path
Verdict - Reviewed
---
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
Re: [LTP] [PATCH v15 1/3] lib/tst_uid: Remove spurious TERRNO from tst_get_free_gid success path
In reply to Wei Gao via ltpHi all,
Quoted 9 lines
tst_get_free_gid_()prints the found GID when it succeeds, but it incorrectly includes TERRNO intst_res_(). This prints whatever value happens to be in errno (often 0 or a stale value) which is confusing in a success path.Remove the spurious TERRNO flag from the
tst_res_()success message.Signed-off-by Wei Gao <[email protected]>Reviewed-by Andrea Cervesato <[email protected]>
Martin might done it intentionally (had a reason for printing it). If not, I'd merge this simple improvement before the release.
Kind regards,
Petr
Quoted 17 lines
--- lib/tst_uid.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)lib/tst_uid.c +1
-1@@ -24,7 +24,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 · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v15 1/3] lib/tst_uid: Remove spurious TERRNO from tst_get_free_gid success path
In reply to Wei Gao via ltpQuoted 18 lines · Wei Gao via ltp
tst_get_free_gid_()prints the found GID when it succeeds, but it incorrectly includes TERRNO intst_res_(). This prints whatever value happens to be in errno (often 0 or a stale value) which is confusing in a success path.Remove the spurious TERRNO flag from the
tst_res_()success message.Signed-off-by Wei Gao <[email protected]>Reviewed-by Andrea Cervesato <[email protected]>--- lib/tst_uid.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)lib/tst_uid.c +0
-0
lib/tst_uid.c gid_t tst_get_free_gid_(const char *file, const int lineno, gid_t skip) · line 30
Quoted 8 lines
lib/tst_uid.c +1
-1@@ -24,7 +24,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; }
Hi,
the errno value printed here is always set by the getgrgid() call on line 23. The TERRNO is intentional and it should stay there.
Signature · 10 lines
Martin Doucha [email protected] SW Quality Engineer SUSE LINUX, s.r.o. CORSO IIa Krizikova 148/34 186 00 Prague 8 Czech Republic -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v15 2/3 lib: New library function tst_get_free_uid
In reply to Wei Gao via ltpAdd 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 | 14 ++++++++++++++ lib/tst_uid.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+)
include/tst_uid.h +14 -0
@@ -7,6 +7,20 @@#include <sys/types.h> +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)) +/* * 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
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 , +"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.55.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v15 3/3 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 (values 1 and 2 for protected_fifos and protected_regular) for opening FIFOs and regular files in world-writable or group-writable sticky directories when the file is not owned by the opener.
--- include/tst_path_defs.h | 2 + runtest/syscalls | 1 + testcases/kernel/syscalls/open/.gitignore | 1 + testcases/kernel/syscalls/open/open16.c | 143 ++++++++++++++++++++++ 4 files changed, 147 insertions(+) create mode 100644 testcases/kernel/syscalls/open/open16.c
include/tst_path_defs.h +2 -0
@@ -47,6 +47,8 @@#define PATH_FS_PIPE_MAX_PAGES "/proc/sys/fs/pipe-max-pages"#define PATH_FS_MAX_USER_GROUPS "/proc/sys/fs/fanotify/max_user_groups"#define PATH_FS_MAX_USER_MARKS "/proc/sys/fs/fanotify/max_user_marks" +#define PATH_FS_PROTECTED_REGULAR "/proc/sys/fs/protected_regular" +#define PATH_FS_PROTECTED_FIFOS "/proc/sys/fs/protected_fifos"/* VM */ #define PATH_VM_DROP_CACHES "/proc/sys/vm/drop_caches"
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 +143 -0
143 lines not on this page · raw message
Signature · 5 lines
2.55.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp