Tests for overlayfs immutable/append-only files
v2 cover Tests for overlayfs immutable/append-only files
Eryu,
Overlayfs never had full support for immutable/append-only files. Whatever works is covered by generic/079 and overlay/030 tests. Both tests cover only upper files and directories. generic/079 is notrun on kernel < 5.10 and passes on >= 5.10.
This series improves the t_immutable test program and adds two new tests.
overlay/075 tests immutable/append-only lower files and directories - the test fails on upstream kernel. Fixing this requires some VFS API changes that Miklos has proposed [1].
overlay/076 is a "dangerous" test that triggers a deadlock. The deadlock was fixed in master and in stable kernel v5.10.15.
Thanks,
Amir.
Changes since v1:
- Split the dangerous test
- Document fix commit
- Fix Eryu's minor review comments on t_immutable
[1] https://lore.kernel.org/linux-fsdevel/[email protected]/
Amir Goldstein (5):
overlay/030: Update comment w.r.t upstream kernel src/t_immutable: factor out some helpers src/t_immutable: Allow setting flags on existing files
overlay: Test lost immutable/append-only flags on copy-up
overlay: Regression test for deadlock on directory ioctl
src/t_immutable.c | 241 +++++++++++++++++++++--------------------- tests/overlay/030 | 7 +- tests/overlay/075 | 92 ++++++++++++++++ tests/overlay/075.out | 11 ++ tests/overlay/076 | 66 ++++++++++++ tests/overlay/076.out | 2 + tests/overlay/group | 2 + 7 files changed, 301 insertions(+), 120 deletions(-) create mode 100755 tests/overlay/075 create mode 100644 tests/overlay/075.out create mode 100644 tests/overlay/076 create mode 100644 tests/overlay/076.out
Signature · 1 line
2.25.1
PATCH v2 1/5 overlay/030: Update comment w.r.t upstream kernel
commit 61536bed2149 ("ovl: support [S|G]ETFLAGS and FS[S|G]ETXATTR ioctls for directories") makes the comment in test header inaccurate. Fix the comment to include this information.
--- tests/overlay/030 | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
tests/overlay/030 +5 -2
@@ -8,8 +8,11 @@ # and directories in an overlayfs upper directory. # # This test is similar and was derived from generic/079, but -# the original test is _notrun on overlay mount because FS_IOC_GETFLAGS -# FS_IOC_SETFLAGS ioctls fail on overlay directory inodes. +# the original test is _notrun with FSTYP=overlay on kernel < v5.10 +# because prior to commit 61536bed2149 ("ovl: support [S|G]ETFLAGS +# and FS[S|G]ETXATTR ioctls for directories"), t_immutable -c would +# fail to prepare immutable/append-only directories on the overlay +# mount path. # seq=`basename $0` seqres=$RESULT_DIR/$seq
Signature · 1 line
2.25.1
PATCH v2 2/5 src/t_immutable: factor out some helpers
In reply to Amir GoldsteinReduce boilerplate code.
define _GNU_SOURCE needed for asprintf.
--- src/t_immutable.c | 221 ++++++++++++++++++++++------------------------ 1 file changed, 104 insertions(+), 117 deletions(-)
src/t_immutable.c +104 -117
@@ -8,6 +8,9 @@#define TEST_UTIME +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif #include <stdio.h> #include <stdlib.h> #include <string.h>
@@ -1895,13 +1898,66 @@ static int check_test_area(const char *dir)return 0 ; } +static int create_dir (char **ppath,const char *fmt,const char *dir) +{ +const char *path; +struct stat st; + +if (asprintf (ppath, fmt, dir) ==-1 ) { +return 1 ; + } + path = *ppath; +if (stat (path, &st) ==0 ) { +fprintf (stderr,"%s: Test area directory %s must not exist for test area creation.\n" , + __progname, path); +return 1 ; + } +if (mkdir (path,0777 ) !=0 ) { +fprintf (stderr,"%s: error creating directory %s: %s\n" , __progname, path,strerror (errno)); +return 1 ; + } +return 0 ; +} + +static int create_file (char **ppath,const char *fmt,const char *dir) +{ +const char *path; +int fd; + +if (asprintf (ppath, fmt, dir) ==-1 ) { +return 1 ; + } + path = *ppath; +if ((fd =open (path,O_WRONLY |O_CREAT |O_EXCL ,0666 )) ==-1 ) { +fprintf (stderr,"%s: error creating file %s: %s\n" , __progname, path,strerror (errno)); +return 1 ; + } +return fd; +} + +static int create_xattrs (int fd) +{ +if (fsetxattr (fd,"trusted.test" ,"readonly" ,strlen ("readonly" ),XATTR_CREATE ) !=0 ) { +if (errno !=EOPNOTSUPP ) { +perror ("setxattr" ); +return 1 ; + } + } +if (fsetxattr (fd,"user.test" ,"readonly" ,strlen ("readonly" ),XATTR_CREATE ) !=0 ) { +if (errno !=EOPNOTSUPP ) { +perror ("setxattr" ); +return 1 ; + } + } +return 0 ; +} +static int create_test_area (const char *dir) {int fd;char *path;static const char *acl_u_text ="u::rw-,g::rw-,o::rw-,u:nobody:rw-,m::rw-" ;static const char *acl_u_text_d ="u::rwx,g::rwx,o::rwx,u:nobody:rwx,m::rwx" ; -struct stat st;static const char *immutable ="This is an immutable file.\nIts contents cannot be altered.\n" ;static const char *append_only ="This is an append-only file.\nIts contents cannot be altered.\n" "Data can only be appended.\n---\n" ;
@@ -1911,79 +1967,45 @@ static int create_test_area(const char *dir)return 1 ; } -if (stat (dir, &st) ==0 ) { -fprintf (stderr,"%s: Test area directory %s must not exist for test area creation.\n" , - __progname, dir); -return 1 ; - } -umask (0000 ); -if (mkdir (dir,0777 ) !=0 ) { -fprintf (stderr,"%s: error creating directory %s: %s\n" , __progname, dir,strerror (errno)); +if (create_dir (&path,"%s" , dir)) {return 1 ; } - -asprintf (&path,"%s/immutable.d" , dir); -if (mkdir (path,0777 ) !=0 ) { -fprintf (stderr,"%s: error creating directory %s: %s\n" , __progname, path,strerror (errno)); -return 1 ; - } -free (path); - -asprintf (&path,"%s/empty-immutable.d" , dir); -if (mkdir (path,0777 ) !=0 ) { -fprintf (stderr,"%s: error creating directory %s: %s\n" , __progname, path,strerror (errno)); -return 1 ; - }free (path); -asprintf (&path,"%s/append-only.d" , dir); -if (mkdir (path,0777 ) !=0 ) { -fprintf (stderr,"%s: error creating directory %s: %s\n" , __progname, path,strerror (errno)); -return 1 ; +if (create_dir (&path,"%s/append-only.d" , dir)) { +return 1 ; }free (path); -asprintf (&path,"%s/empty-append-only.d" , dir); -if (mkdir (path,0777 ) !=0 ) { -fprintf (stderr,"%s: error creating directory %s: %s\n" , __progname, path,strerror (errno)); -return 1 ; +if (create_dir (&path,"%s/append-only.d/dir" , dir)) { +return 1 ; }free (path); -asprintf (&path,"%s/immutable.d/dir" , dir); -if (mkdir (path,0777 ) !=0 ) { -fprintf (stderr,"%s: error creating directory %s: %s\n" , __progname, path,strerror (errno)); +if ((fd =create_file (&path,"%s/append-only.d/file" , dir)) ==-1 ) {return 1 ; } +close (fd);free (path); -asprintf (&path,"%s/append-only.d/dir" , dir); -if (mkdir (path,0777 ) !=0 ) { -fprintf (stderr,"%s: error creating directory %s: %s\n" , __progname, path,strerror (errno)); -return 1 ; +if (create_dir (&path,"%s/immutable.d" , dir)) { +return 1 ; }free (path); -asprintf (&path,"%s/append-only.d/file" , dir); -if ((fd =open (path,O_WRONLY |O_CREAT |O_EXCL ,0666 )) ==-1 ) { -fprintf (stderr,"%s: error creating file %s: %s\n" , __progname, path,strerror (errno)); -return 1 ; +if (create_dir (&path,"%s/immutable.d/dir" , dir)) { +return 1 ; } -close (fd);free (path); -asprintf (&path,"%s/immutable.d/file" , dir); -if ((fd =open (path,O_WRONLY |O_CREAT |O_EXCL ,0666 )) ==-1 ) { -fprintf (stderr,"%s: error creating file %s: %s\n" , __progname, path,strerror (errno)); +if ((fd =create_file (&path,"%s/immutable.d/file" , dir)) ==-1 ) {return 1 ; }close (fd);free (path); -asprintf (&path,"%s/immutable.f" , dir); -if ((fd =open (path,O_WRONLY |O_CREAT |O_EXCL ,0666 )) ==-1 ) { -fprintf (stderr,"%s: error creating file %s: %s\n" , __progname, path,strerror (errno)); +if ((fd =create_file (&path,"%s/immutable.f" , dir)) ==-1 ) {return 1 ; }if (write (fd, immutable,strlen (immutable)) !=strlen (immutable)) {
@@ -1994,17 +2016,8 @@ static int create_test_area(const char *dir)perror ("acl" );return 1 ; } -if (fsetxattr (fd,"trusted.test" ,"readonly" ,strlen ("readonly" ),XATTR_CREATE ) !=0 ) { -if (errno !=EOPNOTSUPP ) { -perror ("setxattr" ); -return 1 ; - } - } -if (fsetxattr (fd,"user.test" ,"readonly" ,strlen ("readonly" ),XATTR_CREATE ) !=0 ) { -if (errno !=EOPNOTSUPP ) { -perror ("setxattr" ); -return 1 ; - } +if (create_xattrs (fd)) { +return 1 ; }if (fsetflag (path, fd,1 ,1 )) {perror ("fsetflag" );
@@ -2014,8 +2027,7 @@ static int create_test_area(const char *dir)close (fd);free (path); -asprintf (&path,"%s/append-only.f" , dir); -if ((fd =open (path,O_WRONLY |O_CREAT |O_EXCL ,0666 )) ==-1 ) { +if ((fd =create_file (&path,"%s/append-only.f" , dir)) ==-1 ) {fprintf (stderr,"%s: error creating file %s: %s\n" , __progname, path,strerror (errno));return 1 ; }
@@ -2027,17 +2039,8 @@ static int create_test_area(const char *dir)perror ("acl" );return 1 ; } -if (fsetxattr (fd,"trusted.test" ,"readonly" ,strlen ("readonly" ),XATTR_CREATE ) !=0 ) { -if (errno !=EOPNOTSUPP ) { -perror ("setxattr" ); -return 1 ; - } - } -if (fsetxattr (fd,"user.test" ,"readonly" ,strlen ("readonly" ),XATTR_CREATE ) !=0 ) { -if (errno !=EOPNOTSUPP ) { -perror ("setxattr" ); -return 1 ; - } +if (create_xattrs (fd)) { +return 1 ; }if (fsetflag (path, fd,1 ,0 )) {perror ("fsetflag" );
@@ -2056,17 +2059,8 @@ static int create_test_area(const char *dir)perror ("acl" );return 1 ; } -if (fsetxattr (fd,"trusted.test" ,"readonly" ,strlen ("readonly" ),XATTR_CREATE ) !=0 ) { -if (errno !=EOPNOTSUPP ) { -perror ("setxattr" ); -return 1 ; - } - } -if (fsetxattr (fd,"user.test" ,"readonly" ,strlen ("readonly" ),XATTR_CREATE ) !=0 ) { -if (errno !=EOPNOTSUPP ) { -perror ("setxattr" ); -return 1 ; - } +if (create_xattrs (fd)) { +return 1 ; }if (fsetflag (path, fd,1 ,1 )) {perror ("fsetflag" );
@@ -2076,7 +2070,9 @@ static int create_test_area(const char *dir)close (fd);free (path); -asprintf (&path,"%s/empty-immutable.d" , dir); +if (create_dir (&path,"%s/empty-immutable.d" , dir)) { +return 1 ; + }if ((fd =open (path,O_RDONLY )) ==-1 ) {fprintf (stderr,"%s: error opening %s: %s\n" , __progname, path,strerror (errno));return 1 ;
@@ -2098,17 +2094,8 @@ static int create_test_area(const char *dir)perror ("acl" );return 1 ; } -if (fsetxattr (fd,"trusted.test" ,"readonly" ,strlen ("readonly" ),XATTR_CREATE ) !=0 ) { -if (errno !=EOPNOTSUPP ) { -perror ("setxattr" ); -return 1 ; - } - } -if (fsetxattr (fd,"user.test" ,"readonly" ,strlen ("readonly" ),XATTR_CREATE ) !=0 ) { -if (errno !=EOPNOTSUPP ) { -perror ("setxattr" ); -return 1 ; - } +if (create_xattrs (fd)) { +return 1 ; }if (fsetflag (path, fd,1 ,0 )) {perror ("fsetflag" );
@@ -2118,7 +2105,9 @@ static int create_test_area(const char *dir)close (fd);free (path); -asprintf (&path,"%s/empty-append-only.d" , dir); +if (create_dir (&path,"%s/empty-append-only.d" , dir)) { +return 1 ; + }if ((fd =open (path,O_RDONLY )) ==-1 ) {fprintf (stderr,"%s: error opening %s: %s\n" , __progname, path,strerror (errno));return 1 ;
@@ -2242,6 +2231,7 @@ int main(int argc, char **argv) {int ret;int failed =0 ; +int runtest =1 , create =0 , remove =0 ;/* this arg parsing is gross, but who cares, its a test program */
@@ -2251,32 +2241,29 @@ int main(int argc, char **argv) }if (!strcmp (argv[1 ],"-c" )) { -if (argc ==3 ) { -if ((ret =create_test_area (argv[argc-1 ]))) -return ret; - }else { -fprintf (stderr,"usage: t_immutable -c test_area_dir\n" ); -return 1 ; - } + create =1 ; }else if (!strcmp (argv[1 ],"-C" )) { -if (argc ==3 ) { -return create_test_area (argv[argc-1 ]); - }else { -fprintf (stderr,"usage: t_immutable -C test_area_dir\n" ); -return 1 ; - } +/* Prepare test area without running tests */ + create =1 ; + runtest =0 ; }else if (!strcmp (argv[1 ],"-r" )) { -if (argc ==3 ) -return remove_test_area (argv[argc-1 ]); -else { -fprintf (stderr,"usage: t_immutable -r test_area_dir\n" ); -return 1 ; - } - }else if (argc !=2 ) { -fprintf (stderr,"usage: t_immutable [-c|-r] test_area_dir\n" ); + remove =1 ; + } + +if (argc !=2 + (create | remove)) { +fprintf (stderr,"usage: t_immutable [-C|-c|-r] test_area_dir\n" );return 1 ; } +if (create) { + ret =create_test_area (argv[argc-1 ]); +if (ret || !runtest) { +return ret; + } + }else if (remove) { +return remove_test_area (argv[argc-1 ]); + } +umask (0000 );if (check_test_area (argv[argc-1 ]))
Signature · 1 line
2.25.1
PATCH v2 3/5 src/t_immutable: Allow setting flags on existing files
In reply to Amir GoldsteinFor overlayfs tests we need to be able to setflags on existing (lower) files.
t_immutable -C test_dir
Creates the test area and sets flags, but it also allows setting flags on an existing test area.
t_immutable -R test_dir
Removes the flags from existing test area, but does not remove the files in the test area.
To setup a test area with file without flags, need to run the -C and -R commands.
--- src/t_immutable.c | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-)
src/t_immutable.c +24 -6
@@ -1898,6 +1898,8 @@ static int check_test_area(const char *dir)return 0 ; } +static int allow_existing; +static int create_dir (char **ppath,const char *fmt,const char *dir) {const char *path;
@@ -1908,6 +1910,9 @@ static int create_dir(char **ppath, const char *fmt, const char *dir) } path = *ppath;if (stat (path, &st) ==0 ) { +if (allow_existing &&S_ISDIR (st.st_mode)) { +return 0 ; + }fprintf (stderr,"%s: Test area directory %s must not exist for test area creation.\n" , __progname, path);return 1 ;
@@ -1921,6 +1926,7 @@ static int create_dir(char **ppath, const char *fmt, const char *dir)static int create_file (char **ppath,const char *fmt,const char *dir) { +int flags =O_WRONLY |O_CREAT | (allow_existing ?0 :O_EXCL );const char *path;int fd;
@@ -1928,7 +1934,7 @@ static int create_file(char **ppath, const char *fmt, const char *dir)return 1 ; } path = *ppath; -if ((fd =open (path,O_WRONLY |O_CREAT |O_EXCL ,0666 )) ==-1 ) { +if ((fd =open (path, flags,0666 )) ==-1 ) {fprintf (stderr,"%s: error creating file %s: %s\n" , __progname, path,strerror (errno));return 1 ; }
@@ -1937,13 +1943,15 @@ static int create_file(char **ppath, const char *fmt, const char *dir)static int create_xattrs (int fd) { -if (fsetxattr (fd,"trusted.test" ,"readonly" ,strlen ("readonly" ),XATTR_CREATE ) !=0 ) { +int flags = allow_existing ?0 :XATTR_CREATE ; + +if (fsetxattr (fd,"trusted.test" ,"readonly" ,strlen ("readonly" ), flags) !=0 ) {if (errno !=EOPNOTSUPP ) {perror ("setxattr" );return 1 ; } } -if (fsetxattr (fd,"user.test" ,"readonly" ,strlen ("readonly" ),XATTR_CREATE ) !=0 ) { +if (fsetxattr (fd,"user.test" ,"readonly" ,strlen ("readonly" ), flags) !=0 ) {if (errno !=EOPNOTSUPP ) {perror ("setxattr" );return 1 ;
@@ -2214,6 +2222,10 @@ static int remove_test_area(const char *dir)return 1 ; } +if (allow_existing) { +return 0 ; + } + pid =fork ();if (!pid) {execl ("/bin/rm" ,"rm" ,"-rf" , dir,NULL );
@@ -2236,7 +2248,7 @@ int main(int argc, char **argv)/* this arg parsing is gross, but who cares, its a test program */ if (argc <2 ) { -fprintf (stderr,"usage: t_immutable [-C|-c|-r] test_area_dir\n" ); +fprintf (stderr,"usage: t_immutable [-C|-c|-R|-r] test_area_dir\n" );return 1 ; }
@@ -2246,18 +2258,24 @@ int main(int argc, char **argv)/* Prepare test area without running tests */ create =1 ; runtest =0 ; +/* With existing test area, only setflags */ + allow_existing =1 ; }else if (!strcmp (argv[1 ],"-r" )) { remove =1 ; + }else if (!strcmp (argv[1 ],"-R" )) { +/* Cleanup flags on test area but leave the files */ + remove =1 ; + allow_existing =1 ; }if (argc !=2 + (create | remove)) { -fprintf (stderr,"usage: t_immutable [-C|-c|-r] test_area_dir\n" ); +fprintf (stderr,"usage: t_immutable [-C|-c|-R|-r] test_area_dir\n" );return 1 ; }if (create) { ret =create_test_area (argv[argc-1 ]); -if (ret || !runtest) { +if (ret || allow_existing || !runtest) {return ret; } }else if (remove) {
Signature · 1 line
2.25.1
PATCH v2 4/5 overlay: Test lost immutable/append-only flags on copy-up
In reply to Amir GoldsteinChengguang Xu reported [1] that append-only flag is lost on copy-up. I had noticed that for directories, immutable flag can also be lost on copy up (when parent is copied up). That's an old overlayfs bug.
[1] https://lore.kernel.org/linux-unionfs/[email protected]/
--- tests/overlay/075 | 92 +++++++++++++++++++++++++++++++++++++++++++ tests/overlay/075.out | 11 ++++++ tests/overlay/group | 1 + 3 files changed, 104 insertions(+) create mode 100755 tests/overlay/075 create mode 100644 tests/overlay/075.out
tests/overlay/075 new file +92 -0
@@ -0,0 +1,92 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (C) 2021 CTERA Networks. All Rights Reserved. +# +# FS QA Test No. 075 +# +# Run the t_immutable test program for immutable/append-only files +# and directories that exist in overlayfs lower layer. +# +# This test is similar and was derived from generic/079, but instead +# of creating new files which are created in upper layer, prepare +# the test area in lower layer before running the t_immutable test on +# the overlayfs mount. +# +seq=`basename $0` +seqres=$RESULT_DIR/$seq +echo "QA output created by $seq" + +here=`pwd` +timmutable=$here/src/t_immutable +lowerdir=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER +upperdir=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER +tmp=/tmp/$$ +status=1 # failure is the default! +trap "_cleanup; exit \$status" 0 1 2 3 15 + +_cleanup() +{ + # -r will fail to remove test dirs, because we added subdirs + # we just need to remove the flags so use -R + $timmutable -R $upperdir/testdir &> /dev/null + $timmutable -R $lowerdir/testdir &> /dev/null + rm -f $tmp.* +} + +# get standard environment, filters and checks +. ./common/rc +. ./common/filter + +_supported_fs overlay + +_require_chattr ia +_require_test_program "t_immutable" +_require_scratch + +_scratch_mkfs + +# Preparing test area files in lower dir and check chattr support of base fs +mkdir -p $lowerdir +mkdir -p $upperdir +$timmutable -C $lowerdir/testdir >$tmp.out 2>&1 +if grep -q -e 'Operation not supported' -e "Inappropriate ioctl" $tmp.out; then + _notrun "Setting immutable/append flag not supported" +fi +# Remove the immutable/append-only flags and create subdirs +$timmutable -R $lowerdir/testdir >$tmp.out 2>&1 +for dir in $lowerdir/testdir/*.d; do + mkdir $dir/subdir +done +# Restore the immutable/append-only flags +$timmutable -C $lowerdir/testdir >$tmp.out 2>&1 + +_scratch_mount + +# Test immutability of files in overlay +echo "Before directories copy up" +$timmutable $SCRATCH_MNT/testdir 2>&1 + +# Trigger copy-up of immutable/append-only dirs by touching their subdirs +# inode flags are not copied-up, so immutable/append-only flags are lost +for dir in $SCRATCH_MNT/testdir/*.d; do + touch $dir/subdir +done + +# Trigger copy-up of append-only files by touching them +# inode flags are not copied-up, so append-only flags are lost +# touch on the immutable files is expected to fail, so immutable +# flags will not be lost +for file in $SCRATCH_MNT/testdir/*.f; do + touch $file > /dev/null 2>&1 +done + +# immutable/append-only flags still exist on the overlay in-core inode +# After mount cycle, flags are forever lost +_scratch_cycle_mount + +# Test immutability of files in overlay after directories copy-up +echo "After directories copy up" +$timmutable $SCRATCH_MNT/testdir 2>&1 + +status=$? +exit
tests/overlay/075.out new file +11 -0
@@ -0,0 +1,11 @@ +QA output created by 075 +Before directories copy up +testing immutable...PASS. +testing append-only...PASS. +testing immutable as non-root...PASS. +testing append-only as non-root...PASS. +After directories copy up +testing immutable...PASS. +testing append-only...PASS. +testing immutable as non-root...PASS. +testing append-only as non-root...PASS.
tests/overlay/group +1 -0
@@ -77,6 +77,7 @@ 072 auto quick copyup hardlink 073 auto quick whiteout 074 auto quick exportfs dangerous +075 auto quick perms 100 auto quick union samefs 101 auto quick union nonsamefs 102 auto quick union nonsamefs xino
Signature · 1 line
2.25.1
PATCH v2 5/5 overlay: Regression test for deadlock on directory ioctl
In reply to Amir GoldsteinOverlayfs added the ability to set inode flags (e.g. chattr +i) in kernel 5.10 by commit 61536bed2149 ("ovl: support [S|G]ETFLAGS and FS[S|G]ETXATTR ioctls for directories").
Icenowy Zheng reported [1] a regression in that commit that causes a deadlock when setting inode flags on lower dir.
The regression was fixed by commit b854cc659dcb ("ovl: avoid deadlock on directory ioctl") and applied to kernel 5.10.15.
[1] https://lore.kernel.org/linux-unionfs/[email protected]/
--- tests/overlay/076 | 66 +++++++++++++++++++++++++++++++++++++++++++ tests/overlay/076.out | 2 ++ tests/overlay/group | 1 + 3 files changed, 69 insertions(+) create mode 100644 tests/overlay/076 create mode 100644 tests/overlay/076.out
tests/overlay/076 new file +66 -0
@@ -0,0 +1,66 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (C) 2021 CTERA Networks. All Rights Reserved. +# +# FS QA Test 076 +# +# Support for chattr on overlayfs directories was added in kernel v5.10 +# by commit 61536bed2149 ("ovl: support [S|G]ETFLAGS and FS[S|G]ETXATTR +# ioctls for directories"). That commit introduced a deadlock. +# +# This is a regression test for the fix commit b854cc659dcb ("ovl: avoid +# deadlock on directory ioctl") +# +seq=`basename $0` +seqres=$RESULT_DIR/$seq +echo "QA output created by $seq" + +here=`pwd` +tmp=/tmp/$$ +status=1 # failure is the default! +trap "_cleanup; exit \$status" 0 1 2 3 15 + +_cleanup() +{ + cd / + $CHATTR_PROG -i $lowerdir/foo > /dev/null 2>&1 + $CHATTR_PROG -i $upperdir/foo > /dev/null 2>&1 + rm -f $tmp.* +} + +# get standard environment, filters and checks +. ./common/rc +. ./common/filter + +# remove previous $seqres.full before test +rm -f $seqres.full + +# real QA test starts here +_supported_fs overlay +_require_scratch +_require_chattr i + +# remove all files from previous runs +_scratch_mkfs + +# prepare lower test file +lowerdir=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER +upperdir=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER +workdir=$OVL_BASE_SCRATCH_MNT/$OVL_WORK +mkdir -p $lowerdir +mkdir $lowerdir/foo + +# mounting overlay +_scratch_mount + +# Try to add the immutable attributes, it will invoke ioctl() on the directory +# The ioctl will fail on kernel < 5.10, succeed on kernel >= 5.10.15 and hang +# on kernel v5.10..v5.10.14. Anything but hang is considered a test success. +$CHATTR_PROG +i $SCRATCH_MNT/foo > /dev/null 2>&1 + +$UMOUNT_PROG $SCRATCH_MNT + +# success, all done +echo "Silence is golden" +status=0 +exit
tests/overlay/076.out new file +2 -0
@@ -0,0 +1,2 @@ +QA output created by 076 +Silence is golden
tests/overlay/group +1 -0
@@ -78,6 +78,7 @@ 073 auto quick whiteout 074 auto quick exportfs dangerous 075 auto quick perms +076 auto quick perms dangerous 100 auto quick union samefs 101 auto quick union nonsamefs 102 auto quick union nonsamefs xino
Signature · 1 line
2.25.1