Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752648AbdGPOFC (ORCPT ); Sun, 16 Jul 2017 10:05:02 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:43278 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751824AbdGPN6B (ORCPT ); Sun, 16 Jul 2017 09:58:01 -0400 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Deepak Rawat" , "Murray McAllister" , "Sinclair Yeh" Date: Sun, 16 Jul 2017 14:56:46 +0100 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 173/178] drm/vmwgfx: Make sure backup_handle is always valid In-Reply-To: X-SA-Exim-Connect-IP: 2a02:8011:400e:2:6f00:88c8:c921:d332 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1547 Lines: 42 3.16.46-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Sinclair Yeh commit 07678eca2cf9c9a18584e546c2b2a0d0c9a3150c upstream. When vmw_gb_surface_define_ioctl() is called with an existing buffer, we end up returning an uninitialized variable in the backup_handle. The fix is to first initialize backup_handle to 0 just to be sure, and second, when a user-provided buffer is found, we will use the req->buffer_handle as the backup_handle. Reported-by: Murray McAllister Signed-off-by: Sinclair Yeh Reviewed-by: Deepak Rawat [bwh: Backported to 3.16: There's no size check after vmw_user_dmabuf_lookup(), so only check ret == 0.] Signed-off-by: Ben Hutchings --- --- a/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c @@ -1245,7 +1245,7 @@ int vmw_gb_surface_define_ioctl(struct d int ret; uint32_t size; const struct svga3d_surface_desc *desc; - uint32_t backup_handle; + uint32_t backup_handle = 0; if (req->mip_levels > DRM_VMW_MAX_MIP_LEVELS) return -EINVAL; @@ -1317,6 +1317,8 @@ int vmw_gb_surface_define_ioctl(struct d ret = vmw_user_dmabuf_lookup(tfile, req->buffer_handle, &res->backup, &user_srf->backup_base); + if (ret == 0) + backup_handle = req->buffer_handle; } else if (req->drm_surface_flags & drm_vmw_surface_flag_create_buffer) ret = vmw_user_dmabuf_alloc(dev_priv, tfile,