Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1ol5Ij-0001Fr-PN for mharc-grub-devel@gnu.org; Wed, 19 Oct 2022 05:23:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50990) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ol5Ih-0001Fc-GD for grub-devel@gnu.org; Wed, 19 Oct 2022 05:23:48 -0400 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]:38511) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ol5Ie-0001N5-13 for grub-devel@gnu.org; Wed, 19 Oct 2022 05:23:46 -0400 Received: by mail-pl1-x62b.google.com with SMTP id o21so13965322ple.5 for ; Wed, 19 Oct 2022 02:23:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axtens.net; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=TEcOipPRAu+d2FCQ3z3I6xwFZ8JFkLeqA57JleLrV6I=; b=ER22NNRica1tHRD+9qjQQcZvPusYLheYohET08BmNT/AMsihfgbHfVACy8FDRArekl ZklN22aG1DcxgaYmZwSdSzuGof26SSZ4MBA6fgFmm7w3U+9AahsNmM3T1wgbZtjfKo1e h5msCPySIQng9H3+uixPZQal0Mc5CGbqD/nOw= 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:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=TEcOipPRAu+d2FCQ3z3I6xwFZ8JFkLeqA57JleLrV6I=; b=Wo9d09fg/+AYJDttabPm5WuVxbmBqdQ7M/mbq1QmDEugpzt2osCZyBr2313bFebHwU BNF3cGyG0g5d5uVcSOjmd0Ym6Icgc2CayUkxcvMpheg7EUX/NTmZvgXp981iuyku5qa5 UgfEcf4ourPLKC08hZtR1VDigWhiTSapz9H0kPA5FQKnznrCIQibH7Gp3lkaSj1eNTs8 nhS2DVboqvaafK4wkmjsXHM8qnp1ChK1AMX1LkYu1tg2LhN7KBfOk7oddJVlyZ+yRpSQ 6YZVjACX9XIJ+ErOvlBcq7EVAQXZJcTJGDM/1DjhR3iRe/JHO55iO6DvG5u5JguWjgKg 1p3Q== X-Gm-Message-State: ACrzQf347YAdyDRTioSj47v05cLst+4wtN9Bz8feAfWNpdc9KtrNwN64 PFIsNkM7dJVaxc3pVyqWF3RI1o0HKgmJzA== X-Google-Smtp-Source: AMsMyM7v/ithzsSO+3mrZrf461wSleLGfHX95PHJtJlkugagDDUqckQHwlc0l0Rz/47jwU1ggpMPSQ== X-Received: by 2002:a17:902:b597:b0:182:8547:ae57 with SMTP id a23-20020a170902b59700b001828547ae57mr7551732pls.92.1666171420836; Wed, 19 Oct 2022 02:23:40 -0700 (PDT) Received: from linkitivity.lan ([2001:4479:e300:5b00:adc4:cee7:10f9:2e55]) by smtp.gmail.com with ESMTPSA id jc19-20020a17090325d300b0017ca9f4d22fsm10050401plb.209.2022.10.19.02.23.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Oct 2022 02:23:40 -0700 (PDT) From: Daniel Axtens To: grub-devel@gnu.org Cc: Daniel Axtens Subject: [PATCH] diskfilter: don't make a RAID array with more than 1024 disks Date: Wed, 19 Oct 2022 20:23:22 +1100 Message-Id: <20221019092322.1299368-1-dja@axtens.net> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::62b; envelope-from=dja@axtens.net; helo=mail-pl1-x62b.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: Wed, 19 Oct 2022 09:23:48 -0000 This is 'belt and braces' with commit 12e20a6a695f ("disk/diskfilter: Check calloc() result for NULL"): we end up trying to use too much memory in situations like corrupted Linux software raid setups purporting to use a huge number of disks. Simply refuse to permit such configurations. 1024 is a bit arbitrary, yes, and I feel a bit like I'm tempting fate here, but I think 1024 disks in an array (that grub has to read to boot!) should be enough for anyone. Signed-off-by: Daniel Axtens --- v2: add a minimum of 1 disk as nmemb is a signed integer. Tested with `./grub-fs-tester` using mdraid12_raid1 and mdraid12_raid5. Hopefully that means things work; I don't have software raid set up locally. --- grub-core/disk/diskfilter.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/grub-core/disk/diskfilter.c b/grub-core/disk/diskfilter.c index 4ac50320ef4e..24de8e6c6521 100644 --- a/grub-core/disk/diskfilter.c +++ b/grub-core/disk/diskfilter.c @@ -1046,6 +1046,13 @@ grub_diskfilter_make_raid (grub_size_t uuidlen, char *uuid, int nmemb, struct grub_diskfilter_pv *pv; grub_err_t err; + /* We choose not to support more than 1024 disks */ + if (nmemb < 1 || nmemb > 1024) + { + grub_free (uuid); + return NULL; + } + switch (level) { case 1: -- 2.25.1