Handle invalid os_type in e2p.
cover Handle invalid os_type in e2p.
Hi! While fuzzing with american fuzzy lop, I discovered an issue in the e2p library. The fix there seemed straightforward, but I'm not sure I understand the testing infrastructure; running dumpe2fs looks like the easiest way to trigger the problem. Any feedback here would be welcome. Thanks!
Adam Buchbinder
Google, Inc.
PATCH 1/2 tests: dumpe2fs against an image with bad os_type.
The os_type here is large enough to be negative when interpreted as a signed integer.
This test case was generated by american fuzzy lop, starting from a base filesystem image from files.fuzzing-project.org.
--- tests/d_bad_ostype/expect | 1 + tests/d_bad_ostype/image.gz | Bin 0 -> 272 bytes tests/d_bad_ostype/name | 1 + tests/d_bad_ostype/script | 19 +++++++++++++++++++ 4 files changed, 21 insertions(+) create mode 100644 tests/d_bad_ostype/expect create mode 100644 tests/d_bad_ostype/image.gz create mode 100644 tests/d_bad_ostype/name create mode 100644 tests/d_bad_ostype/script
tests/d_bad_ostype/expect new file +1 -0
@@ -0,0 +1 @@ +Filesystem OS type: (unknown os)
tests/d_bad_ostype/image.gz new file binary +0 -0
tests/d_bad_ostype/name new file +1 -0
@@ -0,0 +1 @@ +handle bad (negative) os_type
tests/d_bad_ostype/script new file +19 -0
@@ -0,0 +1,19 @@ +gzip -dc < $test_dir/image.gz > $TMPFILE + +OUT=$test_name.log +EXP=$test_dir/expect +$DUMPE2FS $TMPFILE 2>&1 | sed -f $cmd_dir/filter.sed | grep 'Filesystem OS type:' > $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
Signature · 1 line
2.14.0.rc0.284.gd933b75aa4-goog
Re: [PATCH 1/2] tests: dumpe2fs against an image with bad os_type.
Quoted 6 lines · Adam Buchbinder
The
os_typehere is large enough to be negative when interpreted as a signed integer.This test case was generated by american fuzzy lop, starting from a base filesystem image from files.fuzzing-project.org.
It is preferable to create the image filesystem via script as part of the test (e.g. using "debugfs -w ssv ostype 0xf00000000" or similar), rather than using a binary image. That allows us to see what is being changed, rather than getting a binary blob.
Cheers, Andreas
Quoted 67 lines
Signed-off-by Adam Buchbinder <[email protected]>---
tests/d_bad_ostype/expect | 1 + tests/d_bad_ostype/image.gz | Bin 0 -> 272 bytes tests/d_bad_ostype/name | 1 + tests/d_bad_ostype/script | 19 +++++++++++++++++++ 4 files changed, 21 insertions(+)create mode 100644 tests/d_bad_ostype/expect
create mode 100644 tests/d_bad_ostype/image.gz
create mode 100644 tests/d_bad_ostype/name
create mode 100644 tests/d_bad_ostype/scripttests/d_bad_ostype/expect new file +1
-0@@ -0,0 +1 @@ +Filesystem OS type: (unknown os)tests/d_bad_ostype/image.gz new file binary +0
-0tests/d_bad_ostype/name new file +1
-0@@ -0,0 +1 @@ +handle bad (negative) os_typetests/d_bad_ostype/script new file +19
-1@@ -0,0 +1,19 @@ +gzip -dc < $test_dir/image.gz > $TMPFILE + +OUT=$test_name.log +EXP=$test_dir/expect +$DUMPE2FS $TMPFILE 2>&1 | sed -f $cmd_dir/filter.sed | grep 'Filesystem OS type:' > $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 --
Quoted 2 lines
2.14.0.rc0.284.gd933b75aa4-goog
Cheers, Andreas
PATCH 2/2 e2p: Fix segfault in e2p_os2string.
In reply to Adam BuchbinderPassing in a negative integer would lead to a segfault, and a crafted filesystem image could trigger that.
--- lib/e2p/ostype.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/e2p/ostype.c +1 -1
@@ -30,7 +30,7 @@ char *e2p_os2string(int os_type)const char *os;char *ret; -if (os_type <=EXT2_OS_LITES ) +if (os_type >=0 && os_type <=EXT2_OS_LITES ) os = os_tab[os_type];else os ="(unknown os)" ;
Signature · 1 line
2.14.0.rc0.284.gd933b75aa4-goog
Re: [PATCH 2/2] e2p: Fix segfault in e2p_os2string.
Quoted 5 lines · Adam Buchbinder
Passing in a negative integer would lead to a segfault, and a crafted filesystem image could trigger that.
Signed-off-by Adam Buchbinder <[email protected]>
Note that it would be better to land this patch as 1/2, and the test which causes the segfault as 2/2, otherwise it could break git bisect.
Cheers, Andreas
Quoted 9 lines
---
lib/e2p/ostype.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)lib/e2p/ostype.c +0
-0
lib/e2p/ostype.c char *e2p_os2string(int os_type) · line 36
Quoted 8 lines
lib/e2p/ostype.c +1
-1@@ -30,7 +30,7 @@ char *e2p_os2string(int os_type)const char *os;char *ret; -if (os_type <=EXT2_OS_LITES ) +if (os_type >=0 && os_type <=EXT2_OS_LITES ) os = os_tab[os_type];else os ="(unknown os)" ;
Cheers, Andreas
v2 cover Handle invalid os_type in e2p.
In reply to Adam BuchbinderHi! Here's a new version with the updates suggested by Andreas Dilger, specifically to switch the order (to not break git bisect) and for the test to avoid including a binary blob.
Adam Buchbinder
Google, Inc.
PATCH v2 1/2 e2p: Fix segfault in e2p_os2string.
Passing in a negative integer would lead to a segfault, and a crafted filesystem image could trigger that.
--- lib/e2p/ostype.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/e2p/ostype.c +1 -1
@@ -30,7 +30,7 @@ char *e2p_os2string(int os_type)const char *os;char *ret; -if (os_type <=EXT2_OS_LITES ) +if (os_type >=0 && os_type <=EXT2_OS_LITES ) os = os_tab[os_type];else os ="(unknown os)" ;
Signature · 1 line
2.14.0.rc0.284.gd933b75aa4-goog
Re: [PATCH v2 1/2] e2p: Fix segfault in e2p_os2string.
Quoted 7 lines · Adam Buchbinder
Passing in a negative integer would lead to a segfault, and a crafted filesystem image could trigger that.
Signed-off-by Adam Buchbinder <[email protected]>
Quoted 18 lines
---
lib/e2p/ostype.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)lib/e2p/ostype.c +1
-2@@ -30,7 +30,7 @@ char *e2p_os2string(int os_type)const char *os;char *ret; -if (os_type <=EXT2_OS_LITES ) +if (os_type >=0 && os_type <=EXT2_OS_LITES ) os = os_tab[os_type];else os ="(unknown os)" ; --
Quoted 2 lines
2.14.0.rc0.284.gd933b75aa4-goog
Cheers, Andreas
Theodore Ts'o
AppliedRe: [PATCH v2 1/2] e2p: Fix segfault in e2p_os2string.
In reply to Adam BuchbinderQuoted 4 lines · Adam Buchbinder
Passing in a negative integer would lead to a segfault, and a crafted filesystem image could trigger that.
Signed-off-by Adam Buchbinder <[email protected]>
Thanks, applied.
- Ted
PATCH v2 2/2 tests: dumpe2fs against an image with bad os_type.
In reply to Adam BuchbinderThe os_type here is large enough to be negative when interpreted as a signed integer.
This test case was generated by american fuzzy lop, starting from a base filesystem image from files.fuzzing-project.org.
--- tests/d_bad_ostype/expect | 1 + tests/d_bad_ostype/name | 1 + tests/d_bad_ostype/script | 21 +++++++++++++++++++++ 3 files changed, 23 insertions(+) create mode 100644 tests/d_bad_ostype/expect create mode 100644 tests/d_bad_ostype/name create mode 100644 tests/d_bad_ostype/script
tests/d_bad_ostype/expect new file +1 -0
@@ -0,0 +1 @@ +Filesystem OS type: (unknown os)
tests/d_bad_ostype/name new file +1 -0
@@ -0,0 +1 @@ +handle bad (negative) os_type
tests/d_bad_ostype/script new file +21 -0
@@ -0,0 +1,21 @@ +dd if=/dev/zero of=$TMPFILE bs=1k count=64 > /dev/null 2>&1 +$MKE2FS -q -b 1024 $TMPFILE +$DEBUGFS -w -R 'set_super_value creator_os 0xf0000000' $TMPFILE + +OUT=$test_name.log +EXP=$test_dir/expect +$DUMPE2FS $TMPFILE 2>&1 | sed -f $cmd_dir/filter.sed | grep 'Filesystem OS type:' > $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
Signature · 1 line
2.14.0.rc0.284.gd933b75aa4-goog
Re: [PATCH v2 2/2] tests: dumpe2fs against an image with bad os_type.
Quoted 8 lines · Adam Buchbinder
The
os_typehere is large enough to be negative when interpreted as a signed integer.This test case was generated by american fuzzy lop, starting from a base filesystem image from files.fuzzing-project.org.
Signed-off-by Adam Buchbinder <[email protected]>
Quoted 51 lines
---
tests/d_bad_ostype/expect | 1 + tests/d_bad_ostype/name | 1 + tests/d_bad_ostype/script | 21 +++++++++++++++++++++ 3 files changed, 23 insertions(+)create mode 100644 tests/d_bad_ostype/expect
create mode 100644 tests/d_bad_ostype/name
create mode 100644 tests/d_bad_ostype/scripttests/d_bad_ostype/expect new file +1
-0@@ -0,0 +1 @@ +Filesystem OS type: (unknown os)tests/d_bad_ostype/name new file +1
-0@@ -0,0 +1 @@ +handle bad (negative) os_typetests/d_bad_ostype/script new file +21
-1@@ -0,0 +1,21 @@ +dd if=/dev/zero of=$TMPFILE bs=1k count=64 > /dev/null 2>&1 +$MKE2FS -q -b 1024 $TMPFILE +$DEBUGFS -w -R 'set_super_value creator_os 0xf0000000' $TMPFILE + +OUT=$test_name.log +EXP=$test_dir/expect +$DUMPE2FS $TMPFILE 2>&1 | sed -f $cmd_dir/filter.sed | grep 'Filesystem OS type:' > $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 --
Quoted 2 lines
2.14.0.rc0.284.gd933b75aa4-goog
Cheers, Andreas
Theodore Ts'o
AppliedRe: [PATCH v2 2/2] tests: dumpe2fs against an image with bad os_type.
In reply to Adam BuchbinderQuoted 7 lines · Adam Buchbinder
The
os_typehere is large enough to be negative when interpreted as a signed integer.This test case was generated by american fuzzy lop, starting from a base filesystem image from files.fuzzing-project.org.
Signed-off-by Adam Buchbinder <[email protected]>
Thanks, applied.
- Ted