[LTP] [PATCH v1] chdir01.c: set umask to 0 within setup

Petr Vorel pvorel@suse.cz
Thu Mar 7 22:33:35 CET 2024


Hi Martin, all,

> Hi,
> you're trying to fix a vfat mount quirk. We should fix that in the LTP
> library instead, e.g. by setting umask(0) and then restoring the original
> value inside safe_mount().

This makes sense. FYI Wei first tried to adjust umask globally for all tests in
the do_setup() [1], which I worried it would influence tests.

Later Li fixed problem in cgroup tests [2]. This is obviously more general
solution, Wei please send a patch for it and to the commit message
Suggested-by: Martin Doucha <mdoucha@suse.cz>

While we are fixing issues caused by too restrictive umask (Wei fixed e.g.
statx07 [3]), just to let you know that some failures are kernel failures (at
least creat09 which uses all_filesystems, had bug on XFS [4], which got fixed
in the kernel).

Kind regards,
Petr

[1] https://lore.kernel.org/ltp/20240219134845.22171-1-wegao@suse.com/
[2] https://github.com/linux-test-project/ltp/commit/50626b4a1d01caacd418156ec997853bd4a9fc39
[3] https://github.com/linux-test-project/ltp/commit/d95f453ac624dc159d3acddb62eadeb9a8215f0e
[4] https://lore.kernel.org/ltp/62343BF2.1020006@fujitsu.com/

> On 06. 03. 24 11:46, Wei Gao via ltp wrote:
> > When system's default umask is 0077, this will trigger following issues:
> > chdir01.c:100: TFAIL: nobody: chdir("subdir") returned unexpected value -1: EACCES (13)

> > Signed-off-by: Wei Gao <wegao@suse.com>
> > ---
> >   testcases/kernel/syscalls/chdir/chdir01.c | 11 ++++++++---
> >   1 file changed, 8 insertions(+), 3 deletions(-)

> > diff --git a/testcases/kernel/syscalls/chdir/chdir01.c b/testcases/kernel/syscalls/chdir/chdir01.c
> > index d50a8f50c..97a707199 100644
> > --- a/testcases/kernel/syscalls/chdir/chdir01.c
> > +++ b/testcases/kernel/syscalls/chdir/chdir01.c
> > @@ -56,12 +56,15 @@ static struct test_case {
> >   static void setup(void)
> >   {
> > +	mode_t old_umask = umask(0);
> > +
> > +	SAFE_MKFS(tst_device->dev, tst_device->fs_type, NULL, NULL);Hi,
> > +	SAFE_MOUNT(tst_device->dev, MNTPOINT, tst_device->fs_type, 0, 0);
> > +
> >   	char *cwd;
> >   	int fd;
> >   	struct stat statbuf;
> > -	umask(0);
> > -
> >   	cwd = SAFE_GETCWD(NULL, 0);
> >   	workdir = SAFE_MALLOC(strlen(cwd) + strlen(MNTPOINT) + 2);
> >   	sprintf(workdir, "%s/%s", cwd, MNTPOINT);
> > @@ -89,6 +92,7 @@ static void setup(void)
> >   	if (!ltpuser)
> >   		ltpuser = SAFE_GETPWNAM(TESTUSER);
> > +	umask(old_umask);
> >   }
> >   static void check_result(const char *user, const char *name, int retval,
> > @@ -146,13 +150,14 @@ static void cleanup(void)
> >   {
> >   	SAFE_CHDIR("..");
> >   	free(workdir);
> > +	SAFE_UMOUNT(MNTPOINT);
> >   }
> >   static struct tst_test test = {
> >   	.needs_root = 1,
> > -	.mount_device = 1,
> >   	.mntpoint = MNTPOINT,
> >   	.all_filesystems = 1,
> > +	.needs_device = 1,
> >   	.test = run,
> >   	.tcnt = ARRAY_SIZE(testcase_list),
> >   	.setup = setup,


More information about the ltp mailing list