Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1p17Es-00029L-K3 for mharc-grub-devel@gnu.org; Fri, 02 Dec 2022 09:42:06 -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 1p17Eo-00028x-0Z for grub-devel@gnu.org; Fri, 02 Dec 2022 09:42:02 -0500 Received: from mail-pf1-x432.google.com ([2607:f8b0:4864:20::432]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1p17El-0007oz-0V for grub-devel@gnu.org; Fri, 02 Dec 2022 09:42:01 -0500 Received: by mail-pf1-x432.google.com with SMTP id k79so5075684pfd.7 for ; Fri, 02 Dec 2022 06:41:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axtens.net; s=google; h=content-transfer-encoding:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:from:to:cc:subject:date:message-id :reply-to; bh=z3gC9hxBmRNgR19kra2X1PTC1TJ/Lw2xICbIb/4DCyw=; b=HUMLG7RVfk5S87UA78dR33lC2VWyiIRlQx3eG0CV5ToLXfGv4ATzYLwG9VhaUl1Aj4 ECNMDTyiSb14JsL3G3MvhzohuSUQ/sSw1bIMDHeIGpJymyeBMdTby0VoqQYvLN0ZKxsQ IBaxzVyRzHLyn9+O6YzNRt0TX5CdrRDcluUWI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=z3gC9hxBmRNgR19kra2X1PTC1TJ/Lw2xICbIb/4DCyw=; b=N1K/EmQx+0u3SHnSIM9mROkctnerUdA5bK0Zh/0kIjOQ2R56jJ/QnfVsIxf5XqgSm0 4BjWJQOFxWb2Uv/X2e06Fo50fjjLP8rym4xDUrTwTSZiNjywbyJacpDg7lAOMw6D5yoD BLSaCEwtoV9geSzp58RZe+CvsCoPxbVj0YCXNLMUVwqqZnmd0TCqTcMWKxVfBSpiQ79v 96xvjJgxtuQWosc4o9/DzVk/oWH5ctzLrvR0eV4zbQ2HwiuXF4DTwDviVIs5Rjy7g1UU CTpPc3AtqOyfNS07zshwBbo8TA0ZG/osaGgR3/TRzf9U9hsyOQzbQYn9/Tk3BrdOgND4 Dz+A== X-Gm-Message-State: ANoB5pnME1bkd31qB2yxwGSOLk5Yg7XAFY1Zam0NO0XR7T2eWPxF/F5r 7SbN/F/Ii2idemNs3JjWAnOcTg== X-Google-Smtp-Source: AA0mqf5q8D0mlGyC+Pq8QN3WHyuV6YgJrV8PGtQ6ZN33rzfztN7hyBlE+5lit+nZB9+2nrbCTCFw9A== X-Received: by 2002:a05:6a00:f8a:b0:56c:2576:9d2a with SMTP id ct10-20020a056a000f8a00b0056c25769d2amr54068404pfb.60.1669992115427; Fri, 02 Dec 2022 06:41:55 -0800 (PST) Received: from localhost ([2001:4479:e300:5b00:eefa:1a0:c656:6a80]) by smtp.gmail.com with ESMTPSA id z9-20020a1709027e8900b00186b8752a78sm5663879pla.80.2022.12.02.06.41.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Dec 2022 06:41:54 -0800 (PST) From: Daniel Axtens To: Steve McIntyre , grub-devel@gnu.org Cc: 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] In-Reply-To: <20221115183132.GJ3245702@tack.einval.com> References: <20221115183132.GJ3245702@tack.einval.com> Date: Sat, 03 Dec 2022 01:41:51 +1100 Message-ID: <87wn79eukw.fsf@dja-thinkpad.axtens.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Received-SPF: pass client-ip=2607:f8b0:4864:20::432; envelope-from=dja@axtens.net; helo=mail-pf1-x432.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_NONE=-0.0001, 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: Fri, 02 Dec 2022 14:42:03 -0000 Steve McIntyre writes: > Hi all! > > =D0=BF=D1=80=D0=BE=D0=B3=D1=80=D0=B0=D0=BC=D0=BC=D0=B8=D1=81=D1=82 =D0=BD= =D0=B5=D0=BA=D1=82=D0=BE (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 en= d 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.] 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 =3D NAT_JOURNAL_ENTRIES entries _inclusive_, because the loop below uses i < n, not i <=3D n. D'oh. 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 *da= ta, grub_uint32_t nid, grub_uint16_t n =3D grub_le_to_cpu16 (data->nat_j.n_nats); grub_uint16_t i; =20 - if (n >=3D 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; } =20 +#ifdef GRUB_UTIL +#include +#endif + static grub_err_t get_blkaddr_from_nat_journal (struct grub_f2fs_data *data, grub_uint32_t n= id, grub_uint32_t *blkaddr) @@ -650,6 +654,10 @@ get_blkaddr_from_nat_journal (struct grub_f2fs_data *d= ata, grub_uint32_t nid, grub_uint16_t n =3D grub_le_to_cpu16 (data->nat_j.n_nats); grub_uint16_t i; =20 +#ifdef GRUB_UTIL + fprintf(stderr, "%s: n =3D %hu\n", __func__, n); +#endif + if (n > NAT_JOURNAL_ENTRIES) return grub_error (GRUB_ERR_BAD_FS, "invalid number of nat journal entries"); Amusingly the debug code shows that the grub-fs-tester tests always have n =3D 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. Kind regards, Daniel > > ----- Forwarded message from =D0=BF=D1=80=D0=BE=D0=B3=D1=80=D0=B0=D0=BC= =D0=BC=D0=B8=D1=81=D1=82 =D0=BD=D0=B5=D0=BA=D1=82=D0=BE ----- > > From: =D0=BF=D1=80=D0=BE=D0=B3=D1=80=D0=B0=D0=BC=D0=BC=D0=B8=D1=81=D1=82 = =D0=BD=D0=B5=D0=BA=D1=82=D0=BE > To: submit@bugs.debian.org > Date: Sat, 15 Oct 2022 23:54:36 +0300 > Subject: Bug#1021846: grub-install is broken since 2.06-3: error: unknown= filesystem > Message-Id: <3168731665867229@wf4nrjvtssjecb53.iva.yp-c.yandex.net> > > Package: grub-pc > Version: 2.06-3~deb11u1 > Severity: critical > > Hello. Since version 2.06-3, grub-install is broken: it fails with "error= : unknown filesystem". > I test command /usr/sbin/grub-install -v /dev/sda > in some versions. Results in mail attachments. > Versions older than 2.06-3 works without error (2.06-2 and lower). > Tested versions: 2.04-20, 2.06-1, 2.06-2, 2.06-3~deb10u1, 2.06-3~deb11u1,= 2.06-4. > > Disk partitions: > > # fdisk --list-details > Disk /dev/sda: 29,82 GiB, 32017047552 bytes, 62533296 sectors > Disk model: TS32GSSD370S > Units: sectors of 1 * 512 =3D 512 bytes > Sector size (logical/physical): 512 bytes / 512 bytes > I/O size (minimum/optimal): 512 bytes / 512 bytes > Disklabel type: dos > Disk identifier: 0xc7177f7e > > Device Boot Start End Sectors Id Type Start-C/H/S End-C/H/S Attrs > /dev/sda1 2048 22763519 22761472 83 Linux 4/4/1 1023/254/2 > /dev/sda2 * 25866240 62531583 36665344 7 HPFS/ 1023/254/2 1023/254/2 80 > > $ disktype /dev/sda1 > --- /dev/sda1 > Block device, size 10.85 GiB (11653873664 bytes) > F2FS file system (version 1.14) > > $ disktype /dev/sda2 > --- /dev/sda2 > Block device, size 17.48 GiB (18772656128 bytes) > NTFS file system > Volume size 17.48 GiB (18772652032 bytes, 36665336 sectors) > > > > > > > > > ----- End forwarded message ----- > --=20 > Steve McIntyre, Cambridge, UK. steve@einva= l.com > Mature Sporty Personal > More Innovation More Adult > A Man in Dandism > Powered Midship Specialty > > > _______________________________________________ > Grub-devel mailing list > Grub-devel@gnu.org > https://lists.gnu.org/mailman/listinfo/grub-devel