From a8a1ee12550f4ecd0bb7e75a60e25a57bcc5a0e9 Mon Sep 17 00:00:00 2001 From: "Darrick J. Wong" Date: Sat, 2 Aug 2014 23:49:41 -0400 Subject: [PATCH] tests: add regression tests for MMP blocks with bad checksums Add regression tests to examine how e2fsck deals with MMP blocks with (a) a bad magic number; and (b) an incorrect checksum. Signed-off-by: Darrick J. Wong Signed-off-by: Theodore Ts'o --- e2fsck/unix.c | 4 +++- tests/m_mmp_bad_csum/expect | 9 +++++++++ tests/m_mmp_bad_csum/image.gz | Bin 0 -> 2594 bytes tests/m_mmp_bad_csum/name | 1 + tests/m_mmp_bad_csum/script | 30 ++++++++++++++++++++++++++++++ tests/m_mmp_bad_magic/.log | 9 +++++++++ tests/m_mmp_bad_magic/expect | 9 +++++++++ tests/m_mmp_bad_magic/image.gz | Bin 0 -> 2597 bytes tests/m_mmp_bad_magic/name | 1 + tests/m_mmp_bad_magic/script | 30 ++++++++++++++++++++++++++++++ 10 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 tests/m_mmp_bad_csum/expect create mode 100644 tests/m_mmp_bad_csum/image.gz create mode 100644 tests/m_mmp_bad_csum/name create mode 100644 tests/m_mmp_bad_csum/script create mode 100644 tests/m_mmp_bad_magic/.log create mode 100644 tests/m_mmp_bad_magic/expect create mode 100644 tests/m_mmp_bad_magic/image.gz create mode 100644 tests/m_mmp_bad_magic/name create mode 100644 tests/m_mmp_bad_magic/script diff --git a/e2fsck/unix.c b/e2fsck/unix.c index d883c9e1a..f71afbc97 100644 --- a/e2fsck/unix.c +++ b/e2fsck/unix.c @@ -1166,7 +1166,9 @@ check_error: ext2fs_mmp_clear(fs); retval = 0; } - } + } else + com_err(ctx->program_name, retval, "%s", + _("while reading MMP block")); return retval; } diff --git a/tests/m_mmp_bad_csum/expect b/tests/m_mmp_bad_csum/expect new file mode 100644 index 000000000..e15e7b440 --- /dev/null +++ b/tests/m_mmp_bad_csum/expect @@ -0,0 +1,9 @@ +Superblock MMP block checksum does not match MMP block. Fix? yes + +Pass 1: Checking inodes, blocks, and sizes +Pass 2: Checking directory structure +Pass 3: Checking directory connectivity +Pass 4: Checking reference counts +Pass 5: Checking group summary information +test_filesys: 11/128 files (0.0% non-contiguous), 19/512 blocks +Exit status is 0 diff --git a/tests/m_mmp_bad_csum/image.gz b/tests/m_mmp_bad_csum/image.gz new file mode 100644 index 0000000000000000000000000000000000000000..c896ff60dbbdf68a566007262c54a99b0b912fde GIT binary patch literal 2594 zc-oWi=3qEtbUm1f`R!fX4BJGQP}+o9CR^Xh@pHia(x6(L^Y2jyR^P-qG} z5_V9{qj05&pdgo(hLr|~)((rV2LY_%?Bb#>EaHJ(&UclLo$e2E(#}}Ab?1BT_j~tD z-~Hs??%l_$rz>+ZdaRyUB+@>?cT%TDi_==0b*-nEl(#+=S}Yy^wKYKNYi*~~7wve_ ztCy}trDadD$>w^PqSkWq{89d$%lD?|&A+?z_0y{dXa7ug{(1PXI$IwvFaO!l*zJ4j zw#&xcm+a-ZK6?pfuo&EW8B zO8frPlQ(QL`lqk*(`RYT=a27`TLWrrFISZp>&s=>GB7YiNO*Z0J&eArbB!Iy`&a$+ z{r}reBIRwb_A=xu_E}r6{{CU#+l)?jKmMoJzt7j3WA!SE6R1$fBv)~db=I$SPAn(k7Mxaou{eSxn<@p{? zFQ5O9=YMuS=f<{|@9%HV{t&Y7^@%g<^)G$-5U=t7-|{d9qQHWQQ^c-61sUA-n2Upf zd{CcM@_6;W`HAc7jH}cCy|&$G-8s!S{Qt5GF`lanPp60&1z+pd@;-BJdAs71Lm!s@ z`a5A-^1FwpOXe5vZ7sRJzqEeW>;G!A{^v?q&Ubly_wtwez_rh3AN{xX^!4!X4^npi zuP(A*`}h8(+Lw0!sz1G4_kZf!&--~FKmF+cz2xzHi#7kw{!kC*-dy-D;OC$G|1++A gmS-3RqhJ(_f>AIEMgeU=L;ZX9A63hh85k5806Bs;_y7O^ literal 0 Hc-jL100001 diff --git a/tests/m_mmp_bad_csum/name b/tests/m_mmp_bad_csum/name new file mode 100644 index 000000000..61c31d4a3 --- /dev/null +++ b/tests/m_mmp_bad_csum/name @@ -0,0 +1 @@ +mmp with bad csum (metadata_csum) diff --git a/tests/m_mmp_bad_csum/script b/tests/m_mmp_bad_csum/script new file mode 100644 index 000000000..d10129402 --- /dev/null +++ b/tests/m_mmp_bad_csum/script @@ -0,0 +1,30 @@ +# use current directory instead of /tmp becase tmpfs doesn't support DIO +rm -f $TMPFILE +TMPFILE=$(mktemp ./tmp-$test_name.XXXXXX) + +stat -f $TMPFILE | grep -q "Type: tmpfs" +if [ $? = 0 ]; then + rm -f $TMPFILE + echo "$test_name: $test_description: skipped for tmpfs (no O_DIRECT)" + return 0 +fi +gzip -dc < $test_dir/image.gz > $TMPFILE + +OUT=$test_dir.log +EXP=$test_dir/expect +$FSCK -fy $TMPFILE 2>&1 | sed -f $cmd_dir/filter.sed > $OUT +echo Exit status is $? >> $OUT + +rm -f $TMPFILE +cmp -s $OUT $EXP +status=$? + +if [ "$status" = 0 ] ; then + echo "$test_name: $test_description: ok" + touch $test_name.ok +else + echo "$test_name: $test_description: failed" + diff $DIFF_OPTS $EXP $OUT > $test_name.failed + rm -f $test_name.tmp +fi +unset OUT EXP diff --git a/tests/m_mmp_bad_magic/.log b/tests/m_mmp_bad_magic/.log new file mode 100644 index 000000000..b5dfb8970 --- /dev/null +++ b/tests/m_mmp_bad_magic/.log @@ -0,0 +1,9 @@ +Superblock has invalid MMP magic. Fix? yes + +Pass 1: Checking inodes, blocks, and sizes +Pass 2: Checking directory structure +Pass 3: Checking directory connectivity +Pass 4: Checking reference counts +Pass 5: Checking group summary information +test_filesys: 11/128 files (0.0% non-contiguous), 19/512 blocks +Exit status is 0 diff --git a/tests/m_mmp_bad_magic/expect b/tests/m_mmp_bad_magic/expect new file mode 100644 index 000000000..b5dfb8970 --- /dev/null +++ b/tests/m_mmp_bad_magic/expect @@ -0,0 +1,9 @@ +Superblock has invalid MMP magic. Fix? yes + +Pass 1: Checking inodes, blocks, and sizes +Pass 2: Checking directory structure +Pass 3: Checking directory connectivity +Pass 4: Checking reference counts +Pass 5: Checking group summary information +test_filesys: 11/128 files (0.0% non-contiguous), 19/512 blocks +Exit status is 0 diff --git a/tests/m_mmp_bad_magic/image.gz b/tests/m_mmp_bad_magic/image.gz new file mode 100644 index 0000000000000000000000000000000000000000..2d57fbf5fa2ee4939a41f00ea1d3d0b096346d3e GIT binary patch literal 2597 zc-oWi=3rQDbUm1f`R!d_50O9yh6m=4+m6P|YjbfCxVmtKvtxjxtd-k^g-z>Z_k;)tmP~ZAx{+`mVW;2 ze){&gcX_*amOpuXboK4?t_!tIj$eLly8YH<_np3Ct!)c=Y%_8pRT2Tgt z+OEU*Q#~VsrT#ykRI@B(-^&-turp>wWfed*>1c_8n{ zd(r*>^Z5er2%h@RWYTW&?uEwv!@sv}HMBD{nG;){qG4WfVyh5PVMN9(=Zfp~ds9n; zul}iDwAJQ6J5V$$`QQBgv+DzE{w)oy2J#)&p8Fr(6SpJnA3u=y>_3n=aA^L2@p|Th z`275b$N$Ikr}(eCzw6`s`{joZB$ORK7{7m?$K}KIi9eVAVvk~EAO6N?J2`9W9`6kfJmC|qucd2fEid18 zLC)=5`1|%PGR6GIFV~*?`s7mV|7Ck$uKPbbqePU*}tX=)PUM zelPF(dw+6u=G*_%-gtihcz>>M`Ct9~+5dAZqGbM;oHhB^d3e?Ro_eFH2GYy $TMPFILE + +OUT=$test_dir.log +EXP=$test_dir/expect +$FSCK -fy $TMPFILE 2>&1 | sed -f $cmd_dir/filter.sed > $OUT +echo Exit status is $? >> $OUT + +rm -f $TMPFILE +cmp -s $OUT $EXP +status=$? + +if [ "$status" = 0 ] ; then + echo "$test_name: $test_description: ok" + touch $test_name.ok +else + echo "$test_name: $test_description: failed" + diff $DIFF_OPTS $EXP $OUT > $test_name.failed + rm -f $test_name.tmp +fi +unset OUT EXP -- 2.47.2