From nobody Tue Feb 14 18:38:27 2023 X-Original-To: freebsd-arm@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4PGVMp3rmmz3pq3H for ; Tue, 14 Feb 2023 18:38:30 +0000 (UTC) (envelope-from jmg@gold.funkthat.com) Received: from gold.funkthat.com (gold.funkthat.com [IPv6:2001:470:800b::2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "gate2.funkthat.com", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4PGVMp1Tbvz3nVC for ; Tue, 14 Feb 2023 18:38:29 +0000 (UTC) (envelope-from jmg@gold.funkthat.com) Authentication-Results: mx1.freebsd.org; none Received: from gold.funkthat.com (localhost [127.0.0.1]) by gold.funkthat.com (8.15.2/8.15.2) with ESMTPS id 31EIcRMN018722 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Tue, 14 Feb 2023 10:38:28 -0800 (PST) (envelope-from jmg@gold.funkthat.com) Received: (from jmg@localhost) by gold.funkthat.com (8.15.2/8.15.2/Submit) id 31EIcRVi018721; Tue, 14 Feb 2023 10:38:27 -0800 (PST) (envelope-from jmg) Date: Tue, 14 Feb 2023 10:38:27 -0800 From: John-Mark Gurney To: bob prohaska Cc: freebsd-arm@freebsd.org Subject: Re: fsck segfaults on rpi3 running 13-stable (and on 14-CURRENT analyzing the same file system that resulted from the 13-STABLE crash) Message-ID: <20230214183827.GG95670@funkthat.com> Mail-Followup-To: bob prohaska , freebsd-arm@freebsd.org References: <984314A1-FF42-4F92-A212-6BC0D85CB630@yahoo.com> <20230212165333.GB19401@www.zefox.net> <20230212191308.GA21535@www.zefox.net> <20230212195324.GB21535@www.zefox.net> <03840D0B-13D4-4F22-BDAF-2887A4D78BED@yahoo.com> <20230213232519.GD95670@funkthat.com> <20230214161415.GA28276@www.zefox.net> List-Id: Porting FreeBSD to ARM processors List-Archive: https://lists.freebsd.org/archives/freebsd-arm List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-arm@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230214161415.GA28276@www.zefox.net> X-Operating-System: FreeBSD 11.3-STABLE amd64 X-PGP-Fingerprint: D87A 235F FB71 1F3F 55B7 ED9B D5FF 5A51 C0AC 3D65 X-Files: The truth is out there X-URL: https://www.funkthat.com/ X-Resume: https://www.funkthat.com/~jmg/resume.html X-TipJar: bitcoin:13Qmb6AeTgQecazTWph4XasEsP7nGRbAPE X-to-the-FBI-CIA-and-NSA: HI! HOW YA DOIN? can i haz chizburger? User-Agent: Mutt/1.6.1 (2016-04-27) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.4.3 (gold.funkthat.com [127.0.0.1]); Tue, 14 Feb 2023 10:38:28 -0800 (PST) X-Rspamd-Queue-Id: 4PGVMp1Tbvz3nVC X-Spamd-Bar: ---- X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[]; ASN(0.00)[asn:6939, ipnet:2001:470::/32, country:US] X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-ThisMailContainsUnwantedMimeParts: N bob prohaska wrote this message on Tue, Feb 14, 2023 at 08:14 -0800: > > On Feb 13, 2023, at 15:25, John-Mark Gurney 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 > > > #include > > > > > > 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 ICQiRFVdjat7bKSNnTiDJHm3qZ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faAjqA1T2/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."