tests: check decoding of successful quotactl
* tests/quotactl-success.c: New file. * tests/quotactl-success-v.c: Likewise. * tests/quotactl-xfs-success.c: Likewise. * tests/quotactl-xfs-success-v.c: Likewise. * tests/quotactl-success.test: New test. * tests/quotactl-success-v.test: Likewise. * tests/quotactl-xfs-success.test: Likewise. * tests/quotactl-xfs-success-v.test: Likewise. * tests/.gitignore: Add quotactl-success, quotactl-success-v, quotactl-xfs-success and quotactl-xfs-success-v. * tests/Makefile.am (check_PROGRAMS): Likewise. (DECODER_TESTS): Add four new tests listed above. * tests/quotactl.h: [INJECT_RETVAL] (check_quota): Use errstr instead of sprintrc; check that returned value is equivalent to the injected one; append "(INJECTED)" string to errstr. * tests/quotactl.c: Changed condition rc != 0 to rc < 0 in callback functions and value of opaque pointer addr_cb_arg in order to check successful injection. * tests/quotactl-xfs.c: Likewise.
This commit is contained in:
parent
860ccdefea
commit
1b5b5b76b5
4
tests/.gitignore
vendored
4
tests/.gitignore
vendored
@ -390,6 +390,10 @@ quotactl
|
||||
quotactl-v
|
||||
quotactl-xfs
|
||||
quotactl-xfs-v
|
||||
quotactl-success
|
||||
quotactl-success-v
|
||||
quotactl-xfs-success
|
||||
quotactl-xfs-success-v
|
||||
read-write
|
||||
readahead
|
||||
readdir
|
||||
|
@ -153,6 +153,10 @@ check_PROGRAMS = $(PURE_EXECUTABLES) \
|
||||
qual_signal \
|
||||
quotactl-v \
|
||||
quotactl-xfs-v \
|
||||
quotactl-success \
|
||||
quotactl-success-v \
|
||||
quotactl-xfs-success \
|
||||
quotactl-xfs-success-v \
|
||||
redirect-fds \
|
||||
restart_syscall \
|
||||
run_expect_termsig \
|
||||
@ -273,6 +277,10 @@ DECODER_TESTS = \
|
||||
prctl-tid_address.test \
|
||||
prctl-tsc.test \
|
||||
qual_fault-exit_group.test \
|
||||
quotactl-success.test \
|
||||
quotactl-success-v.test \
|
||||
quotactl-xfs-success.test \
|
||||
quotactl-xfs-success-v.test \
|
||||
readv.test \
|
||||
rt_sigaction.test \
|
||||
scm_rights-fd.test \
|
||||
|
2
tests/quotactl-success-v.c
Normal file
2
tests/quotactl-success-v.c
Normal file
@ -0,0 +1,2 @@
|
||||
#define INJECT_RETVAL 42
|
||||
#include "quotactl-v.c"
|
6
tests/quotactl-success-v.test
Executable file
6
tests/quotactl-success-v.test
Executable file
@ -0,0 +1,6 @@
|
||||
#!/bin/sh -efu
|
||||
|
||||
. "${srcdir=.}/scno_tampering.sh"
|
||||
|
||||
run_strace -v -e trace=quotactl -e inject=quotactl:retval=42 ../quotactl-success-v > "$EXP"
|
||||
match_diff "$LOG" "$EXP"
|
2
tests/quotactl-success.c
Normal file
2
tests/quotactl-success.c
Normal file
@ -0,0 +1,2 @@
|
||||
#define INJECT_RETVAL 42
|
||||
#include "quotactl.c"
|
6
tests/quotactl-success.test
Executable file
6
tests/quotactl-success.test
Executable file
@ -0,0 +1,6 @@
|
||||
#!/bin/sh -efu
|
||||
|
||||
. "${srcdir=.}/scno_tampering.sh"
|
||||
|
||||
run_strace -e trace=quotactl -e inject=quotactl:retval=42 ../quotactl-success > "$EXP"
|
||||
match_diff "$LOG" "$EXP"
|
2
tests/quotactl-xfs-success-v.c
Normal file
2
tests/quotactl-xfs-success-v.c
Normal file
@ -0,0 +1,2 @@
|
||||
#define INJECT_RETVAL 42
|
||||
#include "quotactl-xfs-v.c"
|
6
tests/quotactl-xfs-success-v.test
Executable file
6
tests/quotactl-xfs-success-v.test
Executable file
@ -0,0 +1,6 @@
|
||||
#!/bin/sh -efu
|
||||
|
||||
. "${srcdir=.}/scno_tampering.sh"
|
||||
|
||||
run_strace -v -e trace=quotactl -e inject=quotactl:retval=42 ../quotactl-xfs-success-v > "$EXP"
|
||||
match_diff "$LOG" "$EXP"
|
2
tests/quotactl-xfs-success.c
Normal file
2
tests/quotactl-xfs-success.c
Normal file
@ -0,0 +1,2 @@
|
||||
#define INJECT_RETVAL 42
|
||||
#include "quotactl-xfs.c"
|
6
tests/quotactl-xfs-success.test
Executable file
6
tests/quotactl-xfs-success.test
Executable file
@ -0,0 +1,6 @@
|
||||
#!/bin/sh -efu
|
||||
|
||||
. "${srcdir=.}/scno_tampering.sh"
|
||||
|
||||
run_strace -e trace=quotactl -e inject=quotactl:retval=42 ../quotactl-xfs-success > "$EXP"
|
||||
match_diff "$LOG" "$EXP"
|
@ -92,7 +92,7 @@ print_xdisk_quota(int rc, void *ptr, void *arg)
|
||||
struct fs_disk_quota *dq = ptr;
|
||||
long out_arg = (long) arg;
|
||||
|
||||
if (((rc != 0) && out_arg) || (out_arg > 1)) {
|
||||
if (((rc < 0) && out_arg) || (out_arg > 1)) {
|
||||
printf("%p", dq);
|
||||
return;
|
||||
}
|
||||
@ -132,7 +132,7 @@ print_xquota_stat(int rc, void *ptr, void *arg)
|
||||
struct fs_quota_stat *qs = ptr;
|
||||
long out_arg = (long) arg;
|
||||
|
||||
if (((rc != 0) && out_arg) || (out_arg > 1)) {
|
||||
if (((rc < 0) && out_arg) || (out_arg > 1)) {
|
||||
printf("%p", qs);
|
||||
return;
|
||||
}
|
||||
@ -166,7 +166,7 @@ print_xquota_statv(int rc, void *ptr, void *arg)
|
||||
struct fs_quota_statv *qs = ptr;
|
||||
long out_arg = (long) arg;
|
||||
|
||||
if (((rc != 0) && out_arg) || (out_arg > 1)) {
|
||||
if (((rc < 0) && out_arg) || (out_arg > 1)) {
|
||||
printf("%p", qs);
|
||||
return;
|
||||
}
|
||||
@ -269,7 +269,7 @@ main(void)
|
||||
(intptr_t) 1);
|
||||
|
||||
check_quota(CQF_ADDR_CB, ARG_STR(QCMD(Q_XGETQUOTA, GRPQUOTA)),
|
||||
ARG_STR(NULL), -1, xdq, print_xdisk_quota, (intptr_t) 2);
|
||||
ARG_STR(NULL), -1, xdq, print_xdisk_quota, (intptr_t) 1);
|
||||
|
||||
|
||||
/* Q_XGETNEXTQUOTA */
|
||||
@ -299,7 +299,7 @@ main(void)
|
||||
|
||||
check_quota(CQF_ID_SKIP | CQF_ADDR_CB,
|
||||
ARG_STR(QCMD(Q_XGETQSTAT, USRQUOTA)),
|
||||
ARG_STR("NULL"), xqstat, print_xquota_stat, (intptr_t) 2);
|
||||
ARG_STR("NULL"), xqstat, print_xquota_stat, (intptr_t) 1);
|
||||
|
||||
check_quota(CQF_ID_SKIP,
|
||||
ARG_STR(QCMD(Q_XGETQSTAT, PRJQUOTA)),
|
||||
@ -315,7 +315,7 @@ main(void)
|
||||
|
||||
check_quota(CQF_ID_SKIP | CQF_ADDR_CB,
|
||||
ARG_STR(QCMD(Q_XGETQSTATV, GRPQUOTA)),
|
||||
ARG_STR(NULL), xqstatv, print_xquota_statv, (intptr_t) 2);
|
||||
ARG_STR(NULL), xqstatv, print_xquota_statv, (intptr_t) 1);
|
||||
|
||||
check_quota(CQF_ID_SKIP,
|
||||
ARG_STR(QCMD(Q_XGETQSTATV, PRJQUOTA)),
|
||||
|
@ -83,7 +83,7 @@ print_dqblk(long rc, void *ptr, void *arg)
|
||||
struct if_dqblk *db = ptr;
|
||||
long out_arg = (long) arg;
|
||||
|
||||
if (((rc != 0) && out_arg) || (out_arg > 1)) {
|
||||
if (((rc < 0) && out_arg) || (out_arg > 1)) {
|
||||
printf("%p", db);
|
||||
return;
|
||||
}
|
||||
@ -113,7 +113,7 @@ print_nextdqblk(long rc, void *ptr, void *arg)
|
||||
struct if_nextdqblk *db = ptr;
|
||||
long out_arg = (long) arg;
|
||||
|
||||
if (((rc != 0) && out_arg) || (out_arg > 1)) {
|
||||
if (((rc < 0) && out_arg) || (out_arg > 1)) {
|
||||
printf("%p", db);
|
||||
return;
|
||||
}
|
||||
@ -146,7 +146,7 @@ print_dqinfo(long rc, void *ptr, void *arg)
|
||||
struct if_dqinfo *di = ptr;
|
||||
long out_arg = (long) arg;
|
||||
|
||||
if (((rc != 0) && out_arg) || (out_arg > 1)) {
|
||||
if (((rc < 0) && out_arg) || (out_arg > 1)) {
|
||||
printf("%p", di);
|
||||
return;
|
||||
}
|
||||
@ -168,7 +168,7 @@ print_dqfmt(long rc, void *ptr, void *arg)
|
||||
long out_arg = (long) arg;
|
||||
const char *fmtstr;
|
||||
|
||||
if (((rc != 0) && out_arg) || (out_arg > 1)) {
|
||||
if (((rc < 0) && out_arg) || (out_arg > 1)) {
|
||||
printf("%p", fmtval);
|
||||
return;
|
||||
}
|
||||
@ -272,7 +272,7 @@ main(void)
|
||||
(intptr_t) 1);
|
||||
|
||||
check_quota(CQF_ADDR_CB, ARG_STR(QCMD(Q_GETQUOTA, GRPQUOTA)),
|
||||
ARG_STR(NULL), -1, dqblk, print_dqblk, (intptr_t) 2);
|
||||
ARG_STR(NULL), -1, dqblk, print_dqblk, (intptr_t) 1);
|
||||
|
||||
|
||||
/* Q_GETNEXTQUOTA */
|
||||
@ -303,7 +303,7 @@ main(void)
|
||||
check_quota(CQF_ID_SKIP | CQF_ADDR_CB,
|
||||
ARG_STR(QCMD(Q_GETINFO, GRPQUOTA)),
|
||||
bogus_special, bogus_special_str, dqinfo,
|
||||
print_dqinfo, (intptr_t) 2);
|
||||
print_dqinfo, (intptr_t) 1);
|
||||
|
||||
/* Q_SETINFO */
|
||||
|
||||
|
@ -78,6 +78,7 @@ enum check_quotactl_flags {
|
||||
CQF_ADDR_CB = 1 << CQF_ADDR_CB_BIT,
|
||||
};
|
||||
|
||||
static const char *errstr;
|
||||
|
||||
/**
|
||||
* Generic quotactl syscall checker function. Call convention:
|
||||
@ -181,6 +182,20 @@ check_quota(uint32_t flags, int cmd, const char *cmd_str,
|
||||
va_end(ap);
|
||||
|
||||
rc = syscall(__NR_quotactl, cmd, special, id, addr);
|
||||
|
||||
errstr = sprintrc(rc);
|
||||
|
||||
#ifdef INJECT_RETVAL
|
||||
if (rc != INJECT_RETVAL)
|
||||
error_msg_and_fail("Got a return value of %ld != %d",
|
||||
rc, INJECT_RETVAL);
|
||||
|
||||
static char inj_errstr[4096];
|
||||
|
||||
snprintf(inj_errstr, sizeof(inj_errstr), "%s (INJECTED)", errstr);
|
||||
errstr = inj_errstr;
|
||||
#endif
|
||||
|
||||
printf("quotactl(%s, %s", cmd_str, special_str);
|
||||
|
||||
if (!(flags & CQF_ID_SKIP)) {
|
||||
@ -205,7 +220,7 @@ check_quota(uint32_t flags, int cmd, const char *cmd_str,
|
||||
}
|
||||
}
|
||||
|
||||
printf(") = %s\n", sprintrc(rc));
|
||||
printf(") = %s\n", errstr);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user