* [BUGFIX PATCH 2/2] selftests: safesetid: Check the return value of setuid/setgid
2019-12-05 7:33 [BUGFIX PATCH 0/2] selftests: safesetid: Fix build warnings and errors Masami Hiramatsu
2019-12-05 7:33 ` [BUGFIX PATCH 1/2] selftests: safesetid: Move link library to LDLIBS Masami Hiramatsu
@ 2019-12-05 7:33 ` Masami Hiramatsu
2019-12-05 12:16 ` [BUGFIX PATCH 0/2] selftests: safesetid: Fix build warnings and errors Masami Hiramatsu
2 siblings, 0 replies; 4+ messages in thread
From: Masami Hiramatsu @ 2019-12-05 7:33 UTC (permalink / raw)
To: Shuah Khan; +Cc: Micah Morton, linux-kselftest, linux-kernel, jaswinder.singh
Check the return value of setuid() and setgid().
This fixes the following warnings and improves test result.
safesetid-test.c: In function ‘main’:
safesetid-test.c:294:2: warning: ignoring return value of ‘setuid’, declared with attribute warn_unused_result [-Wunused-result]
setuid(NO_POLICY_USER);
^~~~~~~~~~~~~~~~~~~~~~
safesetid-test.c:295:2: warning: ignoring return value of ‘setgid’, declared with attribute warn_unused_result [-Wunused-result]
setgid(NO_POLICY_USER);
^~~~~~~~~~~~~~~~~~~~~~
safesetid-test.c:309:2: warning: ignoring return value of ‘setuid’, declared with attribute warn_unused_result [-Wunused-result]
setuid(RESTRICTED_PARENT);
^~~~~~~~~~~~~~~~~~~~~~~~~
safesetid-test.c:310:2: warning: ignoring return value of ‘setgid’, declared with attribute warn_unused_result [-Wunused-result]
setgid(RESTRICTED_PARENT);
^~~~~~~~~~~~~~~~~~~~~~~~~
safesetid-test.c: In function ‘test_setuid’:
safesetid-test.c:216:3: warning: ignoring return value of ‘setuid’, declared with attribute warn_unused_result [-Wunused-result]
setuid(child_uid);
^~~~~~~~~~~~~~~~~
Fixes: c67e8ec03f3f ("LSM: SafeSetID: add selftest")
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
tools/testing/selftests/safesetid/safesetid-test.c | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/tools/testing/selftests/safesetid/safesetid-test.c b/tools/testing/selftests/safesetid/safesetid-test.c
index 8f40c6ecdad1..0c4d50644c13 100644
--- a/tools/testing/selftests/safesetid/safesetid-test.c
+++ b/tools/testing/selftests/safesetid/safesetid-test.c
@@ -213,7 +213,8 @@ static void test_setuid(uid_t child_uid, bool expect_success)
}
if (cpid == 0) { /* Code executed by child */
- setuid(child_uid);
+ if (setuid(child_uid) < 0)
+ exit(EXIT_FAILURE);
if (getuid() == child_uid)
exit(EXIT_SUCCESS);
else
@@ -291,8 +292,10 @@ int main(int argc, char **argv)
// First test to make sure we can write userns mappings from a user
// that doesn't have any restrictions (as long as it has CAP_SETUID);
- setuid(NO_POLICY_USER);
- setgid(NO_POLICY_USER);
+ if (setuid(NO_POLICY_USER) < 0)
+ die("Error with set uid(%d)\n", NO_POLICY_USER);
+ if (setgid(NO_POLICY_USER) < 0)
+ die("Error with set gid(%d)\n", NO_POLICY_USER);
// Take away all but setid caps
drop_caps(true);
@@ -306,8 +309,10 @@ int main(int argc, char **argv)
die("test_userns failed when it should work\n");
}
- setuid(RESTRICTED_PARENT);
- setgid(RESTRICTED_PARENT);
+ if (setuid(RESTRICTED_PARENT) < 0)
+ die("Error with set uid(%d)\n", RESTRICTED_PARENT);
+ if (setgid(RESTRICTED_PARENT) < 0)
+ die("Error with set gid(%d)\n", RESTRICTED_PARENT);
test_setuid(ROOT_USER, false);
test_setuid(ALLOWED_CHILD1, true);
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [BUGFIX PATCH 0/2] selftests: safesetid: Fix build warnings and errors
2019-12-05 7:33 [BUGFIX PATCH 0/2] selftests: safesetid: Fix build warnings and errors Masami Hiramatsu
2019-12-05 7:33 ` [BUGFIX PATCH 1/2] selftests: safesetid: Move link library to LDLIBS Masami Hiramatsu
2019-12-05 7:33 ` [BUGFIX PATCH 2/2] selftests: safesetid: Check the return value of setuid/setgid Masami Hiramatsu
@ 2019-12-05 12:16 ` Masami Hiramatsu
2 siblings, 0 replies; 4+ messages in thread
From: Masami Hiramatsu @ 2019-12-05 12:16 UTC (permalink / raw)
To: Masami Hiramatsu
Cc: Shuah Khan, Micah Morton, linux-kselftest, linux-kernel,
jaswinder.singh
On Thu, 5 Dec 2019 16:33:12 +0900
Masami Hiramatsu <mhiramat@kernel.org> wrote:
> Hi,
>
> Here are the patches to fix build warnings and erorrs on
> kselftest safesetid.
Oops, I found one another bug in safesetid. I'll send v2 including
new fix.
Thank you,
>
> Thank you,
>
> ---
>
> Masami Hiramatsu (2):
> selftests: safesetid: Move link library to LDLIBS
> selftests: safesetid: Check the return value of setuid/setgid
>
>
> tools/testing/selftests/safesetid/Makefile | 3 ++-
> tools/testing/selftests/safesetid/safesetid-test.c | 15 ++++++++++-----
> 2 files changed, 12 insertions(+), 6 deletions(-)
>
> --
> Masami Hiramatsu (Linaro) <mhiramat@kernel.org>
--
Masami Hiramatsu <mhiramat@kernel.org>
^ permalink raw reply [flat|nested] 4+ messages in thread