open16: allow restricted O_CREAT of FIFOs and regular files
v14 cover open16: allow restricted O_CREAT of FIFOs and regular files
v13->v14:
* Swapped informal "Level 1/2" descriptions for actual sysctl values 1 and 2.
* Moved local sysctl macros to the global include/tst_path_defs.h header.
* Use designated initializers.
* Flat-nested the child process path by using SAFE_FORK() with an early parent return.
* Replaced conditional branch logic with the unified TST_EXP_FD_OR_FAIL() macro.
* Add 8 missing CVE tags associated with the kernel commit.
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 v14 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 via ltp
lib/tst_uid: Remove spurious TERRNO fromtst_get_free_gidsuccess path
--- [PATCH 3/3] ---
Quoted 5 lines
+/*\
+ * Verify restricted opening (:manpage:open(2)and :manpage:openat(2)) of
+ * FIFOs and regular files in sticky directories. This protection is controlled via
+ */proc/sys/fs/protected_fifosand/proc/sys/fs/protected_regularsysctl values:
+ *
Quoted 8 lines
+ * - When set to "0", writing/opening is unrestricted.
+ * - When set to "1",O_CREATopen on FIFOs/regular files we don't own in world-writable
+ * sticky directories is disallowed, unless they are owned by the owner of the directory.
+ * - When set to "2", the same restriction also applies to group-writable sticky directories.
+ *
+ * This test requires root to modify/proc/sys/fs/protected_*sysctls and
+ * to manage file ownership and permissions in sticky directories.
+ */
Use double backticks (``...``) for inline literals in the reST description block instead of single backticks or unquoted text:
``/proc/sys/fs/protected_fifos``, ``/proc/sys/fs/protected_regular``, and ``/proc/sys/fs/protected_*``.
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 v14 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 v14 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