Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1607597

[PATCH] virtio_balloon: prevent uninitialized variable use

Path csiph.com!news.mixmin.net!news.unit0.net!news.panservice.it!bofh.it!news.nic.it!robomod
From Arnd Bergmann <arnd@arndb.de>
Newsgroups linux.kernel
Subject [PATCH] virtio_balloon: prevent uninitialized variable use
Date Thu, 23 Mar 2017 16:20:02 +0100
Message-ID <tocGS-3Wl-5@gated-at.bofh.it> (permalink)
X-Original-To "Michael S. Tsirkin" <mst@redhat.com>, Jason Wang <jasowang@redhat.com>
X-Mailer git-send-email 2.9.0
X-Provags-ID V03:K0:suLpLs04jygvelN9GfdDTC0stXdOZDHynKvkTQC8I2k6ubRnY7v dHZZHYPiL6pmaJ67YT4PDnGNe/lkwnb3y/59ArnFXB3ZxvRapMCtYqakR7pMPd82iD5LtwY V67WQwRByH1yK4Fj8TeFWGRXez584SxQWdb0G/k3fZFN+UXdJZx1q/nNmxD42tHuPJ+tgy8 NJDP4tu0mUwA8xl9T3sxQ==
X-Ui-Out-Filterresults notjunk:1;V01:K0:3/OC+5t9QrQ=:3v0HpQMP4WYV0OHYRI2klu Dm9iIi7SMwkuLULW/s/PKWOv+i3R2F7XJq8clol2rvjXYPncVNYZbS4dEAYSwoGEOD+1rqRod 1pSjgy9s5rLlO6UyB4qcN8+RyJH78VTQJ3DRv6W0/jVTREQQZzX0LME+H9jF5zZGqu35vKlgr XEJisls7zLxlUqGWagPyfNf1egjXwfDfb7ghEhJPHRsNTkxd5VDqmNC312DQ2jAwBlQcRvaF/ PvtNn1LFvRRErUyED5EMICVTULnwzVJF808aVdAPnY9zat2dZHFJfjlGuXe2jfHe7d40/38Ft eIYHKDpE3Rz/qftMtiG1vtSwqHkIiYo9WIy2tzHFjVR8hvPYZJEO17t9DGPOJvNRxfnEYrz7+ y5hr4hsGta/gLxW+dMw0aGyMSsVyyCLhU2AIO4+t9OuQNmd97FR/BqmCb2TIA17yU8ewGnmRP Rm3uWztLpnfQB8T7j6+3JBDRmgBtdrHzNr784GrijrA+BFOCpTgGpvBuFVEXXOPoj24KrG2ZF WzAF9v8gog3gszM6a7zlO7f/5eYyrxiRXJFcayS+HAevPi+a9nHUDLuqtg4Iks/gm+8zxHIBC +XWdchewyn/2BmepPcn5+Vul7EI7ThkEm1cEWMGqdQIsGYR4ZlEBMU+KyVANF5TbxbMNrsL1f gD0slq2BwcvI5qkKEm5H0FHQh0iGEE3jlskS0S/S8XpcNgbL7/OVHUyfR5fub9VCmyn0=
Sender robomod@news.nic.it
List-ID <linux-kernel.vger.kernel.org>
X-Mailing-List linux-kernel@vger.kernel.org
Approved robomod@news.nic.it
Lines 40
Organization linux.* mail to news gateway
X-Original-Cc Arnd Bergmann <arnd@arndb.de>, Minchan Kim <minchan@kernel.org>, Andrew Morton <akpm@linux-foundation.org>, Konstantin Neumoin <kneumoin@virtuozzo.com>, "Denis V. Lunev" <den@openvz.org>, Yisheng Xie <xieyisheng1@huawei.com>, Ingo Molnar <mingo@kernel.org>, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org
X-Original-Date Thu, 23 Mar 2017 16:17:19 +0100
X-Original-Message-ID <20170323151728.679684-1-arnd@arndb.de>
X-Original-Sender linux-kernel-owner@vger.kernel.org
Xref csiph.com linux.kernel:1607597

Show key headers only | View raw


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 <arnd@arndb.de>
---
 drivers/virtio/virtio_balloon.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
index 4e1191508228..cd5c54e2003d 100644
--- a/drivers/virtio/virtio_balloon.c
+++ b/drivers/virtio/virtio_balloon.c
@@ -254,12 +254,14 @@ static void update_balloon_stats(struct virtio_balloon *vb)
 
 	available = si_mem_available();
 
+#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,
-- 
2.9.0

Back to linux.kernel | Previous | NextNext in thread | Find similar | Unroll thread


Thread

[PATCH] virtio_balloon: prevent uninitialized variable use Arnd Bergmann <arnd@arndb.de> - 2017-03-23 16:20 +0100
  Re: [PATCH] virtio_balloon: prevent uninitialized variable use David Hildenbrand <david@redhat.com> - 2017-03-24 19:40 +0100
    Re: [PATCH] virtio_balloon: prevent uninitialized variable use Ladi Prosek <lprosek@redhat.com> - 2017-03-24 21:20 +0100
      Re: [PATCH] virtio_balloon: prevent uninitialized variable use Arnd Bergmann <arnd@arndb.de> - 2017-03-24 21:50 +0100
        Re: [PATCH] virtio_balloon: prevent uninitialized variable use "Michael S. Tsirkin" <mst@redhat.com> - 2017-03-24 22:00 +0100
          Re: [PATCH] virtio_balloon: prevent uninitialized variable use Ladi Prosek <lprosek@redhat.com> - 2017-03-27 12:10 +0200

csiph-web