squashfs: Add regression test for sanity check bug
PATCH 1/1 squashfs: Add regression test for sanity check bug
From: Joerg Vehlow <[email protected]>
Adds a regression test for the fixesc1b2028315 ("squashfs: fix inode lookup sanity checks ?") and8b44ca2b62 ("squashfs: fix xattr id and id lookup sanity checks")
--- runtest/fs | 2 + testcases/kernel/fs/squashfs/.gitignore | 1 + testcases/kernel/fs/squashfs/Makefile | 11 +++ .../kernel/fs/squashfs/squashfs-createfiles.c | 84 +++++++++++++++++++ .../kernel/fs/squashfs/squashfs_regression.sh | 65 ++++++++++++++ 5 files changed, 163 insertions(+) create mode 100644 testcases/kernel/fs/squashfs/.gitignore create mode 100644 testcases/kernel/fs/squashfs/Makefile create mode 100644 testcases/kernel/fs/squashfs/squashfs-createfiles.c create mode 100755 testcases/kernel/fs/squashfs/squashfs_regression.sh
runtest/fs +2 -0
@@ -85,3 +85,5 @@ fs_fill fs_fill binfmt_misc01 binfmt_misc01.sh binfmt_misc02 binfmt_misc02.sh + +squashfs_regression_sh squashfs_regression.sh
testcases/kernel/fs/squashfs/.gitignore new file +1 -0
@@ -0,0 +1 @@ +squashfs-createfiles
testcases/kernel/fs/squashfs/Makefile new file +11 -0
@@ -0,0 +1,11 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (C) 2009, Cisco Systems Inc. +# Ngie Cooper, July 2009 + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/testcases.mk + +INSTALL_TARGETS := squashfs_regression.sh + +include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/fs/squashfs/squashfs-createfiles.c new file +84 -0
84 lines not on this page · raw message
testcases/kernel/fs/squashfs/squashfs_regression.sh new file +65 -0
65 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH 1/1 squashfs: Add regression test for sanity check bug
Hi!
Quoted 131 lines
Adds a regression test for the fixes
c1b2028315("squashfs: fix inode lookup sanity checks ???") and8b44ca2b62("squashfs: fix xattr id and id lookup sanity checks")Signed-off-by Joerg Vehlow <[email protected]>--- runtest/fs | 2 + testcases/kernel/fs/squashfs/.gitignore | 1 + testcases/kernel/fs/squashfs/Makefile | 11 +++ .../kernel/fs/squashfs/squashfs-createfiles.c | 84 +++++++++++++++++++ .../kernel/fs/squashfs/squashfs_regression.sh | 65 ++++++++++++++ 5 files changed, 163 insertions(+) create mode 100644 testcases/kernel/fs/squashfs/.gitignore create mode 100644 testcases/kernel/fs/squashfs/Makefile create mode 100644 testcases/kernel/fs/squashfs/squashfs-createfiles.c create mode 100755 testcases/kernel/fs/squashfs/squashfs_regression.shruntest/fs +2
-0@@ -85,3 +85,5 @@ fs_fill fs_fill binfmt_misc01 binfmt_misc01.sh binfmt_misc02 binfmt_misc02.sh + +squashfs_regression_sh squashfs_regression.shtestcases/kernel/fs/squashfs/.gitignore new file +1
-0@@ -0,0 +1 @@ +squashfs-createfilestestcases/kernel/fs/squashfs/Makefile new file +11
-0@@ -0,0 +1,11 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (C) 2009, Cisco Systems Inc. +# Ngie Cooper, July 2009 + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/testcases.mk + +INSTALL_TARGETS := squashfs_regression.sh + +include $(top_srcdir)/include/mk/generic_leaf_target.mktestcases/kernel/fs/squashfs/squashfs-createfiles.c new file +73
-0@@ -0,0 +1,84 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2021 Joerg Vehlow <[email protected]> +* +* Simple c program for fast batch creation of dummy files, +* it can also set unique uid/gid combinations and xattr for +* all files creates. The same as shell code is extremely slower. +*/ + + +#include <stdlib.h> +#include <stdio.h> +#include <sys/stat.h> +#include <sys/types.h> +#include <unistd.h> +#include <fcntl.h> +#include <sys/xattr.h> + +#define TST_NO_DEFAULT_MAIN +#include "tst_test.h" +#include "tst_safe_macros.h" + +void print_usage (const char *name) +{ +printf ("Usage: %s [OPTION]\n\n" , name); +printf ("Creates n files in the current directory names 0,1,...\n\n" ); +printf (" -n n the number of files to create (default: 2048)\n" ); +printf (" -c set uid and groupid of file i to i:i\n" ); +printf (" -x set xattr security.x of file i to i\n" ); +printf (" -h this message\n" ); +} + +int main (int argc,char ** argv) +{ +int i; +int option; +int nfiles =2048 ; +int set_owner =0 ; +int set_xattr =0 ; + +while ((option =getopt (argc, argv,"n:cxh" )) !=-1 ) { +switch (option) { +case 'n' : +if (tst_parse_int (optarg, &nfiles,0 ,INT_MAX )) { +printf ("Value for -n is invalid\n" ); +print_usage (argv[0 ]); +return EXIT_FAILURE ; + } +break ; +case 'c' : + set_owner =1 ; +break ; +case 'x' : + set_xattr =1 ; +break ; +case 'h' : +print_usage (argv[0 ]); +return EXIT_SUCCESS ; +default : +print_usage (argv[0 ]); +return EXIT_FAILURE ; + } + } + +for (i =0 ; i < nfiles; ++i) + { +int fd; +char name[20 ]; +sprintf (name,"%d" , i); + fd =SAFE_OPEN (name,O_CREAT |O_EXCL ,0666 ); +if (set_owner) +SAFE_FCHOWN (fd, i, i); +
testcases/kernel/fs/squashfs/squashfs-createfiles.c line 83
Quoted 10 lines
testcases/kernel/fs/squashfs/squashfs-createfiles.c new file +10
-0+/* This must be either security, user or trusted namespace. +* Nothing else can be stores in squashfs. +* Since the files are most likely created on a tmpfs, +* user is also not possible, because it is not allowed on tmpfs. */ +if (set_xattr) +SAFE_FSETXATTR (fd,"security.x" , &i,sizeof (i),XATTR_CREATE ); +close (fd); + } + +return 0 ;
The whitespaces are mostly wrong in this part, looks like tabs and spaces mixed together. Have you tried to run the patch trough the kernel checkpatch.pl script?
Quoted 62 lines
testcases/kernel/fs/squashfs/squashfs-createfiles.c new file +1
-0+}testcases/kernel/fs/squashfs/squashfs_regression.sh new file +55
-0@@ -0,0 +1,65 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (c) 2021 Joerg Vehlow <[email protected]> +# +# This is a regression test for squashfs. +# See test comment for details. + +TST_TESTFUNC=test +TST_CLEANUP=cleanup +TST_NEEDS_CMDS=mksquashfs +TST_NEEDS_ROOT=1 +TST_NEEDS_TMPDIR=1 + +. tst_test.sh + +cleanup() +{ + umount mnt >/dev/null 2>&1 +} + + +# For inodes: 1023 (+1) entries +# For ids: 2048 +# Fox xattr: 512 + +test1() +{ + # Kernel commits + # - f37aa4c7366e23f91b81d00bafd6a7ab54e4a381 + # - eabac19e40c095543def79cb6ffeb3a8588aaff4 + # - 506220d2ba21791314af569211ffd8870b8208fa + # added some sanity checks, that verified the size of + # inode lookup, id (uid/gid) and xattr blocks in the squashfs, + # but roke mounting filesystems with completely filled blocks. + # A block has a max size of 8192. + # An inode lookup entry has an uncompressed size of 8 bytes, + # an id block 4 bytes and an xattr block 16 bytes. + # + # To fill up at least one block for each of the three tables, + # 2048 files with unique uid/gid and xattr are created. + # + # The bugs are fixed in kernel commits + # - c1b2028315c6b15e8d6725e0d5884b15887d3daa + # - 8b44ca2b634527151af07447a8090a5f3a043321 + + tst_res TINFO "Test squashfs sanity check regressions" + + mkdir data + cd data + ROD squashfs-createfiles -cxn 2048 + cd .. + + # Create squashfs without any comporession. + # This allows reasoning about block sizes + mksquashfs data image.raw -noI -noD -noX -noF >/dev/null 2>&1
testcases/kernel/fs/squashfs/squashfs_regression.sh line 65
Quoted 10 lines
testcases/kernel/fs/squashfs/squashfs_regression.sh new file +10
-0+ squashfs-info image.raw + + mkdir mnt + EXPECT_PASS_BRK mount -o loop image.raw mnt + umount mnt + + tst_res TPASS "Test passed" +} + +tst_run
Given how simple is this part it may be easier to code the whole test in C instead.
Signature · 2 lines
Cyril Hrubis [email protected]