From patchwork Thu Feb 20 06:23:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 11393429 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8680C14BC for ; Thu, 20 Feb 2020 06:23:18 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 540042465D for ; Thu, 20 Feb 2020 06:23:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="XX9lUbWn" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 540042465D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 7B4AA6B0005; Thu, 20 Feb 2020 01:23:17 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 765BE6B0006; Thu, 20 Feb 2020 01:23:17 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 67AA06B0007; Thu, 20 Feb 2020 01:23:17 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0077.hostedemail.com [216.40.44.77]) by kanga.kvack.org (Postfix) with ESMTP id 4D9AF6B0005 for ; Thu, 20 Feb 2020 01:23:17 -0500 (EST) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 1D8D42C6D for ; Thu, 20 Feb 2020 06:23:17 +0000 (UTC) X-FDA: 76509513234.28.hole00_73eb66b413b44 X-Spam-Summary: 2,0,0,be945bd6a8b050d5,d41d8cd98f00b204,keescook@chromium.org,:akpm@linux-foundation.org:hughd@google.com:glider@google.com:keescook@chromium.org::linux-kernel@vger.kernel.org,RULES_HIT:41:152:355:379:541:800:960:967:973:988:989:1260:1277:1311:1313:1314:1345:1437:1515:1516:1518:1534:1542:1593:1594:1711:1730:1747:1777:1792:2393:2525:2559:2563:2682:2685:2693:2859:2933:2937:2939:2942:2945:2947:2951:2954:3022:3138:3139:3140:3141:3142:3353:3865:3866:3867:3868:3870:3872:3874:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4321:4605:5007:6261:6653:9025:9036:10004:10400:11026:11473:11658:11914:12043:12297:12438:12517:12519:12555:12698:12737:13161:13229:13894:14096:14097:14181:14394:14659:14721:21080:21444:21451:21627:30054,0,RBL:209.85.216.66:@chromium.org:.lbl8.mailshell.net-66.201.201.201 62.14.0.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:27,LUA_SUMMARY:none X-HE-Tag: hole00_73eb66b413b44 X-Filterd-Recvd-Size: 4683 Received: from mail-pj1-f66.google.com (mail-pj1-f66.google.com [209.85.216.66]) by imf46.hostedemail.com (Postfix) with ESMTP for ; Thu, 20 Feb 2020 06:23:16 +0000 (UTC) Received: by mail-pj1-f66.google.com with SMTP id q39so437162pjc.0 for ; Wed, 19 Feb 2020 22:23:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=eaPPmscQlj+AWtUQR/y2B7lA/cfvOcnI8Mj4BnPit3k=; b=XX9lUbWn/5B4I76NggdGaUA6Melm3yonu6fb13Fdexg0pZNNaY94FRS6DIyXajJj07 RYmQlj0RVtamoa+XMQdMOX3n2i8aixjoz+MGanaZt2EFZXSkB86rsBbBn5ICCDVhpOAB LUaTnpYKyh+JMXKa1Tiq9K5f9ONx1WXPeb6aI= 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:mime-version :content-transfer-encoding; bh=eaPPmscQlj+AWtUQR/y2B7lA/cfvOcnI8Mj4BnPit3k=; b=PR9jdgeU/JzybLplziITqVSN2PNO7qrRh6GSwC2s/gl0APRf8y+B+1cMjSvS9MJczP MZnwylaPPviYxcQvcR42UVM90qwKb5zFxjKsSlTueToieXiM3kyBTkDb3Pk1kh6h4/bv w8KfNQRVM4rHeG/qd2QagBJtM8zqCR3IcJ9SO3dAgK7zWWGSlz8vtm/yH911Hhy8/QWB 1oKC8X3u1rrpLXFPYh3ZysHahdGHzjzNgHarKctWcYtkKcz4VYDNiV6mpKZ30sQmE+A1 rahKCkGA+CUbhlENpx95dzQar4h9ANtFALfWdI6Fbf8V1AcembC9QWsWhrZlX+03VcrC KPsQ== X-Gm-Message-State: APjAAAUfp8LyhAfspPbaliincD1gG7rThTO1saGnYwOkbWcmeVBxjXIF eSD/23YyWcteQKX/dEpYkOAMjg== X-Google-Smtp-Source: APXvYqybrzR1Jcrl6AnW0y34px7XVuRxCPT/1UBHhOW7jjsgahCA8Jzlgc4CZWtHz4pVpWmXY+h9Mw== X-Received: by 2002:a17:902:222:: with SMTP id 31mr29543202plc.108.1582179795261; Wed, 19 Feb 2020 22:23:15 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id b186sm1260017pgc.46.2020.02.19.22.23.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Feb 2020 22:23:14 -0800 (PST) From: Kees Cook To: Andrew Morton , Hugh Dickins Cc: Alexander Potapenko , Kees Cook , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH] shmem: Distribute switch variables for initialization Date: Wed, 19 Feb 2020 22:23:12 -0800 Message-Id: <20200220062312.69165-1-keescook@chromium.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Variables declared in a switch statement before any case statements cannot be automatically initialized with compiler instrumentation (as they are not part of any execution flow). With GCC's proposed automatic stack variable initialization feature, this triggers a warning (and they don't get initialized). Clang's automatic stack variable initialization (via CONFIG_INIT_STACK_ALL=y) doesn't throw a warning, but it also doesn't initialize such variables[1]. Note that these warnings (or silent skipping) happen before the dead-store elimination optimization phase, so even when the automatic initializations are later elided in favor of direct initializations, the warnings remain. To avoid these problems, move such variables into the "case" where they're used or lift them up into the main function body. mm/shmem.c: In function ‘shmem_getpage_gfp’: mm/shmem.c:1816:10: warning: statement will never be executed [-Wswitch-unreachable] 1816 | loff_t i_size; | ^~~~~~ [1] https://bugs.llvm.org/show_bug.cgi?id=44916 Signed-off-by: Kees Cook --- mm/shmem.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index c8f7540ef048..8aca8275181f 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1813,17 +1813,20 @@ static int shmem_getpage_gfp(struct inode *inode, pgoff_t index, if (shmem_huge == SHMEM_HUGE_FORCE) goto alloc_huge; switch (sbinfo->huge) { - loff_t i_size; - pgoff_t off; case SHMEM_HUGE_NEVER: goto alloc_nohuge; - case SHMEM_HUGE_WITHIN_SIZE: + case SHMEM_HUGE_WITHIN_SIZE: { + loff_t i_size; + pgoff_t off; + off = round_up(index, HPAGE_PMD_NR); i_size = round_up(i_size_read(inode), PAGE_SIZE); if (i_size >= HPAGE_PMD_SIZE && i_size >> PAGE_SHIFT >= off) goto alloc_huge; - /* fallthrough */ + + fallthrough; + } case SHMEM_HUGE_ADVISE: if (sgp_huge == SGP_HUGE) goto alloc_huge;