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 843D5446073; Thu, 30 Jul 2026 16:09:01 +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=1785427742; cv=none; b=W10qhydfaRvXXkVQ9S6+HaT+zCGvK4sptSRu+qwexZS3gvNa6dYJMG5szJLHVsOz3Yu1uhl9kk9I/KNI0sBzmBHCDGcQ+qruZsymRdYqPhb0xKpZcsvV+FgZMpaS82OE+9c8K9HBTrzjWdhm5rYCCMJka+2xY1GRUZiIYzNntmM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785427742; c=relaxed/simple; bh=eAZsHBBdOkgWN0mDD7dn9tKbIqKNWK9jCsGWtEF1o00=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=oIG6ANTYzJyAQcDbg12JfDTiXrT0e8TAJhy8m+dKt0l+NVsXCQjgNxqpFfmsQkShXAPYJXkXuVz/4xITpQKlj/goLyPv2UlwfK78LVhCnDhHcLcSxNQ+0+pmTmM9GJgxNDVV26sCtA/Xht5LZtqAuJZjdHSfdDDFEhEUG1fyy+4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=eavsMIuT; 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="eavsMIuT" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D39041F000E9; Thu, 30 Jul 2026 16:09:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1785427741; bh=rNveJAYo6Sxwdwn21dwc4ml4wXnoUhN0J+h5r1QGH8w=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=eavsMIuTJgA3bu5DOiR96BKq2U7RnjHAeokihS6YZhZw9SGPnghNKRbWT9kj/UCnK mkPGcYFdt+UPEVTYdHVhtgf7oq296GMf34FSRA0euCRLasDisOMTya+m4C2V/Ld2LL 36GzVcJnR3lSB1Z38+xzvGYryVvO5JArxX7mHX20= 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.6 233/484] drm/vc4: Prevent shader BO mappings from becoming writable Date: Thu, 30 Jul 2026 16:12:10 +0200 Message-ID: <20260730141428.540948193@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260730141423.392222816@linuxfoundation.org> References: <20260730141423.392222816@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.6-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);