From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 90B4B270545; Thu, 30 Jul 2026 15:41:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785426093; cv=none; b=rGEGP/XlJRr9/T0zEj1k6fV2zkeydu2d2iLS6Pj9GOJ74xzdJ6iudNLiBRmbj6x4Luz+LpEVjg82utBzHygd/ATEI5hGA+hKy+JG5vHFbj0Vfxve/BTHgwgPPUAgEWRCWAQxgepW4oFDhu4sDpHV04AziepoEevMMyO/tP5ZXkA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785426093; c=relaxed/simple; bh=vi9qZyNVgGi0IdgNyeg8WWEMmKUeQBgc7XpdUvyaPB4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=mbS0FC70zWNUz6zTXqOAF8ihKC0xrsByOD6xvmJ94yuIzBsyXLC20dmDI1KCufupunfkDcA8j6hU1O53EFz1q0c3234t89Ck05I2K44FPpYUjvfsbWqw80MspdeEk4DPnOgBIM4WquePVYdOyPKxTvkOPHdIxs7oj9Lbigy4uvc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=VPjKVoL+; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="VPjKVoL+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E55931F000E9; Thu, 30 Jul 2026 15:41:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1785426092; bh=jeUoz+9V12lEXgLxvGnIdIT9neFJAWKTRZ/e6JrZr6o=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=VPjKVoL+rUdPMckWNJRtwD6HwsADJ5DE5QNiCBizXv1fjSjtzyzvUR4E16FukUXD1 zyT9FPq5hIoST2GpAAII97/+6cRYbbCyeCFMuf0NjiWQG1+BlEQrTDrA+41htIr6eC NAiaGqlCRWmriRv7knbKKMaoJUFJRbq5NRCGK0to= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Sashiko , Linmao Li , =?UTF-8?q?Ma=C3=ADra=20Canal?= Subject: [PATCH 6.12 298/602] drm/vc4: Prevent shader BO mappings from becoming writable Date: Thu, 30 Jul 2026 16:11:30 +0200 Message-ID: <20260730141442.233718448@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260730141435.976815864@linuxfoundation.org> References: <20260730141435.976815864@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Linmao Li commit 0c9e6367639548307d3f578f6943ce72c9d39087 upstream. vc4_gem_object_mmap() rejects a writable mapping of a validated shader BO, but leaves VM_MAYWRITE set. Userspace can map the BO read-only and then turn it writable with mprotect(). Validated shader BOs must stay read-only: the validator checks the instructions once and the GPU trusts them afterwards. A writable mapping lets userspace rewrite the code after validation, bypassing the validator. Clear VM_MAYWRITE on the read-only path so the mapping cannot be upgraded, as i915 already does for its read-only objects. Fixes: 463873d57014 ("drm/vc4: Add an API for creating GPU shaders in GEM BOs.") Cc: stable@vger.kernel.org Reported-by: Sashiko Closes: https://lore.kernel.org/dri-devel/20260720085554.B0AF01F000E9@smtp.kernel.org/ Signed-off-by: Linmao Li Link: https://patch.msgid.link/20260721011558.1672477-1-lilinmao@kylinos.cn Reviewed-by: Maíra Canal Signed-off-by: Maíra Canal Signed-off-by: Greg Kroah-Hartman --- drivers/gpu/drm/vc4/vc4_bo.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) --- a/drivers/gpu/drm/vc4/vc4_bo.c +++ b/drivers/gpu/drm/vc4/vc4_bo.c @@ -733,9 +733,13 @@ static int vc4_gem_object_mmap(struct dr { struct vc4_bo *bo = to_vc4_bo(obj); - if (bo->validated_shader && (vma->vm_flags & VM_WRITE)) { - DRM_DEBUG("mmapping of shader BOs for writing not allowed.\n"); - return -EINVAL; + if (bo->validated_shader) { + if (vma->vm_flags & VM_WRITE) { + DRM_DEBUG("mmapping of shader BOs for writing not allowed.\n"); + return -EINVAL; + } + + vm_flags_clear(vma, VM_MAYWRITE); } mutex_lock(&bo->madv_lock);