[LTP] [PATCH v2 2/2] syscalls/faccessat202: Add new testcase
Cyril Hrubis
chrubis@suse.cz
Tue Aug 22 16:59:22 CEST 2023
Hi!
> +static struct passwd *ltpuser;
> +
> +static struct tcase {
> + int *fd;
> + char **filename;
> + int mode;
> + int flags;
> + int exp_errno;
> +} tcases[] = {
> + {&atcwd_fd, &bad_path, R_OK, 0, EFAULT},
> + {&atcwd_fd, &rel_path, R_OK, -1, EINVAL},
> + {&atcwd_fd, &rel_path, -1, 0, EINVAL},
> + {&bad_fd, &rel_path, R_OK, 0, EBADF},
> + {&fd, &rel_path, R_OK, 0, ENOTDIR},
> + {&atcwd_fd, &rel_path, R_OK, AT_EACCESS, EACCES},
> +};
> +
> +static void verify_faccessat2(unsigned int i)
> +{
> + struct tcase *tc = &tcases[i];
> +
> + if (tc->exp_errno == EACCES) {
> + if (SAFE_FORK() == 0) {
> + SAFE_SETUID(ltpuser->pw_uid);
^
Should be SAFE_SETEUID() right?
Because the AT_EACESS causes the call to use EUID instead of UID so we
have to change only the EUID and keep the UID to root UID.
And with that we can drop the SAFE_FORK() since we can change EUID back
as long as UID is priviledged, so the code should be:
if (tc->exp_errno == EACESS)
SAFE_SETEUID(ltpuser->pw_uid);
TST_EXP_FAIL(...);
if (tc->exp_errno == EACESS)
SAFE_SETEUID(ltpuser->pw_uid);
> + TST_EXP_FAIL(faccessat2(*tc->fd, *tc->filename,
> + tc->mode, tc->flags), tc->exp_errno);
> + }
> +
> + tst_reap_children();
> + } else {
> + TST_EXP_FAIL(faccessat2(*tc->fd, *tc->filename,
> + tc->mode, tc->flags), tc->exp_errno);
Can we get a better message here? As it is it prints
"faccessat2(*tc->fd, *tc->filename, tc->mode, tc->flags) ..."
Which is a bit ugly.
> + }
> +}
> +
> +static void setup(void)
> +{
> + SAFE_MKDIR(TESTDIR, 0666);
> + SAFE_TOUCH(RELPATH, 0444, NULL);
> +
> + fd = SAFE_OPEN(RELPATH, O_RDONLY);
> + bad_path = tst_get_bad_addr(NULL);
> +
> + ltpuser = SAFE_GETPWNAM(TESTUSER);
> +}
> +
> +static void cleanup(void)
> +{
> + if (fd > -1)
> + SAFE_CLOSE(fd);
> +}
> +
> +static struct tst_test test = {
> + .test = verify_faccessat2,
> + .tcnt = ARRAY_SIZE(tcases),
> + .setup = setup,
> + .cleanup = cleanup,
> + .bufs = (struct tst_buffers []) {
> + {&rel_path, .str = RELPATH},
> + {},
> + },
> + .needs_tmpdir = 1,
> + .needs_root = 1,
> + .forks_child = 1,
> +};
> --
> 2.39.1
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
--
Cyril Hrubis
chrubis@suse.cz
More information about the ltp
mailing list