[LTP] [PATCH v16 2/2] open16: allow restricted O_CREAT of FIFOs and regular files

Wei Gao wegao@suse.com
Fri Oct 23 04:46:53 CEST 2026


On Thu, Oct 22, 2026 at 05:44:36PM +0200, Petr Vorel wrote:
> Hi Wei,
> 
> ...
> > +static void verify_open(unsigned int n)
> > +{
> > +	struct tcase *tc = &tcases[n];
> > +
> > +	SAFE_FILE_PRINTF(PATH_FS_PROTECTED_REGULAR, "%u", n);
> > +	SAFE_FILE_PRINTF(PATH_FS_PROTECTED_FIFOS, "%u", n);
> > +
> > +	if (tc->owner_uid != (uid_t)-1 || tc->use_nobody_gid) {
> > +		gid_t gid = tc->use_nobody_gid ? gid1 : 0;
> > +
> > +		SAFE_CHOWN(DIR, tc->owner_uid, gid);
> > +	}
> > +
> > +	if (tc->dir_mode)
> > +		SAFE_CHMOD(DIR, tc->dir_mode);
> > +
> > +	if (SAFE_FORK())
> > +		return;
> > +
> > +	SAFE_SETGID(gid1);
> > +	SAFE_SETUID(uid2);
> > +
> > +	TST_EXP_FD_OR_FAIL(openat(dir_fd, TEST_FILE, O_RDWR | O_CREAT, 0777),
> > +			   tc->exp_errno, "openat %s (sysctl_val=%u)", TEST_FILE, n);
> > +	if (TST_RET != -1)
> > +		SAFE_CLOSE(TST_RET);
> > +
> > +	TST_EXP_FD_OR_FAIL(open(TEST_FIFO_PATH, O_RDWR | O_CREAT, 0777),
> > +			   tc->exp_errno, "open %s (sysctl_val=%u)", TEST_FIFO, n);
> > +	if (TST_RET != -1)
> > +		SAFE_CLOSE(TST_RET);
> > +
> > +	exit(0);
> 
> Do we need this explicit exit?
Yes i think exit(0) is necessary because only the child process reaches this point.
> 
> The rest LGTM.
> Reviewed-by: Petr Vorel <pvorel@suse.cz>
> 
> Kind regards,
> Petr


More information about the ltp mailing list