Re: fsck segfaults on rpi3 running 13-stable (and on 14-CURRENT analyzing the same file system that resulted from the 13-STABLE crash)
- Reply: bob prohaska : "Re: fsck segfaults on rpi3 running 13-stable (and on 14-CURRENT analyzing the same file system that resulted from the 13-STABLE crash)"
- In reply to: bob prohaska : "Re: fsck segfaults on rpi3 running 13-stable (and on 14-CURRENT analyzing the same file system that resulted from the 13-STABLE crash)"
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 14 Feb 2023 18:38:27 UTC
bob prohaska wrote this message on Tue, Feb 14, 2023 at 08:14 -0800: > > On Feb 13, 2023, at 15:25, John-Mark Gurney <jmg@funkthat.com> wrote: > > > [huge snip] > > > > Ok, decided to run AFL on fsck, and this one was the first crash it > > > discovered. The problem is that ctime can return NULL, and the return > > > value isn't checked, because it then immediately does &p[4] which > > > results is printf and friends being passed 0x4. > > > > > > Simple test program that demonstrates this problem: > > > #include <time.h> > > > #include <stdio.h> > > > > > > int > > > main() > > > { > > > const char *p; > > > time_t t; > > > > > > t = -5098919203113507862; > > > > > > p = ctime(&t); > > > > > > printf("MTIME=%12.12s %4.4s ", &p[4], &p[20]); > > > > > > return 0; > > > } > > > > > > I'm not sure what the correct fix is for when times are wildly out of > > > valid range. > > > > > Is this a demonstration that the fsck segfault can be reproduced > independtly of my particular corrupt filesystem? AFL is new to me. Yes, it is. It turns out that the FS to produce this failure is a LOT smaller than I expected when compresed, I have included it later in the email. The constant above was taken directly from the failing FS. AFL is a very useful tool, and found this crash and apparently 50+ other crashes in only 5-10 minutes of running... I'll be investigating a few of the other crashes as well, as fsck does ocassionally deal w/ untrusted fs's. Also, afl was a LOT easier to run than I expected (I had run it before, just not insturmented a FreeBSD program before), installed afl++-llvm from ports, went into the fsck_ffs dir, and ran: CC=/usr/local/afl++-llvm/bin/afl-cc CXX=/usr/local/afl++-llvm/bin/afl-c++ make I then created a simple starting file system: mkdir testcase_dir; cd testcase_dir touch -s 1m test.ufs; mdconfig -f test.ufs; newfs /dev/md0; mdconfig -d -u 0 cd .. And then ran it against that test case: mkdir findings_dir /usr/local/afl++-llvm/bin/afl-fuzz -i testcase_dir/ -o findings_dir/ /usr/obj/usr/src/arm64.aarch64/sbin/fsck_ffs/fsck_ffs -y @@ To get back the FS, pipe in the base64 blob below through: openssl enc -d -base64 | xz -d > somefile And then run fsck_ffs on it. /Td6WFoAAATm1rRGAgAhARYAAAB0L+Wj5A/9BKddAABv/f//o7f/Rz5IFXI5YVG4 kijmo4YH+e7kHoLTL8U6PAFLsX7JiopNL6MN2X+m44wjEVPgWRjFdYrid/i2lH8M asDdr70i7w1p4SshtpY7LOoHpyp/p6OA/Nr4LJfZY/Svg3PS8bkcs82fLVdnpkfj tUW1Xpr6aNEd/6QbigL574jJbAi7hGfKb+aPYEZG51EtkwtmWbD+1giJdwmV7G7L P60SrLFhLMkWYShiaZGwmHTmITH6V9auY9KAbvDFpTq7fB17vIarx47LLJU2Bq8x o79kER0IFPTVa8m+D8xxIzruoGIWSBjeR1mBJWloKHU/2hBBT2PyeiQJ1I8MWowC 1T4KtnO6LMJhB7du7B2Z1hEwvTd+kzqpEFZgUSh8DiepZqT+6udLxvvtOYX1mH/4 ICQiRFVdjat7bKSNnTiDJHm3qZY0LdpDEhhTCJBSW1qzBgnUjz9jyXe78HKNtZBY HLHfCf/FoMC/CCVZwQnBJpKKBqbgXDexv3Gr9ePWQw6U7y6eBT1f/eQTTevL/jI5 TOhjcquYE+N9Jw5xL+4dpMEoukZ8kJ+WQRZIbrSM6L6w+E46sXqRXybaYSpwDhZV +8z1drD1RDY+vN7T1/psQNLjZw/IdDjlwMoOl+3c6N/n2i/+O+4dfJ/eMPXv3B+f Aa5kf3xx2qhF3czcD9iXHzN0kZpq/hLlZCSZJkkLsPcdh1yNinQ11m/x6kENoSBg bW/tjCEH52ULIixG7G58hDEZulYjmPpHYFum0eK+LMKMYdR/cRCr2euttKV9kA5i oVsoH9YT+YKc6xsFSL17308iGLSRXq8RGqCrtJ1Xjx2RMep8E9ayDyKPRnCbhHnl +/0kLjYBWwd4bB8y4o1fb/4yCSHvU94Uw/CPYryh0q6Xnio62UwXZmFfI7fI/4W3 29olwCloEgW2HFkAYtIKkbMJWvSR2+jNCkO/HxeSwghxlXnwveagDzbITvLapf3C LAJZxE9A1UFzDct8OmgaHRrqDcYxH/tdDsHO7hd9BbDL9ESXHFJfRzWvOVtZFDjj E/GPukGiMCLQAysgeiOpDH0I8CQjuJQZNyOF1qTC3XOg0z7azMBMYaVR7FlQkOQA DsklKx4GMe957nMiXb65GcysKBTykwcwXd3rY/vG1wWm7Umrk7/fOcAuvKr3rXrw vUSHNVznSejKf4nytxSbfIOTj8iFSAN/u0T1XnmWgW6aEmzMWx963S2g/NA52/rW Th7Tcpw127SOWOZAPApe7LNe1Gjq+vXKw2plLWG3rLyOzcgBgenjlRAMVB+nyQqF w2Lxzs9MsIYIlh23lJCRRH/qOaaKMmXFWx1Od2NPXq2DPWCW/gzinQ0tElWcP54s ZyoYcU+a3jCZmLGLY2B1pZkJGllWNCUMBNMjlpKGoBY5G3kIfMbXeJu6aE9orbXI 9eVI88jLM+WoSCRZog8bD9oE94uTFbxBw0ka703C/dJsFCDFGdN7FzmsGv0zvDyA cLHzCVwEg5KfaAjqA1T2/WSB947h+3YPImuV8JQxNPjT15yskd26f+V4f2s5D2/6 ugXWgY4fRzN9xfL8TjMD7SY3wByyIAAAuBN40havWu4AAcMJ/p8QAL5WDYOxxGf7 AgAAAAAEWVo= -- John-Mark Gurney Voice: +1 415 225 5579 "All that I will do, has been done, All that I have, has not."