Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1p1WYy-00035w-Eq for mharc-grub-devel@gnu.org; Sat, 03 Dec 2022 12:44:33 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p1WYl-00031G-7J for grub-devel@gnu.org; Sat, 03 Dec 2022 12:44:22 -0500 Received: from cheddar.halon.org.uk ([93.93.131.118]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p1WYi-0005gV-B3 for grub-devel@gnu.org; Sat, 03 Dec 2022 12:44:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=einval.com; s=default; h=In-Reply-To:Content-Transfer-Encoding:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:From:Reply-To:Subject: Content-ID:Content-Description:X-Debbugs-Cc; bh=Fo6ewR3IXigY6xpTaghU4QG7Hsov9Gxk2pfZuUYlfgI=; b=An2urYvZNXHRNOfvCWkJSYHkX/ u+7LNCwKc3g0fGOqmTbPJFvuPS0da0JtqNDE12mEC+CUG6OXpmtBGbJqAcxkPjr7M31/hW65MdSMG alKNlkTf3NPLP9439GOArdkSyadKqghZIII4KB9fccxtxpR1oRlg0hAzD3r62JLxyNb6oIgh+cgID C4lZo05eAQHcFKB5xIok/bkn9nvFXGC31hcP9rVpPajMoVhjJOxCdUOsMi1wV3xhXp7mU7tVGuyKx GIBjLtEz8qNnbLGwumjdXD/3I8N7wtjsHBkNdChZ3tGFt6yYB+X0y0eIyqgq0XUZwZMLi6EurJyPT ni16xvqQ==; Received: from bsmtp by cheddar.halon.org.uk with local-bsmtp (Exim 4.92) (envelope-from ) id 1p1WYc-0000Ee-7h; Sat, 03 Dec 2022 17:44:10 +0000 Received: from steve by tack.einval.org with local (Exim 4.94.2) (envelope-from ) id 1p1WXg-000107-2G; Sat, 03 Dec 2022 17:43:12 +0000 Date: Sat, 3 Dec 2022 17:43:12 +0000 From: Steve McIntyre To: Daniel Axtens Cc: grub-devel@gnu.org, 1021846@bugs.debian.org, programmer11180@programist.ru, Sudhakar Kuppusamy Subject: Re: [programmer11180@programist.ru: Bug#1021846: grub-install is broken since 2.06-3: error: unknown filesystem] Message-ID: <20221203174312.GA3245702@tack.einval.com> References: <20221115183132.GJ3245702@tack.einval.com> <87wn79eukw.fsf@dja-thinkpad.axtens.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <87wn79eukw.fsf@dja-thinkpad.axtens.net> X-attached: unknown User-Agent: Mutt/1.10.1 (2018-07-13) Received-SPF: pass client-ip=93.93.131.118; envelope-from=steve@einval.com; helo=cheddar.halon.org.uk X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 03 Dec 2022 17:44:24 -0000 Hi Daniel! On Sat, Dec 03, 2022 at 01:41:51AM +1100, Daniel Axtens wrote: >Steve McIntyre writes: >> >> программист некто (in CC) reported this bug a few weeks back in >> Debian. Since I applied the bundle of filesystem bounds-checking fixes >> a few months back, he can't run grub-install. He's done the work to >> determine that the patch that breaks things for him is >> >> 2d014248d540c7e087934a94b6e7a2aa7fc2c704 fs/f2fs: Do not read past the end of nat journal entries >> >> The full thread of our discussion is at https://bugs.debian.org/1021846 >> >> I don't have any knowledge of f2fs to go any further here. Help please! :-) > >Ergh, apologies for the regression. > >[somewhat off-topic: The fix came from a crash derived from fuzzing. I >am not really knowledgeable about f2fs either - I was just trying to do >my best based on what we could derive from the existing driver. In >general, filesystems are a nightmare for fuzzing fixes because testing >beyond the (quite decent!) tests that the grub test-suite runs is very >challenging. There is usually no-one who is both involved in grub >security and an expert on any given file system either. We do the best >we can. Sadly our regression rate has been climbing, so we may need to >come up with some other way to secure file systems or get access to >sufficient expertise in the future.] ACK. I used to develop amd maintain filesystems as a day job, I understand the issue! Writing good and comprehensive tests is hard, and therefore quite rare! >I had a massive, massive work-in-progress spiel where I looked at this >code and compared the linux code and counted sizes and so on and so >forth. I was getting nowhere. But eventually I realised I had just made >an off-by-one error in the test. You're allowed to have up to n = >NAT_JOURNAL_ENTRIES entries _inclusive_, because the loop below uses i < >n, not i <= n. D'oh. Doh indeed! :-) >Please try the following: > >diff --git a/grub-core/fs/f2fs.c b/grub-core/fs/f2fs.c >index df6beb544cbd..855e24618c2b 100644 >--- a/grub-core/fs/f2fs.c >+++ b/grub-core/fs/f2fs.c >@@ -650,7 +650,7 @@ get_blkaddr_from_nat_journal (struct grub_f2fs_data *data, grub_uint32_t nid, > grub_uint16_t n = grub_le_to_cpu16 (data->nat_j.n_nats); > grub_uint16_t i; > >- if (n >= NAT_JOURNAL_ENTRIES) >+ if (n > NAT_JOURNAL_ENTRIES) > return grub_error (GRUB_ERR_BAD_FS, > "invalid number of nat journal entries"); > > >If for some reason that doesn't work, please add the following debug >code and report the results: > >diff --git a/grub-core/fs/f2fs.c b/grub-core/fs/f2fs.c >index 855e24618c2b..6e49a6d17b7a 100644 >--- a/grub-core/fs/f2fs.c >+++ b/grub-core/fs/f2fs.c >@@ -643,6 +643,10 @@ get_nat_journal (struct grub_f2fs_data *data) > return err; > } > >+#ifdef GRUB_UTIL >+#include >+#endif >+ > static grub_err_t > get_blkaddr_from_nat_journal (struct grub_f2fs_data *data, grub_uint32_t nid, > grub_uint32_t *blkaddr) >@@ -650,6 +654,10 @@ get_blkaddr_from_nat_journal (struct grub_f2fs_data *data, grub_uint32_t nid, > grub_uint16_t n = grub_le_to_cpu16 (data->nat_j.n_nats); > grub_uint16_t i; > >+#ifdef GRUB_UTIL >+ fprintf(stderr, "%s: n = %hu\n", __func__, n); >+#endif >+ > if (n > NAT_JOURNAL_ENTRIES) > return grub_error (GRUB_ERR_BAD_FS, > "invalid number of nat journal entries"); > программист некто: could you please try these changes and report back? >Amusingly the debug code shows that the grub-fs-tester tests always have >n = 0, which makes sense for a test that doesn't really stress the >file-system, and also explains why we didn't catch the bug when it was >introduced. Right. -- Steve McIntyre, Cambridge, UK. steve@einval.com Armed with "Valor": "Centurion" represents quality of Discipline, Honor, Integrity and Loyalty. Now you don't have to be a Caesar to concord the digital world while feeling safe and proud.