All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH v3] syscall01: use 32bit syscalls if available
@ 2023-02-23  1:28 Edward Liaw via ltp
  2023-02-23  9:09 ` Cyril Hrubis
  0 siblings, 1 reply; 2+ messages in thread
From: Edward Liaw via ltp @ 2023-02-23  1:28 UTC (permalink / raw)
  To: ltp; +Cc: kernel-team

For 32-bit applications, the getuid/getgid syscalls return 16-bit ids,
and the getuid32 and getgid32 syscalls return 32-bit ids.  When
CONFIG_UID16 is disabled in the kernel, getuid/getgid (16-bit UIDs) are
no longer available.  Thus this test will fail when compiled as 32-bit
and with CONFIG_UID16 disabled.  For 64-bit applications, this is not an
issue because getuid/getgid return 32-bit ids and getuid32/getgid32 are
not defined.

The fix for this is to use getuid32/getgid32 if they are available to
match the behavior of glibc.

Signed-off-by: Edward Liaw <edliaw@google.com>
---
 testcases/kernel/syscalls/syscall/syscall01.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/testcases/kernel/syscalls/syscall/syscall01.c b/testcases/kernel/syscalls/syscall/syscall01.c
index 167e6ee86..76e793221 100644
--- a/testcases/kernel/syscalls/syscall/syscall01.c
+++ b/testcases/kernel/syscalls/syscall/syscall01.c
@@ -37,7 +37,11 @@ static void verify_getuid(void)
 	uid_t u1, u2;
 
 	u1 = getuid();
+#ifdef SYS_getuid32
+	u2 = syscall(SYS_getuid32);
+#else
 	u2 = syscall(SYS_getuid);
+#endif
 
 	if (u1 == u2) {
 		tst_res(TPASS, "getuid() == syscall(SYS_getuid)");
@@ -52,7 +56,11 @@ static void verify_getgid(void)
 	gid_t g1, g2;
 
 	g1 = getgid();
+#ifdef SYS_getgid32
+	g2 = syscall(SYS_getgid32);
+#else
 	g2 = syscall(SYS_getgid);
+#endif
 
 	if (g1 == g2) {
 		tst_res(TPASS, "getgid() == syscall(SYS_getgid)");
-- 
2.39.2.637.g21b0678d19-goog


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [LTP] [PATCH v3] syscall01: use 32bit syscalls if available
  2023-02-23  1:28 [LTP] [PATCH v3] syscall01: use 32bit syscalls if available Edward Liaw via ltp
@ 2023-02-23  9:09 ` Cyril Hrubis
  0 siblings, 0 replies; 2+ messages in thread
From: Cyril Hrubis @ 2023-02-23  9:09 UTC (permalink / raw)
  To: Edward Liaw; +Cc: kernel-team, ltp

Hi!
> For 32-bit applications, the getuid/getgid syscalls return 16-bit ids,
> and the getuid32 and getgid32 syscalls return 32-bit ids.  When
> CONFIG_UID16 is disabled in the kernel, getuid/getgid (16-bit UIDs) are
> no longer available.  Thus this test will fail when compiled as 32-bit
> and with CONFIG_UID16 disabled.  For 64-bit applications, this is not an
> issue because getuid/getgid return 32-bit ids and getuid32/getgid32 are
> not defined.
> 
> The fix for this is to use getuid32/getgid32 if they are available to
> match the behavior of glibc.

Sounds reasonable, since we are attempting to test syscall() and not the
getuid implementation. Also this probably fixes the case where the test
would be executed with UID that does not fit into 16 bits as well.

Pushed, thanks.

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-02-23  9:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-23  1:28 [LTP] [PATCH v3] syscall01: use 32bit syscalls if available Edward Liaw via ltp
2023-02-23  9:09 ` Cyril Hrubis

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.