Skip to contentSkip to conversation

Handle invalid os_type in e2p.

PATCH Superseded Adam Buchbinder 3 participants 12 messages Jul 18, 2017 – Jul 22, 2017

lore
Share & tools
lore
#0 lore raw

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.

#1 lore raw

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
new file mode 100644
index 00000000..b00318c4
@@ -0,0 +1 @@
+Filesystem OS type:       (unknown os)
tests/d_bad_ostype/image.gz new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..06805e1093c1ce9d2dc172aa89fb57eaedfa5505
GIT binary patch
tests/d_bad_ostype/name new file +1 -0
new file mode 100644
index 00000000..3da887a8
@@ -0,0 +1 @@
+handle bad (negative) os_type
tests/d_bad_ostype/script new file +19 -0
new file mode 100644
index 00000000..94f356a6
@@ -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
#2 lore raw

Re: [PATCH 1/2] tests: dumpe2fs against an image with bad os_type.

Quoted 6 lines · Adam Buchbinder

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.

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

---

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
new file mode 100644
index 00000000..b00318c4
@@ -0,0 +1 @@
+Filesystem OS type:       (unknown os)
tests/d_bad_ostype/image.gz new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..06805e1093c1ce9d2dc172aa89fb57eaedfa5505
GIT binary patch
tests/d_bad_ostype/name new file +1 -0
new file mode 100644
index 00000000..3da887a8
@@ -0,0 +1 @@
+handle bad (negative) os_type
tests/d_bad_ostype/script new file +19 -1
new file mode 100644
index 00000000..94f356a6
@@ -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

#3 lore raw

PATCH 2/2 e2p: Fix segfault in e2p_os2string.

In reply to Adam Buchbinder

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
index 7f088446..c5fd8ab3 100644
@@ -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
Reviewed-by on v1 2/2
#4 lore raw

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.

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
index 7f088446..c5fd8ab3 100644

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

#5 lore raw

v2 cover Handle invalid os_type in e2p.

In reply to Adam Buchbinder

Hi! 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.

#6 lore raw

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
index 7f088446..c5fd8ab3 100644
@@ -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
Reviewed-by on v2 1/2
#7 lore raw

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.

Quoted 18 lines

---
lib/e2p/ostype.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
lib/e2p/ostype.c +1 -2
index 7f088446..c5fd8ab3 100644
@@ -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

#9 lore raw

PATCH v2 2/2 tests: dumpe2fs against an image with bad os_type.

In reply to Adam Buchbinder

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/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
new file mode 100644
index 00000000..b00318c4
@@ -0,0 +1 @@
+Filesystem OS type:       (unknown os)
tests/d_bad_ostype/name new file +1 -0
new file mode 100644
index 00000000..3da887a8
@@ -0,0 +1 @@
+handle bad (negative) os_type
tests/d_bad_ostype/script new file +21 -0
new file mode 100644
index 00000000..992a3030
@@ -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
Reviewed-by on v2 2/2
#10 lore raw

Re: [PATCH v2 2/2] tests: dumpe2fs against an image with bad os_type.

Quoted 8 lines · Adam Buchbinder

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.

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/script

tests/d_bad_ostype/expect new file +1 -0
new file mode 100644
index 00000000..b00318c4
@@ -0,0 +1 @@
+Filesystem OS type:       (unknown os)
tests/d_bad_ostype/name new file +1 -0
new file mode 100644
index 00000000..3da887a8
@@ -0,0 +1 @@
+handle bad (negative) os_type
tests/d_bad_ostype/script new file +21 -1
new file mode 100644
index 00000000..992a3030
@@ -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

#11 lore raw

Re: [PATCH v2 2/2] tests: dumpe2fs against an image with bad os_type.

In reply to Adam Buchbinder
Quoted 7 lines · Adam Buchbinder

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.

Thanks, applied.

- Ted