From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C5EE73161BE for ; Sat, 8 Aug 2026 23:10:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786230613; cv=none; b=JrhYnP4JFXAlkIK6Ak+P+NlVXsSVwKDPLrQtwfDTGiooGNLo8wHwLzEXKVgvbC8+dSdM8tu6pnHx9lKJJUwPHJb2tqTv00/JDaSfubL8RxxRcXld3650Yx2+wcHne0H0OT6EDqlD5KaBk6Paq+fnTerjc2FIwpjH0PgfGP6T8sY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786230613; c=relaxed/simple; bh=5iFuTwfPnYb+5fSE/gb8+fL3OUPljI+oXH51/CuZLB4=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=jy76ve29LPe8iXcl3mmICUuN/8qwUt9ku5sRY73JWlEFCZkeRCNjN5HZTK6AYbSOLXhL+yI2kqNZvME1ooUSzPeGZepalXcTUGCiH5RbiFVl0UKRUyVq7JCrYp99fHltl57bX4fnDN9SIT6o9DEQhTOQkLPDyLv5Y8cAc3FSJ8c= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=M9Y3XgEu; arc=none smtp.client-ip=209.85.216.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="M9Y3XgEu" Received: by mail-pj1-f41.google.com with SMTP id 98e67ed59e1d1-383b4a3755fso745487a91.3 for ; Sat, 08 Aug 2026 16:10:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786230611; x=1786835411; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=BE5i97l5+UkocwDHkAbi6GQw7M6Leoq3/Bn3JNcvt7I=; b=M9Y3XgEuJnpoWpB8/T3FC8072vkPsyKw1/ReH4fkpCezGjjndtYAa3s7/BZNcmtIMZ i4kV9hbiW+dFLHzJ2ybiCVQ5R/PnTVd5viLYHpyfQh3q7dvLm3KBqTwsbjtNe9nViSJ1 L7LHKDfD1k9Fujc0L2KXs6cNvwB7R4WRq1+iFJbLoPFT2T+bwqS702pKJDe3YsgjqTIf BD9FURegvYtZBjqJDNoCsd2EiFkQ9X41f7pdUdN+O2NBMXSBf3DBWLDDzyXhooax95Nm pHN8Abq7MMqnoGez/g2bIbN4dL+pkMIrxuFPwACm1hZrs67zbapvfWg7AfvcePK7U1sK X/cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786230611; x=1786835411; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=BE5i97l5+UkocwDHkAbi6GQw7M6Leoq3/Bn3JNcvt7I=; b=Nh7f0ZGE7aadh20BIvJ3ABjFTg+qq08L1JV2oGvOBg553S5n60liYs6qYhZeNIxL5B 2sZRo/2O20q/X9EppH41vckNwtAbWyMAzlZyYzrPZlxkef2pP3uigjzuzcnn597/FIwu M0R11AboX2Ctr4BuXakHhHDrEamwa+7gFhc4smpEecSEeb+LXh37d0a+AZWJciM1XgdS 8nVMRHwj/3FhlO7/tR0xs6nAwacOE/xessx6N4otfiwdl7SKllYCEYEwyJR9fEezi1FX QnVNUwJFyvxOp4arP0W3bEzdLFSM/8wR5TC7tuWAWVkSsyHu58nItt7omo9rB/Oh/1vI zXAQ== X-Forwarded-Encrypted: i=1; AHgh+Rra+MTOezTpd0z8LZamKJV/FdPk4G4nqYPRwAzON5lq4/Dd/UG1MD/9BCUhMrIAPvYm7aRWS/naPeOTUog=@vger.kernel.org X-Gm-Message-State: AOJu0Ywmq8p/U89AJCFOKInGDYpODGs2K1/SJJGRhmGZTOjA8VTZXS07 Bc/ZuQ18L3qfJcXFzIMynOfdF2HUZ/CGESxcecFwTnU+ahUhMXZdPitl X-Gm-Gg: AR+sD10YzHUDjvYoGzYiBhwrHDtWljOZWq328EkVpaNyBbOjDvZDv5KekFeCKurmWz5 iPHmilFYs4zW4hAcP1nCi7gc1efPEG6XOD/T9RrVCyKyFFp8sp5ihwdxaVNkAIlFw+TgqYQ6JrZ BHj2lmix19iJPLKHn6FtrycI9WmehNZTA1QIe455eunHmUliN53lTUYoGzm7q71hV1tesELpoUm HdSZ5ko5hDaEG3gs8ZsNxTeKhUfeQev02GJrXT7tzT3ToPmmGeStHc8eVEKVJb3u5tZYUlOtzCI yamE2KR8OC/82GoNyrNDKgS5kjlnsqbEg1ektDfspcCnCpexFSs36BXs7IHd8r08f54abDDiZvR lxemPfkBQbbt9Ee6t+H20RXiI51+KxODbh6HmoESvkvBIAjmGzNGcvUBupV7j2pg08efbxEqbNk JCTbtEJk4s6KyLrLLbHamxjsafRd6iNMA5n/Ah5L+XDa+71sEJNz7H X-Received: by 2002:a17:90b:51ca:b0:38e:6c37:d95a with SMTP id 98e67ed59e1d1-39262305b87mr14578046a91.19.1786230611047; Sat, 08 Aug 2026 16:10:11 -0700 (PDT) Received: from beelink.. ([186.22.57.86]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-141019b4eabsm19551087c88.6.2026.08.08.16.10.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Aug 2026 16:10:09 -0700 (PDT) From: Aldo Ariel Panzardo To: Zack Rusin Cc: Broadcom internal kernel review list , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Aldo Ariel Panzardo Subject: [PATCH] drm/vmwgfx: return an error when a shared GB surface has no backup buffer Date: Sat, 8 Aug 2026 20:10:02 -0300 Message-ID: <20260808231002.67559-1-qwe.aldo@gmail.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit vmw_gb_surface_reference_internal() rejects a surface without a backup buffer by logging an error and jumping to the exit label, but it never sets ret on that path: ret = vmw_surface_handle_reference(dev_priv, file_priv, req->sid, req->handle_type, &base); if (unlikely(ret != 0)) return ret; ... if (!srf->res.guest_memory_bo) { DRM_ERROR("Shared GB surface is missing a backup buffer.\n"); goto out_bad_resource; } ... out_bad_resource: ttm_base_object_unref(&base); return ret; ret is still 0 from the successful vmw_surface_handle_reference() above, so the function returns success while leaving *rep completely unwritten. The other goto to the same label is inside an if (ret != 0) block and so carries a real error; this one is the only path that reaches the label with ret == 0. The caller then copies that untouched output structure to user space. For DRM_VMW_GB_SURFACE_REF, vmw_gb_surface_reference_ioctl() passes a stack local: struct drm_vmw_gb_surface_ref_ext_rep rep_ext; int ret; ret = vmw_gb_surface_reference_internal(dev, req, &rep_ext, file_priv); if (unlikely(ret != 0)) return ret; rep->creq = rep_ext.creq.base; rep->crep = rep_ext.crep; so 48 + 24 = 72 bytes of an uninitialised stack variable are copied into the ioctl buffer, and drm_ioctl() copies that buffer back out. The ioctl is a DRM_IOWR of exactly 72 bytes, so in_size == out_size and the core does not zero any tail. DRM_VMW_GB_SURFACE_REF is DRM_RENDER_ALLOW, so this is reachable by an unprivileged local user through a render node. What actually leaks depends on how the kernel was built. With CONFIG_INIT_STACK_ALL_ZERO, which is the Kconfig default whenever the compiler supports it and therefore what the major distributions ship, rep_ext is zeroed on function entry and user space receives 72 zero bytes. With CONFIG_INIT_STACK_NONE the contents are whatever the previous call at that stack depth left behind; on a test kernel built that way, 53 of the 72 bytes came back non-zero and several of them were kernel pointers. So the information disclosure is configuration dependent, but the control flow defect is not: on every configuration the ioctl reports success and hands back a reply that was never produced, which user space cannot distinguish from a real one. The path was correct when the ioctl was introduced in a97e21923b42 ("drm/vmwgfx: Hook up guest-backed surfaces"): ret was initialised to -EINVAL and the first assignment to it came after this goto, so the label really did return -EINVAL. 14b1c33e8429 split the handler into vmw_gb_surface_reference_internal() and moved the vmw_surface_handle_reference() call - and with it the first assignment to ret - above the check, which left the initialiser dead and this path returning 0. The dead initialiser was removed later, as a Coverity "unused value", by c594285f30fa ("drm/vmwgfx: remove redundant assignment to variable ret"); that removal was correct in itself. The driver already knows the request failed - it logs an error - so report that to the caller. Fixes: 14b1c33e8429 ("drm/vmwgfx: Add new ioctl for GB surface create and reference") Cc: stable@vger.kernel.org Signed-off-by: Aldo Ariel Panzardo --- drivers/gpu/drm/vmwgfx/vmwgfx_surface.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c b/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c --- a/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c @@ -1720,6 +1720,7 @@ vmw_gb_surface_reference_internal(struct drm_device *dev, srf = &user_srf->srf; if (!srf->res.guest_memory_bo) { DRM_ERROR("Shared GB surface is missing a backup buffer.\n"); + ret = -EINVAL; goto out_bad_resource; } metadata = &srf->metadata;