From: Cyril Hrubis <chrubis@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v2] syscalls/prctl07: New test for prctl() with PR_CAP_AMBIENT
Date: Tue, 16 Jul 2019 14:55:24 +0200 [thread overview]
Message-ID: <20190716125524.GA23024@rei> (raw)
In-Reply-To: <1562925275-2390-1-git-send-email-xuyang2018.jy@cn.fujitsu.com>
Hi!
Pushed with minor changes, thanks.
The highlights of the changes are:
* Using proper hexadecimal base when converting CapAmb from string
* Adding the CAP_LIB selectively only for prctl07
The rest is more or less cosmetic to avoid warnings on missing libcap
and such.
diff --git a/testcases/kernel/syscalls/prctl/prctl07.c b/testcases/kernel/syscalls/prctl/prctl07.c
index bbb9161dd..37d77df33 100644
--- a/testcases/kernel/syscalls/prctl/prctl07.c
+++ b/testcases/kernel/syscalls/prctl/prctl07.c
@@ -26,45 +26,44 @@
#include <stdlib.h>
#include "config.h"
#ifdef HAVE_LIBCAP
-#include <sys/capability.h>
+# include <sys/capability.h>
#endif
#include "lapi/syscalls.h"
#include "lapi/prctl.h"
#include "lapi/securebits.h"
#include "tst_test.h"
-static void check_proc_capamb(char *message, int flag)
+#define PROC_STATUS "/proc/self/status"
+
+static inline void check_proc_capamb(char *message, int flag)
{
- unsigned int cap_num;
+ int cap_num;
char CapAmb[20];
- char path[50];
- strcpy(path, "/proc/self/status");
- SAFE_FILE_LINES_SCANF(path, "CapAmb:%s", CapAmb);
- cap_num = atoi(CapAmb);
+ SAFE_FILE_LINES_SCANF(PROC_STATUS, "CapAmb:%s", CapAmb);
+ cap_num = strtol(CapAmb, NULL, 16);
if (flag == 2) {
if (cap_num == 0)
tst_res(TPASS,
"%s, %s CapAmb has been clear as %d",
- message, path, cap_num);
+ message, PROC_STATUS, cap_num);
else
tst_res(TFAIL,
"%s, %s CapAmb has been clear expect 0, got %d",
- message, path, cap_num);
+ message, PROC_STATUS, cap_num);
return;
}
- /*1 << CAP_NET_BIND_SERVICE*/
- if (cap_num == 400)
+ if (cap_num == (1 << CAP_NET_BIND_SERVICE))
tst_res(flag ? TPASS : TFAIL,
"%s, CapAmb in %s has CAP_NET_BIND_SERVICE",
- message, path);
+ message, PROC_STATUS);
else
tst_res(flag ? TFAIL : TPASS,
"%s, CapAmb in %s doesn't have CAP_NET_BIND_SERVICE",
- message, path);
+ message, PROC_STATUS);
}
-static void check_cap_raise(unsigned int cap, char *message, int fail_flag)
+static inline void check_cap_raise(unsigned int cap, char *message, int fail_flag)
{
TEST(prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_RAISE, cap, 0, 0, 0));
switch (fail_flag) {
@@ -84,13 +83,13 @@ static void check_cap_raise(unsigned int cap, char *message, int fail_flag)
tst_res(TPASS,
"PR_CAP_AMBIENT_RAISE failed with EPERM %s", message);
else
- tst_res(TFAIL | TERRNO,
+ tst_res(TFAIL | TTERRNO,
"PR_CAP_AMBIENT_RAISE failed %s", message);
break;
}
}
-static void check_cap_is_set(unsigned int cap, char *message, int val)
+static inline void check_cap_is_set(unsigned int cap, char *message, int val)
{
TEST(prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_IS_SET, cap, 0, 0, 0));
if (TST_RET == 1)
@@ -100,14 +99,14 @@ static void check_cap_is_set(unsigned int cap, char *message, int val)
tst_res(val ? TFAIL : TPASS,
"PR_CAP_AMBIENT_IS_SET %s not in AmbientCap", message);
else
- tst_res(TFAIL | TERRNO, "PR_CAP_AMBIENT_IS_SET failed");
+ tst_res(TFAIL | TTERRNO, "PR_CAP_AMBIENT_IS_SET failed");
}
-static void check_cap_lower(unsigned int cap, char *message)
+static inline void check_cap_lower(unsigned int cap, char *message)
{
TEST(prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_LOWER, cap, 0, 0, 0));
if (TST_RET == -1)
- tst_res(TFAIL | TERRNO,
+ tst_res(TFAIL | TTERRNO,
"PR_CAP_AMBIENT_LOWER %s failed", message);
else
tst_res(TPASS, "PR_CAP_AMBIENT_LOWER %s succeeded", message);
@@ -168,7 +167,7 @@ static void verify_prctl(void)
cap_free(caps);
#else
- tst_res(TCONF, "System doesn't have POSIX capabilities support");
+ tst_res(TCONF, "libcap devel files missing during compilation");
#endif
}
diff --git a/testcases/kernel/syscalls/prctl/Makefile b/testcases/kernel/syscalls/prctl/Makefile
index 1399122e8..cf19507c0 100644
--- a/testcases/kernel/syscalls/prctl/Makefile
+++ b/testcases/kernel/syscalls/prctl/Makefile
@@ -20,6 +20,6 @@ top_srcdir ?= ../../../..
include $(top_srcdir)/include/mk/testcases.mk
-LDLIBS += $(CAP_LIBS)
+prctl07: LDLIBS += $(CAP_LIBS)
include $(top_srcdir)/include/mk/generic_leaf_target.mk
--
Cyril Hrubis
chrubis@suse.cz
prev parent reply other threads:[~2019-07-16 12:55 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-24 6:09 [LTP] [PATCH] syscalls/prctl07.c: New test for prctl() with PR_CAP_AMBIENT Yang Xu
2019-07-09 11:20 ` Cyril Hrubis
2019-07-12 9:54 ` [LTP] [PATCH v2] syscalls/prctl07: " Yang Xu
2019-07-16 12:55 ` Cyril Hrubis [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190716125524.GA23024@rei \
--to=chrubis@suse.cz \
--cc=ltp@lists.linux.it \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox