[Toybox] [PATCH] blkid: fix buffer overflow

enh enh at google.com
Mon Jul 31 07:15:25 PDT 2023


==851591==ERROR: AddressSanitizer: global-buffer-overflow on address
0x561ef8871680 at pc 0x561ef875c5d7 bp 0x7fff86fe1a30 sp
0x7fff86fe1a28
READ of size 1 at 0x561ef8871680 thread T0
    #0 0x561ef875c5d6 in do_blkid toys/other/blkid.c:136
    #1 0x561ef87347bc in loopfiles_rw lib/lib.c:745
    #2 0x561ef8734817 in loopfiles lib/lib.c:753
    #3 0x561ef875d5f7 in blkid_main toys/other/blkid.c:233
    #4 0x561ef8742277 in toy_exec_which /tmp/toybox/main.c:229
    #5 0x561ef874248a in toybox_main /tmp/toybox/main.c:255
    #6 0x561ef87297b4 in main /tmp/toybox/main.c:302
    #7 0x7f1365c46189 in __libc_start_call_main
../sysdeps/nptl/libc_start_call_main.h:58

0x561ef8871680 is located 32 bytes to the left of global variable
'this' defined in 'main.c:23:20' (0x561ef88716a0) of size 8232
0x561ef8871680 is located 0 bytes to the right of global variable
'toybuf' defined in 'main.c:24:40' (0x561ef8870680) of size 4096
SUMMARY: AddressSanitizer: global-buffer-overflow
toys/other/blkid.c:136 in do_blkid
Shadow bytes around the buggy address:
  0x0ac45f106280: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0ac45f106290: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0ac45f1062a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0ac45f1062b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0ac45f1062c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0ac45f1062d0:[f9]f9 f9 f9 00 00 00 00 00 00 00 00 00 00 00 00
  0x0ac45f1062e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0ac45f1062f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0ac45f106300: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0ac45f106310: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0ac45f106320: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
==851591==ABORTING
---
 toys/other/blkid.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/toys/other/blkid.c b/toys/other/blkid.c
index bed20b2c..951f8487 100644
--- a/toys/other/blkid.c
+++ b/toys/other/blkid.c
@@ -124,7 +124,7 @@ static void do_blkid(int fd, char *name)
       uint64_t test;

       // Skip tests not in this 4k block
-      if (fstypes[i].magic_offset > off+sizeof(toybuf)) {
+      if (fstypes[i].magic_offset + fstypes[i].magic_len >
off+sizeof(toybuf)) {
         pass++;
         continue;
       }
-- 
2.41.0.255.g8b1d071c50-goog


More information about the Toybox mailing list