From patchwork Wed Mar 7 21:25:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 10265365 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A0A0E60247 for ; Wed, 7 Mar 2018 21:26:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9811029378 for ; Wed, 7 Mar 2018 21:26:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8CD6C2940B; Wed, 7 Mar 2018 21:26:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.wl.linuxfoundation.org (Postfix) with SMTP id AB94829378 for ; Wed, 7 Mar 2018 21:26:13 +0000 (UTC) Received: (qmail 6124 invoked by uid 550); 7 Mar 2018 21:26:10 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Delivered-To: mailing list kernel-hardening@lists.openwall.com Received: (qmail 6082 invoked from network); 7 Mar 2018 21:26:09 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:mime-version:content-disposition; bh=JWKxbolXDV+D3bGvNGvc+WWEC6sQGh7+nzTc4X5nQrM=; b=dHylESBwOSvI8RgrJ6lqBSnsF/4jpLMs4ELwbNypC2K8NpTmbL/KtN7mY6IWoHMI5F vQK1ZwobZ8In3ASZyGxs4wdBRoudacfbpOVP8hYJJ8L9tMmgPsOH0LgQw+9mniC22N3r POU1XE/DDujHbq83FjGO1AeliIpjeuXHem6Po= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=JWKxbolXDV+D3bGvNGvc+WWEC6sQGh7+nzTc4X5nQrM=; b=Tbmhyf9MHKAhvg0LUEGF9zMs8E7sukYFN1RoJZollzAQG0VUkAnKO1HHV2Hk1UN0pt 9TPBlB4oWaZj9z+zi6n0JGFYHyOgUkavJEGNEyCZ8Bn/FrkdZbbKdH0MP+ngj4MfTErj XOiTFY25AUqTbLnU6JDMf14LPaIFih4nd7uUnEBr80upsM5UgG2giiPie4B9h0GQN+kE 4hASeoWs5JOthwHWVt35NAhRihHagUrrHKN3voL9+kDbA5itojI6VbuNP1egpzNdMq3L 7n2q6hNRGrY83+TXRVViYdV0WrFBDx7Xq3o1myPedJF4igA3G7FDDGOn/PCia0wJIPvS 4Dmw== X-Gm-Message-State: APf1xPDuChSsEEA67sm0tc0pMpKerwNgTBr9a5CsG5ytmvnD/LCuZbxA J2jvV4GjEmL2Dp3TqrbVKDaI8w== X-Google-Smtp-Source: AG47ELt/kvbGAuFnCMWI2E/JtlZBY4rUiCW6PVTFpftr+O0zx5L2E/21DPFhZWY/E5OjdbpsJbOUvg== X-Received: by 10.99.127.29 with SMTP id a29mr19029408pgd.451.1520457958004; Wed, 07 Mar 2018 13:25:58 -0800 (PST) Date: Wed, 7 Mar 2018 13:25:55 -0800 From: Kees Cook To: Andrew Morton Cc: Yury Norov , Andy Shevchenko , Matthew Wilcox , linux-kernel@vger.kernel.org, kernel-hardening@lists.openwall.com Subject: [PATCH] test_bitmap: Do not accidentally use stack VLA Message-ID: <20180307212555.GA17927@beast> MIME-Version: 1.0 Content-Disposition: inline X-Virus-Scanned: ClamAV using ClamSMTP This avoids an accidental stack VLA (since the compiler thinks the value of "len" can change, even when marked "const"). This just replaces it with a #define so it will DTRT. Seen with -Wvla. Fixed as part of the directive to remove all VLAs from the kernel: https://lkml.org/lkml/2018/3/7/621 Cc: Yury Norov Cc: Andy Shevchenko Cc: Matthew Wilcox Signed-off-by: Kees Cook --- lib/test_bitmap.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/test_bitmap.c b/lib/test_bitmap.c index b3f235baa05d..756f20ad03db 100644 --- a/lib/test_bitmap.c +++ b/lib/test_bitmap.c @@ -292,15 +292,17 @@ static void __init test_bitmap_parselist(void) } } +#define EXP_BYTES (sizeof(exp) * 8) + static void __init test_bitmap_arr32(void) { - unsigned int nbits, next_bit, len = sizeof(exp) * 8; + unsigned int nbits, next_bit; u32 arr[sizeof(exp) / 4]; - DECLARE_BITMAP(bmap2, len); + DECLARE_BITMAP(bmap2, EXP_BYTES); memset(arr, 0xa5, sizeof(arr)); - for (nbits = 0; nbits < len; ++nbits) { + for (nbits = 0; nbits < EXP_BYTES; ++nbits) { bitmap_to_arr32(arr, exp, nbits); bitmap_from_arr32(bmap2, arr, nbits); expect_eq_bitmap(bmap2, exp, nbits); @@ -312,7 +314,7 @@ static void __init test_bitmap_arr32(void) " tail is not safely cleared: %d\n", nbits, next_bit); - if (nbits < len - 32) + if (nbits < EXP_BYTES - 32) expect_eq_uint(arr[DIV_ROUND_UP(nbits, 32)], 0xa5a5a5a5); }