public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Cyril Hrubis <chrubis@suse.cz>
To: Yang Xu <xuyang2018.jy@fujitsu.com>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v2 2/2] syscalls/faccessat202: Add new testcase
Date: Tue, 22 Aug 2023 16:59:22 +0200	[thread overview]
Message-ID: <ZOTNSlPaoSaxU493@yuki> (raw)
In-Reply-To: <1692700900-13521-2-git-send-email-xuyang2018.jy@fujitsu.com>

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

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

  reply	other threads:[~2023-08-22 14:59 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-22 10:41 [LTP] [PATCH v2 1/2] syscalls/faccessat201: Add new testcase Yang Xu
2023-08-22 10:41 ` [LTP] [PATCH v2 2/2] syscalls/faccessat202: " Yang Xu
2023-08-22 14:59   ` Cyril Hrubis [this message]
2023-08-23  3:52     ` Yang Xu (Fujitsu)
2023-08-23  6:51       ` Cyril Hrubis
2023-08-22 14:22 ` [LTP] [PATCH v2 1/2] syscalls/faccessat201: " Cyril Hrubis

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=ZOTNSlPaoSaxU493@yuki \
    --to=chrubis@suse.cz \
    --cc=ltp@lists.linux.it \
    --cc=xuyang2018.jy@fujitsu.com \
    /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