Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp672810ybh; Tue, 10 Mar 2020 06:14:54 -0700 (PDT) X-Google-Smtp-Source: ADFU+vv54aKRiGS9/+3ZonuALzp9JGYhdOb0ODf8NJj1V5m285XZDDbCacYUsj0OXX97X87s11db X-Received: by 2002:a05:6808:b13:: with SMTP id s19mr1104539oij.60.1583846094344; Tue, 10 Mar 2020 06:14:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583846094; cv=none; d=google.com; s=arc-20160816; b=jMDQy7x13T+lxhC7p5Rqs6FfAGMKFZ1Xhv2vL1IuDUVgvdD4E7deolfDIsMsEuA3D2 B6NVWFKDhcTw7nj+YcfsNs3ZSsN/Bm94txhh3sDeoWJRRhPFnfX/JXhDY4ttu2kfK7mK /Ri3xs1CDcQJMCuEzcak1+H0x7rsaZlsU3PEuXmA1Z9UUKcMbb6nJnucSMlcJKdj3uHa xvaPU2UZZ8HN/Pbpz7DdiFAyVs7bfxT+YOz1WZVoACpevwr+ZoxwGrsiozq86SVbHe1J Wp/ulxr43Ma8BgatIqhEmmk929ZYEZwuikf96+DQsFtFxRAOJeX0ZZZv5IRdomieh4I7 /vsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=kIZMM3n2a2RkZQE+Ji5Ks+wQ7G0pos0sCh//LFKrAfY=; b=hr2minzUiLol1rkr2nrUOHhpoK9DtVjqLw2ZqIDPC5pQ2JvDSum7sRjecE8GGFIsJw kRYBLehLH5wnDcltqgwJI6pgM3Ltdu+3QVL4DMAeLwyHt0aSyKOSkpfRrmQZIaYvxO6Z k5tfIDr5TnahSpbKG1yDkmUyqwblW4Mq5emJzP0y4lS9aWm4kobDomrwR9AqkM5WYL2t a8izFxkkHxpuTq3fIQiCDHmOUOHMYYuN98PDUMkc6DhF/NtI+BDfQrdQYCOcrKQR81T6 5cnpgZQou4uwyoZJEB1IgR2RqGKYoDQd0c/LtsDUZIY9mLGIjfcpbNXaCVjVHvu6JI4k WO/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=P6xyhMiR; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y25si5810093otj.304.2020.03.10.06.14.41; Tue, 10 Mar 2020 06:14:54 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=P6xyhMiR; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731856AbgCJNOT (ORCPT + 99 others); Tue, 10 Mar 2020 09:14:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:37904 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729264AbgCJNOS (ORCPT ); Tue, 10 Mar 2020 09:14:18 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3253224649; Tue, 10 Mar 2020 13:14:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583846057; bh=gEpI/WZAhYT91gRr4vJsYerumiMWnUy/i4/TlfwAmcY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P6xyhMiRpAzcMuQ7qGwMbG6WL0U+fZrCZYQPornA89q6lA6daO5s5yKM4/Zzo3ncS StOYsB0+mR3WyqbB+wMDcCpl9r1Lo00075Mzk/gdaf85lKuMXUxPgkkhs3jADqUhlf e+DbjfR5NnkxaxR/GHS5DUE6X73VqHVoyXNQa0cA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kees Cook , Juergen Gross , Boris Ostrovsky , Sasha Levin Subject: [PATCH 4.19 30/86] x86/xen: Distribute switch variables for initialization Date: Tue, 10 Mar 2020 13:44:54 +0100 Message-Id: <20200310124532.408826948@linuxfoundation.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200310124530.808338541@linuxfoundation.org> References: <20200310124530.808338541@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kees Cook [ Upstream commit 9038ec99ceb94fb8d93ade5e236b2928f0792c7c ] 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. arch/x86/xen/enlighten_pv.c: In function ‘xen_write_msr_safe’: arch/x86/xen/enlighten_pv.c:904:12: warning: statement will never be executed [-Wswitch-unreachable] 904 | unsigned which; | ^~~~~ [1] https://bugs.llvm.org/show_bug.cgi?id=44916 Signed-off-by: Kees Cook Link: https://lore.kernel.org/r/20200220062318.69299-1-keescook@chromium.org Reviewed-by: Juergen Gross [boris: made @which an 'unsigned int'] Signed-off-by: Boris Ostrovsky Signed-off-by: Sasha Levin --- arch/x86/xen/enlighten_pv.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/arch/x86/xen/enlighten_pv.c b/arch/x86/xen/enlighten_pv.c index 1730a26ff6abc..76864ea591605 100644 --- a/arch/x86/xen/enlighten_pv.c +++ b/arch/x86/xen/enlighten_pv.c @@ -908,14 +908,15 @@ static u64 xen_read_msr_safe(unsigned int msr, int *err) static int xen_write_msr_safe(unsigned int msr, unsigned low, unsigned high) { int ret; +#ifdef CONFIG_X86_64 + unsigned int which; + u64 base; +#endif ret = 0; switch (msr) { #ifdef CONFIG_X86_64 - unsigned which; - u64 base; - case MSR_FS_BASE: which = SEGBASE_FS; goto set; case MSR_KERNEL_GS_BASE: which = SEGBASE_GS_USER; goto set; case MSR_GS_BASE: which = SEGBASE_GS_KERNEL; goto set; -- 2.20.1