From patchwork Tue Feb 20 11:54:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 128881 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp4554445ljc; Tue, 20 Feb 2018 03:59:28 -0800 (PST) X-Google-Smtp-Source: AH8x227X4b9PPpgx5D3y4FJ37pf/okefWtqlwrf63/nBhxwHVIj+51GHEzHUUFbunijPiP5vwWm/ X-Received: by 10.99.165.71 with SMTP id r7mr15111833pgu.60.1519127968752; Tue, 20 Feb 2018 03:59:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519127968; cv=none; d=google.com; s=arc-20160816; b=MOwTfczmMs3rgnxjX7qipElCHgSvWvjY43WmXeEYx6Riy/SoMro+ipX9YDlYwnOL+z u4CT+zDSVuOt7dpQNoHOHYTayAiyKew90xeSHMEOCgkpNpZ6MvK5g5/T0edom0OYRR21 nWIxYgg8eRX9x3O1YP5VaGBeZZ52E4jMnI2fTZZQdr2CuOJnCXMg+RIeWJqxeVa6Kz2m q5HQdbbDXdXNBRo/+kXcIOdiz61esAZZ57kykOJS3oCDaZTCBPPbxvlBiplerfytCe8k dyQ570oJXMi65L4QAowiNJ7vbzsm9tTZu0z1LmBPYcwLfrM7YuU/NZOJwGkryiiRWJI8 P2tA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=w/kY3moN5fjW4Ri+T2lNxreXwUdwZ9LA7wrDaiuBch4=; b=vXBVydD67UJVEDP2FPejszraUr5lDCY6o756Z4Ixi7D8F/CVdiDObAXPjzx0iQH+5P 2HeJwpQxSmQ9BnKMskcFZOK56e7BSPxUIH645du7LAJFQS6mdhgsc5zxpqqjM59r8yaI oo2EE7MkFoMgw0XHlwSvBRxbZ5vo2f1Cbc0OsNld0lbvmDkiLFTtPLpdlu0NO1jA5ENQ xhzKW2FY5g3HPdWjzc2KwzzgyyDBiHpJTps+6KOgHTv/O2GyaSIJZ8r8woCYEadoBuiS gI1T7dfAwBmVMfwBptCU6TP5OAKc2oB4SAPfgGHKemmNtGS7UFbN8+JI2ZpAvBDn4F0u NqkA== ARC-Authentication-Results: i=1; mx.google.com; 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 u6si2165284pfd.236.2018.02.20.03.59.28; Tue, 20 Feb 2018 03:59:28 -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; 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 S1751910AbeBTL7Y (ORCPT + 28 others); Tue, 20 Feb 2018 06:59:24 -0500 Received: from mout.kundenserver.de ([212.227.17.13]:58791 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751868AbeBTL7T (ORCPT ); Tue, 20 Feb 2018 06:59:19 -0500 Received: from wuerfel.lan ([95.208.111.237]) by mrelayeu.kundenserver.de (mreue105 [212.227.15.145]) with ESMTPA (Nemesis) id 0MTgbQ-1fEbgn38Hw-00QVcr; Tue, 20 Feb 2018 12:59:13 +0100 From: Arnd Bergmann To: stable@vger.kernel.org Cc: Greg KH , linux-kernel@vger.kernel.org, Arnd Bergmann , Ladi Prosek , "Michael S . Tsirkin" , virtualization@lists.linux-foundation.org Subject: [4.4-stable 12/22] virtio_balloon: prevent uninitialized variable use Date: Tue, 20 Feb 2018 12:54:59 +0100 Message-Id: <20180220115527.1806578-13-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20180220115527.1806578-1-arnd@arndb.de> References: <20180220115527.1806578-1-arnd@arndb.de> X-Provags-ID: V03:K0:0VKTfdRl6SaYrJSHj7Om8/QLHR38aWGMcre6ZIb4quAvbOxCECo pVBp4jC/p3dkLIoYJom3agahCD9y33MMA09eFeJ5YdfyVY3eFyIT3SVXbewD5eXdiHjEvxI 12Dw1GX720ZU3GGt6sAhmcTNq48sUEq5b6bxzxBqvi4PGdoUc0oo3ObEg2ybuZNmxOzNJpE eXeeyMMGaCjoc0ffRc2wg== X-UI-Out-Filterresults: notjunk:1; V01:K0:j4tCJBnc6dA=:VoU56uRUIBmij9nA9AeV0/ xpNmbA9p4+fexTqlY1q5kpLSkI9u9ygfSk9GhTRLlDvbDbCS/RMAmsr5mZpntZluBG/7jnK1a pVuSj2gIG40wpAu1mI+Wl+AJuUw3mSzMG8A5AlwUjJKDNYA4s1bfSHtwYBVpE4lmgI+aYknyj bjf3m30yQWwlp8OdKogvr62VTD78PtqIiNeZY6FtdjsPWnwP7xGm6w+nsaaob0yFEus5RJDIA a/wFeeshcajciDdFqtLjgdW2/dqj/HFnpzh0UNFPqN+ENLC11HVNcnJRvAeH+bJ12///O7OKk GktK529+zh3AGuTViMAkojKxExzLlr80SJ6qi/FPUzN+vngtMVEC9zCa2UXjyLU5sN9DsSNDl jb5CWGm67ZjyZzfo2iRczC5qxuW+RK5JXU7oaHXyERz93n7g6607IOHE8JvzAxh/lVzrh61Nl UXGghAByuv91JdVx9ChGcj5FajieLQXayUPLufUnLtob5Yo53QzNF2PcqN3zucT7REa9Oegem 37AnI1jQk9PrLvnI8dWrduPRzzqVE6efp/p20ibrge9bA5wTTL2rPrdJD7BABmtaQPWIwzvqh P/r07SDRpQ51XOVGuvEiGPeE9ISHLm/fcuxZOlMxun4eoC6UtmRXb0ZJB3YASOcM/xXERD1Yb YZqU8u5Q33+Pt7+PIFhmzUxSUcEYWu09EP5op63v3WMwDWgjD0IPLXxHoHHewesMSX+K1rWjV yAIgFvnvVjqdDD2uRIRc5Vt0Zmi9Xz5f47bfcw== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org commit f0bb2d50dfcc519f06f901aac88502be6ff1df2c upstream. The latest gcc-7.0.1 snapshot reports a new warning: virtio/virtio_balloon.c: In function 'update_balloon_stats': virtio/virtio_balloon.c:258:26: error: 'events[2]' is used uninitialized in this function [-Werror=uninitialized] virtio/virtio_balloon.c:260:26: error: 'events[3]' is used uninitialized in this function [-Werror=uninitialized] virtio/virtio_balloon.c:261:56: error: 'events[18]' is used uninitialized in this function [-Werror=uninitialized] virtio/virtio_balloon.c:262:56: error: 'events[17]' is used uninitialized in this function [-Werror=uninitialized] This seems absolutely right, so we should add an extra check to prevent copying uninitialized stack data into the statistics. >From all I can tell, this has been broken since the statistics code was originally added in 2.6.34. Fixes: 9564e138b1f6 ("virtio: Add memory statistics reporting to the balloon driver (V4)") Signed-off-by: Arnd Bergmann Signed-off-by: Ladi Prosek Signed-off-by: Michael S. Tsirkin [arnd: backported to 4.4] Signed-off-by: Arnd Bergmann --- drivers/virtio/virtio_balloon.c | 3 +++ 1 file changed, 3 insertions(+) -- 2.9.0 diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c index 01d15dca940e..26d0dff069f0 100644 --- a/drivers/virtio/virtio_balloon.c +++ b/drivers/virtio/virtio_balloon.c @@ -239,12 +239,15 @@ static void update_balloon_stats(struct virtio_balloon *vb) all_vm_events(events); si_meminfo(&i); + +#ifdef CONFIG_VM_EVENT_COUNTERS update_stat(vb, idx++, VIRTIO_BALLOON_S_SWAP_IN, pages_to_bytes(events[PSWPIN])); update_stat(vb, idx++, VIRTIO_BALLOON_S_SWAP_OUT, pages_to_bytes(events[PSWPOUT])); update_stat(vb, idx++, VIRTIO_BALLOON_S_MAJFLT, events[PGMAJFAULT]); update_stat(vb, idx++, VIRTIO_BALLOON_S_MINFLT, events[PGFAULT]); +#endif update_stat(vb, idx++, VIRTIO_BALLOON_S_MEMFREE, pages_to_bytes(i.freeram)); update_stat(vb, idx++, VIRTIO_BALLOON_S_MEMTOT,