Skip to contentSkip to conversation

syscalls/creat: Add "static" in creat01 and creat04

PATCH New Guangwen Feng 2 participants 8 messages Sep 6, 2017 – Sep 7, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 syscalls/creat: Add "static" in creat01 and creat04

---
 testcases/kernel/syscalls/creat/creat01.c | 4 ++--
 testcases/kernel/syscalls/creat/creat04.c | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
testcases/kernel/syscalls/creat/creat01.c +2 -2
index 571c771..6b70be2 100644
@@ -36,12 +36,12 @@
 static char filename[40];
 static int fd;
 
-void setup(void)
+static void setup(void)
 {
 	sprintf(filename, "creat01.%d", getpid());
 }
 
-struct tcase {
+static struct tcase {
 	int mode;
 } tcases[] = {
 	{0644},
testcases/kernel/syscalls/creat/creat04.c +1 -1
index c973108..ebcaa17 100644
@@ -68,7 +68,7 @@ static void verify_creat(unsigned int i)
 		child_fn(i);
 }
 
-void setup(void)
+static void setup(void)
 {
 	struct passwd *pw;
 	int fd;
Signature · 1 line
2.9.4
#1 lore raw

PATCH 2/3 syscalls/add_key: Make use of lapi/keyctl.h

---
 testcases/kernel/syscalls/add_key/Makefile    |  2 ++
 testcases/kernel/syscalls/add_key/add_key01.c | 18 ++++--------------
 testcases/kernel/syscalls/add_key/add_key02.c | 18 +++++-------------
 3 files changed, 11 insertions(+), 27 deletions(-)
testcases/kernel/syscalls/add_key/Makefile +2 -0
index 2ef86f0..c3e9ac1 100644
@@ -20,4 +20,6 @@ top_srcdir		?= ../../../..
 
 include $(top_srcdir)/include/mk/testcases.mk
 
+LDLIBS  += $(KEYUTILS_LIBS)
+
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/add_key/add_key01.c +4 -14
index ac561d7..6756702 100644
@@ -24,28 +24,18 @@
  *	      Manas Kumar Nayak [email protected]>
  */
 
-#include "config.h"
-#ifdef HAVE_LINUX_KEYCTL_H
-# include <linux/keyctl.h>
-#endif
+#include <errno.h>
+
 #include "tst_test.h"
-#include "lapi/syscalls.h"
+#include "lapi/keyctl.h"
 
 static void verify_add_key(void)
 {
-#ifdef HAVE_LINUX_KEYCTL_H
-
-	TEST(tst_syscall(__NR_add_key, "keyring", "wjkey", NULL, 0,
-	                 KEY_SPEC_THREAD_KEYRING));
-
+	TEST(add_key("keyring", "wjkey", NULL, 0, KEY_SPEC_THREAD_KEYRING));
 	if (TEST_RETURN == -1)
 		tst_res(TFAIL | TTERRNO, "add_key call failed");
 	else
 		tst_res(TPASS, "add_key call succeeded");
-
-#else
-	tst_brk(TCONF, "linux/keyctl.h was missing upon compilation.");
-#endif /* HAVE_LINUX_KEYCTL_H */
 }
 
 static struct tst_test test = {
testcases/kernel/syscalls/add_key/add_key02.c +5 -13
index a742824..ce46730 100644
@@ -32,14 +32,11 @@
  * than dereferencing NULL.
  */
 
-#include "config.h"
-#ifdef HAVE_LINUX_KEYCTL_H
-# include <linux/keyctl.h>
-#endif
+#include <errno.h>
+
 #include "tst_test.h"
-#include "lapi/syscalls.h"
+#include "lapi/keyctl.h"
 
-#ifdef HAVE_LINUX_KEYCTL_H
 struct tcase {
 	const char *type;
 	size_t plen;
@@ -58,13 +55,11 @@ struct tcase {
 	{ "user",		64 },
 	{ "logon",              64 },
 };
-#endif /* HAVE_LINUX_KEYCTL_H */
 
 static void verify_add_key(unsigned int i)
 {
-#ifdef HAVE_LINUX_KEYCTL_H
-	TEST(tst_syscall(__NR_add_key, tcases[i].type, "abc:def",
-			 NULL, tcases[i].plen, KEY_SPEC_PROCESS_KEYRING));
+	TEST(add_key(tcases[i].type,
+		"abc:def", NULL, tcases[i].plen, KEY_SPEC_PROCESS_KEYRING));
 
 	if (TEST_RETURN != -1) {
 		tst_res(TFAIL,
@@ -97,9 +92,6 @@ static void verify_add_key(unsigned int i)
 
 	tst_res(TFAIL | TTERRNO, "unexpected error with key type '%s'",
 		tcases[i].type);
-#else
-	tst_brk(TCONF, "linux/keyctl.h was missing upon compilation.");
-#endif /* HAVE_LINUX_KEYCTL_H */
 }
 
 static struct tst_test test = {
Signature · 1 line
2.9.4
#3 lore raw

PATCH 3/3 cve/cve-2016-7042: Make use of the fallback functions in lapi/keyctl.h

In reply to Guangwen Feng
---
 testcases/cve/Makefile        |  1 +
 testcases/cve/cve-2016-7042.c | 12 ++++--------
 2 files changed, 5 insertions(+), 8 deletions(-)
testcases/cve/Makefile +1 -0
index 04abc1f..db87299 100644
@@ -17,6 +17,7 @@ top_srcdir		?= ../..
 
 include $(top_srcdir)/include/mk/testcases.mk
 
+LDLIBS			+= $(KEYUTILS_LIBS)
 CFLAGS			+= -D_GNU_SOURCE
 
 cve-2016-7117:	CFLAGS += -pthread
testcases/cve/cve-2016-7042.c +4 -8
index ff9c057..8719eba 100644
@@ -31,7 +31,6 @@
 #include <stdio.h>
 
 #include "tst_test.h"
-#include "lapi/syscalls.h"
 #include "lapi/keyctl.h"
 
 #define PATH_KEYS	"/proc/keys"
@@ -43,12 +42,11 @@ static void do_test(void)
 {
 	char buf[BUFSIZ];
 
-	key = tst_syscall(__NR_add_key,
-		"user", "ltptestkey", "a", 1, KEY_SPEC_SESSION_KEYRING);
+	key = add_key("user", "ltptestkey", "a", 1, KEY_SPEC_SESSION_KEYRING);
 	if (key == -1)
 		tst_brk(TBROK, "Failed to add key");
 
-	if (tst_syscall(__NR_keyctl, KEYCTL_UPDATE, key, "b", 1))
+	if (keyctl(KEYCTL_UPDATE, key, "b", 1))
 		tst_brk(TBROK, "Failed to update key");
 
 	fd = SAFE_OPEN(PATH_KEYS, O_RDONLY);
@@ -61,8 +59,7 @@ static void do_test(void)
 
 	SAFE_CLOSE(fd);
 
-	if (tst_syscall(__NR_keyctl, KEYCTL_UNLINK, key,
-		KEY_SPEC_SESSION_KEYRING))
+	if (keyctl(KEYCTL_UNLINK, key, KEY_SPEC_SESSION_KEYRING))
 		tst_brk(TBROK, "Failed to unlink key");
 	key = 0;
 }
@@ -75,8 +72,7 @@ static void setup(void)
 
 static void cleanup(void)
 {
-	if (key > 0 && tst_syscall(__NR_keyctl, KEYCTL_UNLINK, key,
-		KEY_SPEC_SESSION_KEYRING))
+	if (key > 0 && keyctl(KEYCTL_UNLINK, key, KEY_SPEC_SESSION_KEYRING))
 		tst_res(TWARN, "Failed to unlink key");
 
 	if (fd > 0)
Signature · 1 line
2.9.4
#4 lore raw

PATCH 3/3 cve/cve-2016-7042: Make use of the fallback functions in lapi/keyctl.h

Hi!

Quoted 1 line

+LDLIBS += $(KEYUTILS_LIBS)

This should be set only for the particular test and not for all of them, like we do with -lrt and -lutil for the rest of the test.

Signature · 2 lines
Cyril Hrubis
[email protected]
#5 lore raw

PATCH v2 1/1 cve/cve-2016-7042: Make use of the fallback functions in lapi/keyctl.h

---
 testcases/cve/Makefile        |  2 ++
 testcases/cve/cve-2016-7042.c | 12 ++++--------
 2 files changed, 6 insertions(+), 8 deletions(-)
testcases/cve/Makefile +2 -0
index 04abc1f..0905fd9 100644
@@ -19,6 +19,8 @@ include $(top_srcdir)/include/mk/testcases.mk
 
 CFLAGS			+= -D_GNU_SOURCE
 
+cve-2016-7042:	LDLIBS += $(KEYUTILS_LIBS)
+
 cve-2016-7117:	CFLAGS += -pthread
 cve-2016-7117:	LDLIBS += -lrt
 
testcases/cve/cve-2016-7042.c +4 -8
index ff9c057..8719eba 100644
@@ -31,7 +31,6 @@
 #include <stdio.h>
 
 #include "tst_test.h"
-#include "lapi/syscalls.h"
 #include "lapi/keyctl.h"
 
 #define PATH_KEYS	"/proc/keys"
@@ -43,12 +42,11 @@ static void do_test(void)
 {
 	char buf[BUFSIZ];
 
-	key = tst_syscall(__NR_add_key,
-		"user", "ltptestkey", "a", 1, KEY_SPEC_SESSION_KEYRING);
+	key = add_key("user", "ltptestkey", "a", 1, KEY_SPEC_SESSION_KEYRING);
 	if (key == -1)
 		tst_brk(TBROK, "Failed to add key");
 
-	if (tst_syscall(__NR_keyctl, KEYCTL_UPDATE, key, "b", 1))
+	if (keyctl(KEYCTL_UPDATE, key, "b", 1))
 		tst_brk(TBROK, "Failed to update key");
 
 	fd = SAFE_OPEN(PATH_KEYS, O_RDONLY);
@@ -61,8 +59,7 @@ static void do_test(void)
 
 	SAFE_CLOSE(fd);
 
-	if (tst_syscall(__NR_keyctl, KEYCTL_UNLINK, key,
-		KEY_SPEC_SESSION_KEYRING))
+	if (keyctl(KEYCTL_UNLINK, key, KEY_SPEC_SESSION_KEYRING))
 		tst_brk(TBROK, "Failed to unlink key");
 	key = 0;
 }
@@ -75,8 +72,7 @@ static void setup(void)
 
 static void cleanup(void)
 {
-	if (key > 0 && tst_syscall(__NR_keyctl, KEYCTL_UNLINK, key,
-		KEY_SPEC_SESSION_KEYRING))
+	if (key > 0 && keyctl(KEYCTL_UNLINK, key, KEY_SPEC_SESSION_KEYRING))
 		tst_res(TWARN, "Failed to unlink key");
 
 	if (fd > 0)
Signature · 1 line
2.9.4
#6 lore raw

PATCH v2 1/1 cve/cve-2016-7042: Make use of the fallback functions in lapi/keyctl.h

Hi!
Pushed, thanks.

Signature · 2 lines
Cyril Hrubis
[email protected]