Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp320655ybv; Wed, 19 Feb 2020 22:24:19 -0800 (PST) X-Google-Smtp-Source: APXvYqxcTcXDzCGs8Rh05a+juW6XL/vNbEmSH68mL/VsQj/1+QV4epkZtXJ2BwgSXo+fZ0JfumVx X-Received: by 2002:a9d:6a85:: with SMTP id l5mr23521059otq.231.1582179859658; Wed, 19 Feb 2020 22:24:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582179859; cv=none; d=google.com; s=arc-20160816; b=R1qV6RcE5JBHE/EhBHFlpjNuTl/Z40jRhuF5nQU5LdL8FPa4KItgra+q6vVP/ukgdn Xey5kqaT1ciF20nAkrtGf0gk7gNgaI+enbjpnEmv0W3sOuj26R28vO05fj9WwaHfGsuX 2slZ5RczUPgA55i5jHgavnPF+IZohgplFY5pjKzYVJlIVpyn0rprj5a4aVLr2Oy/d5aF 8pYWfpNTUZNbxaCE9Qbhj31ZxwJvaegMgwNQiNftzyFhdT08cJVv4cneidBcimFLPGIN dwAWhe8gHQBNieb5GKEgGuisZiBCZiFj2dLS1HKp2qLSr2QKUUoXRh8tVATvosxfTtcI q02g== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=pK6zifq3Fj1hZPmmtdvS+UBS/FWrDP/7PRY/z1oHHl8=; b=PXJJE4mN+W1XvzfujhgI5O1rF08ccpk9KtKYTuzvlKBgHe1j9sFYo8aACQAmWeBEZ0 08CGLbtlXd0c2qokFS2ug2XCbvwhIGbWy+ANEYad4wRJ8QT29vefwRch3dCSX9bceLL0 nqN/CPlwZwiu6uPOnVAH0vDoMgDKVkwldRoKWuH5RK6WTIw58Ae1ChU6eT/Nrwkdd9KW BbnK9BvwG7oscXySDvTI7KnoG9IkD6DrrELhqkcw0yEAyIhorDWiDb+BsY4l5HgqlnPf HNdKtJY1opFbWgjlAi23zsNMRiyWoCin/XslQEIAyOv/vltx3SW0bbXDLQ2kR6sV268U RjJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="KZPJA/xX"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p3si11039523oih.186.2020.02.19.22.24.07; Wed, 19 Feb 2020 22:24:19 -0800 (PST) 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=@chromium.org header.s=google header.b="KZPJA/xX"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727755AbgBTGX2 (ORCPT + 99 others); Thu, 20 Feb 2020 01:23:28 -0500 Received: from mail-pl1-f193.google.com ([209.85.214.193]:42752 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727513AbgBTGXV (ORCPT ); Thu, 20 Feb 2020 01:23:21 -0500 Received: by mail-pl1-f193.google.com with SMTP id e8so1123786plt.9 for ; Wed, 19 Feb 2020 22:23:20 -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=pK6zifq3Fj1hZPmmtdvS+UBS/FWrDP/7PRY/z1oHHl8=; b=KZPJA/xXWgvj7+EDceNGW99DsMGfVsrwZtMNYFEQmEcfbi6t1Ltywm8yF3gRS+KFsW YYa/KruX+agIH6tt/eZGI71UjpwjuT3jsuFYNKw+P7dbnGut/vUuytmTV4wCLvbb1OWN mFx5qdjyKzEPpPz0IfGRUIg5ongLMg7FFfcz0= 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=pK6zifq3Fj1hZPmmtdvS+UBS/FWrDP/7PRY/z1oHHl8=; b=fIAfK9Wun7gi8hl8GRY50FDfj9mKupG+5dn3ICs1aefnYhVheepKpOKhNkcyCOof5i dDesHQVE0RVCMPV3f2FNGVzspcWPA6KU5xBvQatUCEEFN2WyBN5DEykVsYkHoLDgvRNl bKz1w+aC1/2zs/VMjq7Z+rOMKX5tWPyiHOzbhJplH6Go0PNZppCzfiaGKfjzQQzgH/b5 XkzjL6A7CalPgj1kaQG2FfFymOOqQc2PN8DlAJyTJ0jqBkESQCHCky2rKDG0cGIEACKf 1x8Cpw38hVd3iPKgNZkICD+ZVKuVOl5Uo8DKFON+Qq0VFema2W+NlbdBru2Sz3ic1xPk O0hA== X-Gm-Message-State: APjAAAXJLFNBtkyYhfKjMDG9/aekvTeZa1L41FT2xEvgbq+92SSq3vVD HuXRS2dGLu1giTLed4t0Rx6jhQ== X-Received: by 2002:a17:90a:f316:: with SMTP id ca22mr1759190pjb.59.1582179800527; Wed, 19 Feb 2020 22:23:20 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id 3sm1760480pfi.13.2020.02.19.22.23.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Feb 2020 22:23:19 -0800 (PST) From: Kees Cook To: Boris Ostrovsky , Juergen Gross Cc: Alexander Potapenko , Kees Cook , Stefano Stabellini , xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org Subject: [PATCH] x86/xen: Distribute switch variables for initialization Date: Wed, 19 Feb 2020 22:23:18 -0800 Message-Id: <20200220062318.69299-1-keescook@chromium.org> X-Mailer: git-send-email 2.20.1 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 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 --- 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 1f756ffffe8b..789dc12b7962 100644 --- a/arch/x86/xen/enlighten_pv.c +++ b/arch/x86/xen/enlighten_pv.c @@ -896,14 +896,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 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;