Linux Test Project
 help / color / mirror / Atom feed
From: Cyril Hrubis <chrubis@suse.cz>
To: Sachin Sant <sachinp@linux.ibm.com>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v5 1/8] fs/acl: Add ACL_USER_OBJ permission test
Date: Mon, 8 Jun 2026 16:25:29 +0200	[thread overview]
Message-ID: <aibQ2bRNgwTFl4y8@yuki.lan> (raw)
In-Reply-To: <8a4a075d-0440-4f16-b88c-f09b1961e030@linux.ibm.com>

Hi!
> >> +static inline int create_file_as(uid_t uid, gid_t gid, mode_t mode,
> >> +				 int use_umask, mode_t mask)
> >> +{
> >> +	pid_t pid;
> >> +	int status;
> >> +
> >> +	pid = SAFE_FORK();
> >> +	if (!pid) {
> >> +		int fd, err;
> >> +
> >> +		if (setgroups(0, NULL) == -1) {
> >> +			err = errno;
> >> +			_exit(err);
> >> +		}
> >> +
> >> +		if (setgid(gid) == -1) {
> >> +			err = errno;
> >> +			_exit(err);
> >> +		}
> >> +
> >> +		if (setuid(uid) == -1) {
> >> +			err = errno;
> >> +			_exit(err);
> >> +		}
> > These should be SAFE_MACROS().
> Can you elaborate on this?
> This code runs in a forked child process that intentionally tests 
> permission scenarios.
> The function expects these calls to potentially fail as part of testing 
> ACL behavior.
> 
> The current pattern of capturing errno and exiting with it is correct for
> communicating failure back to the parent.
> SAFE_* macros would call tst_brk(TBROK) on failure, which is 
> inappropriate in
> a child process testing permissions.

It does test the permissions for the open() call. It's wrong to check
the errnos from set*() calls.

> The parent process checks the exit status to determine if the operation
> succeeded or failed (line 442: return WEXITSTATUS(status))

And as I described below we do not want to propagate results in LTP. We
should report PASS/FAIL as close to the call that we check as possible.
With that we avoid all possible bugs in result propagation.

> >> +		if (use_umask)
> >> +			umask(mask);
> >> +
> >> +		fd = open(TESTFILE, O_CREAT | O_WRONLY, mode);
> >> +		if (fd >= 0) {
> >> +			close(fd);
> >> +			_exit(0);
> >> +		}
> > Generally in LTP we want to check the test conditions right after they
> > happen. So this function should get expected errno as last parameter and
> > we should check for the result right here with something as:
> >
> > 	if (errno)
> > 		ST_EXP_FAIL()
> > 	else
> > 		TST_EXP_FD()
> >
> > With that we do need to propagate the return value manually, which is
> > prone to errors, and do not need to process the child exit value
> > manually, we can just let the library collect the children with
> > tst_reap_children().

-- 
Cyril Hrubis
chrubis@suse.cz

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

  reply	other threads:[~2026-06-08 14:25 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-08  9:21 [LTP] [PATCH v5 0/8] Convert shell-based ACL test (tacl_xattr.sh) to C Sachin Sant
2026-06-08  9:21 ` [LTP] [PATCH v5 1/8] fs/acl: Add ACL_USER_OBJ permission test Sachin Sant
2026-06-08 11:01   ` [LTP] " linuxtestproject.agent
2026-06-08 11:57   ` [LTP] [PATCH v5 1/8] " Cyril Hrubis
2026-06-08 13:40     ` Sachin Sant
2026-06-08 14:25       ` Cyril Hrubis [this message]
2026-06-08  9:21 ` [LTP] [PATCH v3 2/8] fs/acl: Add ACL mask interaction tests Sachin Sant
2026-06-08  9:21 ` [LTP] [PATCH v3 3/8] fs/acl: Add ACL_OTHER permissions test Sachin Sant
2026-06-08  9:21 ` [LTP] [PATCH v4 4/8] fs/acl: Add default ACL inheritance test Sachin Sant
2026-06-08  9:21 ` [LTP] [PATCH v3 5/8] fs/acl: Add chmod/chown ACL interaction tests Sachin Sant
2026-06-08  9:21 ` [LTP] [PATCH v5 6/8] fs/acl: Add symlink ACL operations test Sachin Sant
2026-06-08  9:21 ` [LTP] [PATCH v4 7/8] fs/acl: Add extended attributes test Sachin Sant
2026-06-08  9:22 ` [LTP] [PATCH v1 8/8] fs/acl: Remove old shell-based ACL test Sachin Sant

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=aibQ2bRNgwTFl4y8@yuki.lan \
    --to=chrubis@suse.cz \
    --cc=ltp@lists.linux.it \
    --cc=sachinp@linux.ibm.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