Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1187308ybv; Thu, 20 Feb 2020 15:06:14 -0800 (PST) X-Google-Smtp-Source: APXvYqwo3a8B65qmsisiTVE8EIcEkNC02S09MnNdKwOl5JVfrKCD+aK1oFXb9A33vYz34JCvfu1k X-Received: by 2002:a9d:7:: with SMTP id 7mr24436780ota.26.1582239973872; Thu, 20 Feb 2020 15:06:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582239973; cv=none; d=google.com; s=arc-20160816; b=SnNo/Gv9YOgtEi9m07+2SqVkezzIEqQ0IQkywiqAj5djJE5MCG9YJIETFyrM1c3wmD 1pCTJrnQdQpWaua257OkMzLdUZUPts893d4r01D4hB8Y+xqW8TRpiBd+V50UFaefskB9 SczKSfkLta0FVegnKXmCzzP1/VH92l5Xu7f5JftpDWa/gRYxNd3/63qLiznaNuPUZBMk cV6IRsRmCVh4e061jI4IOi85tIBBTjWOZCyCZeGTBvwIcF3H3IpfrtSb4mdlzNSkrK0F YQ8iGOnfWWdgMx+tRcSIRSpocqjg8UzgUe2fL489w1w8j0DPR8wMeOS0THivxJvMsP3C HMiw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=c0kZSeFM/+814IXGYlA2mUh7BiAgeVF3A/1ZFnTcsZc=; b=ai/Z4DS5+freBXncEPcytuw+05xz6H37//A+LOvhFeodI5yQbmkU+JmufRVAIBD30X XHQ0uiBofVGqUJHy33VqnW/kEiXNPEVsIkPpBxRzxG39Mt51xtq/XS8HRKAyIf7fY8O1 gTaJwlHJBQjpH9A3i+8HzJYL4rzjQJGa+y2psLnXzNGR3iUjWiXj93TjjviI3x+fcwqx 0yHCLREIqukCSVmKwbSDeJZ1FCVBc+erf3HwywYQ8+Fv2A7CBPuyFK+WcL5IK1r6iMDr oZaDkWu7hRFjRjbHpqe0bWmUKdsN/Qt5Ujy3/0OlvWSGT3d8pXnv2AeSERxMB8t/sHWF zoag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=oNgGUgcX; 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 v24si482627otn.125.2020.02.20.15.06.00; Thu, 20 Feb 2020 15:06:13 -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=oNgGUgcX; 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 S1729258AbgBTXFj (ORCPT + 99 others); Thu, 20 Feb 2020 18:05:39 -0500 Received: from mail-pg1-f194.google.com ([209.85.215.194]:34098 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727135AbgBTXFi (ORCPT ); Thu, 20 Feb 2020 18:05:38 -0500 Received: by mail-pg1-f194.google.com with SMTP id j4so2690701pgi.1 for ; Thu, 20 Feb 2020 15:05:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=c0kZSeFM/+814IXGYlA2mUh7BiAgeVF3A/1ZFnTcsZc=; b=oNgGUgcXPIIzpKoyYuQCg2iZgDGOqNq2Nuywq1XBACo+UkBmEshyJJcH4Rq/FYPAyV wmpxnA+i3Uj2NsKgZB7+n+cELRd+40ZezWMN3LL3O7GAvIzFSkQ7jxZrbtedJlR/P5zc qznGHo5Zt1TIpx7dru+9PdeL5yFGhMh8D4Ztc= 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:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=c0kZSeFM/+814IXGYlA2mUh7BiAgeVF3A/1ZFnTcsZc=; b=Xe3rNAUv6yZUOZ7iQf3PcpnZZJ+CnzvfmUNjbfjv1C/JrOLMxX4RdeZb00Zva3244r VwXE9pb3iM12ZJ9elsRAKtw0EpRJFT0ywYAaUjwtwtnuPYlDLEbP7PoEyywKs4H4EfPv 7k6WNZMQEpdjxan6G70nCjQQ7W9iahrZBy6Sr4kgjCbRPlbyT5oUKqh5ncjt8fRG0+3l zsuuJiE6t+yLzv8JxxV7JwYTylCWrcWN/oNU6xVuiu8MFh5cZxbow0ztiFZDbqKZ6n6M 06fMJg9bbNx3lwDbDH+YI+3W2Y3TRlz8jCE2Coml6p7tfpVsuMwARrsGdqJwAfLAzM4J RiiA== X-Gm-Message-State: APjAAAWr3mfp/WLevn0pOPhvQ13MZXkrqsd5U9edSw3DTyyGrpXNo0+6 Z5tw6IRhhLpXbbrp4dwH27BOxw== X-Received: by 2002:aa7:8f33:: with SMTP id y19mr32954425pfr.47.1582239938288; Thu, 20 Feb 2020 15:05:38 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id g7sm660356pfq.33.2020.02.20.15.05.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Feb 2020 15:05:37 -0800 (PST) Date: Thu, 20 Feb 2020 15:05:36 -0800 From: Kees Cook To: Boris Ostrovsky Cc: =?iso-8859-1?Q?J=FCrgen_Gro=DF?= , Alexander Potapenko , Stefano Stabellini , xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] x86/xen: Distribute switch variables for initialization Message-ID: <202002201505.C3863B2D0@keescook> References: <20200220062318.69299-1-keescook@chromium.org> <16a166da-c6e7-aa36-53a0-1b56197c8fc0@suse.com> <8a7f5bd7-2bb6-d187-cc6e-87ff01c440ce@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <8a7f5bd7-2bb6-d187-cc6e-87ff01c440ce@oracle.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Feb 20, 2020 at 11:33:41AM -0500, Boris Ostrovsky wrote: > > > On 2/20/20 1:37 AM, Jürgen Groß wrote: > > On 20.02.20 07:23, Kees Cook wrote: > >> 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 > > > > Reviewed-by: Juergen Gross > > > > Applied to for-linus-5.6. > > (I replaced 'unsigned' with 'unsigned int' to quiet down checkpatch ) Oh, good call. Sorry I missed that! Thanks! -- Kees Cook