All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH] syscalls/setgroups: fix implicit SETGROUPS parameter casting
@ 2013-08-16  7:10 Stanislav Kholmanskikh
  2013-08-22 13:13 ` chrubis
  0 siblings, 1 reply; 18+ messages in thread
From: Stanislav Kholmanskikh @ 2013-08-16  7:10 UTC (permalink / raw)
  To: ltp-list; +Cc: vasily.isaenko

One of parameters to setgroups() syscall is (gid_t *) pointer.
If TST_USE_COMPAT16_VSYSCALL is defined a pointer to GID_T is passed
instead (and sizeof(GID_T) < sizeof(gid_t)). It's not safe and
can result in unaligned access (and SIGBUS) on several platforms.

Signed-off-by: Stanislav Kholmanskikh <stanislav.kholmanskikh@oracle.com>
---
 testcases/kernel/syscalls/setgroups/compat_16.h   |   22 +++++++++++++++++++-
 testcases/kernel/syscalls/setgroups/setgroups04.c |    6 ++++-
 2 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/testcases/kernel/syscalls/setgroups/compat_16.h b/testcases/kernel/syscalls/setgroups/compat_16.h
index 0de4e78..35723d6 100644
--- a/testcases/kernel/syscalls/setgroups/compat_16.h
+++ b/testcases/kernel/syscalls/setgroups/compat_16.h
@@ -32,9 +32,27 @@ extern void cleanup(void);
 #ifdef TST_USE_COMPAT16_SYSCALL
 
 long
-SETGROUPS(size_t gidsetsize, GID_T *list)
+SETGROUPS(size_t gidsetsize, GID_T *list16)
 {
-	return ltp_syscall(__NR_setgroups, gidsetsize, list);
+	int r;
+	int i;
+
+	gid_t *list32;
+
+	list32 = calloc(gidsetsize, sizeof(gid_t));
+	if (list32 == NULL)
+		tst_brkm(TBROK | TERRNO, NULL,
+			"calloc failed to allocate %zu bytes at %s:%d",
+			gidsetsize * sizeof(gid_t),
+			__FILE__, __LINE__);
+
+	for (i = 0; i < gidsetsize; i++)
+		list32[i] = list16[i];
+
+	r = ltp_syscall(__NR_setgroups, gidsetsize, list32);
+
+	free(list32);
+	return r;
 }
 
 int
diff --git a/testcases/kernel/syscalls/setgroups/setgroups04.c b/testcases/kernel/syscalls/setgroups/setgroups04.c
index 5932b4e..42ddda2 100644
--- a/testcases/kernel/syscalls/setgroups/setgroups04.c
+++ b/testcases/kernel/syscalls/setgroups/setgroups04.c
@@ -111,7 +111,11 @@ int main(int ac, char **av)
 		 * verify that it fails with -1 return value and
 		 * sets appropriate errno.
 		 */
-		TEST(SETGROUPS(gidsetsize, sbrk(0)));
+#ifdef TST_USE_COMPAT16_SYSCALL
+		TEST(ltp_syscall(__NR_setgroups, gidsetsize, sbrk(0)));
+#else
+		TEST(setgroups(gidsetsize, sbrk(0)));
+#endif
 
 		if (TEST_RETURN != -1) {
 			tst_resm(TFAIL, "setgroups() returned %ld, "
-- 
1.7.1


------------------------------------------------------------------------------
Get 100% visibility into Java/.NET code with AppDynamics Lite!
It's a free troubleshooting tool designed for production.
Get down to code-level detail for bottlenecks, with <2% overhead. 
Download for free and get started troubleshooting in minutes. 
http://pubads.g.doubleclick.net/gampad/clk?id=48897031&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

end of thread, other threads:[~2013-09-09 12:07 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-08-16  7:10 [LTP] [PATCH] syscalls/setgroups: fix implicit SETGROUPS parameter casting Stanislav Kholmanskikh
2013-08-22 13:13 ` chrubis
     [not found]   ` <52174875.9030606@oracle.com>
2013-08-23 11:39     ` chrubis
     [not found]       ` <521B331D.7050902@oracle.com>
2013-08-26 11:30         ` chrubis
     [not found]           ` <521B4D82.2060007@oracle.com>
2013-08-26 14:16             ` chrubis
     [not found]               ` <521B6875.8010202@oracle.com>
2013-08-27  9:35                 ` [LTP] [PATCH V2 1/2] syscalls/setgroups: fix 16-bit versions of the testcases Stanislav Kholmanskikh
2013-08-27  9:35                 ` [LTP] [PATCH V2 2/2] syscalls/getgroups: added checks for 16-bit getgroups() syscall Stanislav Kholmanskikh
2013-08-27 12:16                   ` chrubis
     [not found]                     ` <521D9C44.8090607@oracle.com>
2013-08-28  9:55                       ` chrubis
     [not found]                         ` <1377782535-15955-3-git-send-email-stanislav.kholmanskikh@oracle.com>
2013-09-02 15:23                           ` [LTP] [PATCH V3 2/3] fixes for 16-bit syscalls testcases chrubis
     [not found]                             ` <52259811.3000604@oracle.com>
2013-09-03 10:11                               ` chrubis
     [not found]                                 ` <1378215677-14258-1-git-send-email-stanislav.kholmanskikh@oracle.com>
2013-09-04 13:37                                   ` [LTP] [PATCH V3.1 2/2] " chrubis
     [not found]                                     ` <1378364509-20971-1-git-send-email-stanislav.kholmanskikh@oracle.com>
2013-09-05 11:07                                       ` [LTP] [PATCH V4] 16-bit syscalls fixes chrubis
2013-09-09 12:07                                       ` chrubis
     [not found]                         ` <1377782535-15955-4-git-send-email-stanislav.kholmanskikh@oracle.com>
2013-09-02 15:28                           ` [LTP] [PATCH V3 3/3] syscalls/getgroups: added checks for 16-bit getgroups() syscall chrubis
     [not found]                         ` <1377782535-15955-2-git-send-email-stanislav.kholmanskikh@oracle.com>
2013-09-02 15:59                           ` [LTP] [PATCH V3 1/3] syscalls/utils/compat_16.mk: fix build dependencies chrubis
     [not found]                             ` <52257D67.5020900@oracle.com>
2013-09-03 11:06                               ` chrubis
2013-08-27 11:22                 ` [LTP] [PATCH] syscalls/setgroups: fix implicit SETGROUPS parameter casting chrubis

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.