From patchwork Tue Mar 13 19:50:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Salvatore Mesoraca X-Patchwork-Id: 10280641 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 62710602C2 for ; Tue, 13 Mar 2018 19:51:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4E7592842E for ; Tue, 13 Mar 2018 19:51:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 48E63284C9; Tue, 13 Mar 2018 19:51:37 +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, FREEMAIL_FROM, 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 E84B3286D4 for ; Tue, 13 Mar 2018 19:50:53 +0000 (UTC) Received: (qmail 9279 invoked by uid 550); 13 Mar 2018 19:50:49 -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 9235 invoked from network); 13 Mar 2018 19:50:48 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=z3LpzP0/rt/gJXoQPm132osZo5pA7pNwvqGehVEpDeI=; b=RrfBxtQdiA2UlR0iHJ4robya5A8zuMNlobAob6Jh9CWzecwRuBx8+ftY7JJHAKCQAZ 73ODNfOXUYLcIKTvkxNTN0Lch+2shUpfwBvg2Vp/PJ417FAqhOPLWOJLEUymjVwv2hV+ rn2yLxsbVZu9D2PrEQ5xG7iVpj4TMI+t7eSjRjdlDRq3DZM1/a3KpmqGM7M5+pOaBmI4 dQziJ8L9OurVnDGOd60VsTCmk2Qescq0gJfSfJkbakYJ54oCcb4nGkbc1ahyVOSVqk1s zRDsClrw5lqTiTYBGzYk+Dtg1BZaIKxRo/qRm+RQTYRmLko0K5VK7gONJyI3pcNmihVo uTlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=z3LpzP0/rt/gJXoQPm132osZo5pA7pNwvqGehVEpDeI=; b=skLwNOeI4wiHWYUfzE8FDcv5S1JU22nBjMECNOGXfYRDGHkMX46k5lDFqneYW8R3pA C+fNXwVjpp0MvZ6r6eReP1KW5OasTib8wdcOwwUTSRHnpgx3C5QUeTIK9TL/hSPPetA5 TQ5ny86zGVQQhOM0diHNCzt/XVygzfbUoyJ4ozRsO0NoqeUL4NAB+iDX8Dglad8CaSFh s8gbmaoy+Zwo6fzn2aNixADDGPTOaXDB2929TeC1RmOuqU8iRQkgd7AZR/Rxw72n4S7u L5tZVncU9WWvjKd9jHF9wt3O+RqCyI06aCvUjEVYYeg01vWjZ/uqzY9vZD6iOl6jiQCZ Dyhw== X-Gm-Message-State: AElRT7EWC566Ki992Rkg12ZUeV99/W/WW14jyQW7T1XQmIjwH5kmTPHp 9msVKYlad/QHh0rogSjAmT8= X-Google-Smtp-Source: AG47ELtJnZRZc1hMCBv58gO8jwFvt/ZdzXjrUFe3sRadOSsfUAt2KosSIDuZ3F+3x4CiJsYWnHHC3g== X-Received: by 10.223.172.167 with SMTP id o36mr1693158wrc.34.1520970636967; Tue, 13 Mar 2018 12:50:36 -0700 (PDT) From: Salvatore Mesoraca To: linux-kernel@vger.kernel.org Cc: kernel-hardening@lists.openwall.com, linux-btrfs@vger.kernel.org, Chris Mason , David Sterba , Josef Bacik , Kees Cook , Salvatore Mesoraca Subject: [PATCH] Btrfs: drop a VLA in btrfs_check_super_csum() Date: Tue, 13 Mar 2018 20:50:22 +0100 Message-Id: <1520970622-19535-1-git-send-email-s.mesoraca16@gmail.com> X-Mailer: git-send-email 1.9.1 X-Virus-Scanned: ClamAV using ClamSMTP Avoid a VLA[1] by using a real constant expression instead of a variable. The compiler should be able to optimize the original code and avoid using an actual VLA. Anyway this change is useful because it will avoid a false positive with -Wvla, it might also help the compiler generating better code. [1] https://lkml.org/lkml/2018/3/7/621 Signed-off-by: Salvatore Mesoraca --- fs/btrfs/disk-io.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 21f34ad..88cef92 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -403,8 +403,7 @@ static int btrfs_check_super_csum(struct btrfs_fs_info *fs_info, if (csum_type == BTRFS_CSUM_TYPE_CRC32) { u32 crc = ~(u32)0; - const int csum_size = sizeof(crc); - char result[csum_size]; + char result[sizeof(crc)]; /* * The super_block structure does not span the whole @@ -415,7 +414,7 @@ static int btrfs_check_super_csum(struct btrfs_fs_info *fs_info, crc, BTRFS_SUPER_INFO_SIZE - BTRFS_CSUM_SIZE); btrfs_csum_final(crc, result); - if (memcmp(raw_disk_sb, result, csum_size)) + if (memcmp(raw_disk_sb, result, sizeof(result))) ret = 1; }