syscalls/capget[set]: Make use of guarded buffers
PATCH 1/1 syscalls/capget[set]: Make use of guarded buffers
Also, using pid=0 instead of getpid() in capget02.c because it also returns the capabilities for the calling thread.
Signed-off-by Yang Xu <[email protected]>
--- testcases/kernel/syscalls/capget/capget01.c | 17 +++-- testcases/kernel/syscalls/capget/capget02.c | 79 ++++++++++----------- testcases/kernel/syscalls/capset/capset01.c | 24 +++++-- 3 files changed, 66 insertions(+), 54 deletions(-)
testcases/kernel/syscalls/capget/capget01.c +10 -7
@@ -13,6 +13,8 @@#include <linux/capability.h> static pid_t pid; +static struct __user_cap_header_struct *hdr; +static struct __user_cap_data_struct *data; static struct tcase { int version;
@@ -26,16 +28,12 @@ static struct tcase {static void verify_capget (unsigned int n) {struct tcase *tc = &tcases[n]; -struct __user_cap_header_struct hdr = { - .version = tc->version, - .pid = pid, - }; - -struct __user_cap_data_struct data[2 ];tst_res (TINFO ,"%s" , tc->message); -TEST (tst_syscall (__NR_capget, &hdr, data)); + hdr->version = tc->version; + hdr->pid = pid; +TEST (tst_syscall (__NR_capget, hdr, data));if (TST_RET ==0 )tst_res (TPASS ,"capget() returned %ld" ,TST_RET );else
@@ -61,4 +59,9 @@ static struct tst_test test = { TST_CAP(TST_CAP_DROP, CAP_NET_RAW), {} }, + .bufs = (struct tst_buffers []) { + {&hdr, .size =sizeof (*hdr)}, + {&data, .size =2 *sizeof (*data)}, + {}, + } };
testcases/kernel/syscalls/capget/capget02.c +38 -41
110 lines not on this page · raw message
testcases/kernel/syscalls/capset/capset01.c +18 -6
@@ -13,6 +13,9 @@#include "lapi/syscalls.h" #include <linux/capability.h> +static pid_t pid; +static struct __user_cap_header_struct *header; +static struct __user_cap_data_struct *data; static struct tcase { int version; char *message;
@@ -25,26 +28,35 @@ static struct tcase {static void verify_capset (unsigned int n) {struct tcase *tc = &tcases[n]; -struct __user_cap_header_struct header; -struct __user_cap_data_struct data[2 ];tst_res (TINFO ,"%s" , tc->message); - header.version = tc->version; - header.pid =getpid (); + header->version = tc->version; + header->pid = pid; -if (tst_syscall (__NR_capget, &header, data) ==-1 ) { +if (tst_syscall (__NR_capget, header, data) ==-1 ) {tst_res (TFAIL |TTERRNO ,"capget() failed" );return ; } -TEST (tst_syscall (__NR_capset, &header, data)); +TEST (tst_syscall (__NR_capset, header, data));if (TST_RET ==0 )tst_res (TPASS ,"capset() returned %ld" ,TST_RET );else tst_res (TFAIL |TTERRNO ,"Test Failed, capset() returned %ld" ,TST_RET ); } +static void setup (void ) +{ + pid =getpid (); +} +static struct tst_test test = { + .setup = setup, .tcnt =ARRAY_SIZE (tcases), .test = verify_capset, + .bufs = (struct tst_buffers []) { + {&header, .size =sizeof (*header)}, + {&data, .size =2 *sizeof (*data)}, + {}, + } };
Signature · 1 line
2.18.0
PATCH 1/1 syscalls/capget[set]: Make use of guarded buffers
Hi Xu,
Quoted 4 lines
Also, using pid=0 instead of
getpid()incapget02.cbecause it also returns the capabilities for the calling thread.Signed-off-by Yang Xu <[email protected]>
Reviewed-by Petr Vorel <[email protected]>
Thanks these improvements.
...
Quoted 1 line
testcases/kernel/syscalls/capget/capget02.c +0
-0
...
testcases/kernel/syscalls/capget/capget02.c line 51
Quoted 9 lines
testcases/kernel/syscalls/capget/capget02.c +7
-2-tst_res (TINFO ,"%s" , tc->message); -TEST (tst_syscall (__NR_capget, tc->headerp, tc->datap)); + header->version = tc->version; +if (tc->pid ==1 ) + header->pid = unused_pid; +else + header->pid = tc->pid; + +tst_res (TINFO ,"%s " , tc->message);
Why this extra space? I suggest to merge with the original:
tst_res(TINFO, "%s", tc->message);
Kind regards,
Petr