From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=103.168.172.144 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796227976; b=Yb1bJM/QoAkG/Y7FJkWX+o27E1QSHdge0kkxKyO2v2yBkwwnvoGzUo/v9UIwaFZSCmjK 3enbshknpJrSAYobyrGo+P+D8Iisw7Uc6oILhc6lzhN5p2A42QLl9GrcVSRVrRRMysfwL Mxng5qUqSABcoRMViIXGX6XqWe9djFMw4XinWtWJP8AcXNR3XtBjqtUV52p7qW0HfyWMX hitkyaVINf0bRBbj2oaY9Jd1luJygImiyz2qAUid1zeC3498wy1DGNyOxyespHXhL4Lrj yOInW5YZ0ZR+QKWKAbp4YM103JVYXrhhfoKwLRYhqHVuw1pWYyXHH8+GAAWx4hskWeQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796227976; h=DMARC-Filter:Received:Received:DKIM-Signature:DKIM-Signature: X-DKIM2-Info:DKIM2-Signature:X-DKIM2-Info:Message-Instance: X-ME-Sender:X-ME-Received:X-ME-Proxy-Cause:X-ME-Proxy:Feedback-ID: Received:Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:Content-Transfer-Encoding: In-Reply-To; bh=TLivhJpbftO/PPWyuwyUJSk0UMDBdZwNL0m4rCEh528=; b=m+kCxX88uxeskzDZfaILme/ESRxXhkTRBjqSNuYhu/SElV9ySGspLvTX0C7slieQJPbT 2bZTTv7Qv1lY/kLhlc0kEJk5LJRGz2ijpLZwj+BRdtX7WpmgTyVvsxPN9xG550gs8LzRM SDBoiD6nXCDOlzaryV7ktDyrTv3D/eTvdFK8sTsyklyx31Wm0EvGnqxXw6CNt2OPdZTIf 4p2eJXDdeo1I8pUjf0aS4Z4Z1axVKZyGFVJXLRQmNJbLynTFjVjye4JPURSGcipVg464F yxRFk+0DkY937lQKakxHHwe4kxgS299gEvLsgE5E8Pu6x3Y3HuFv0Foa4+qnr6RQeDA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=ragnatech.se; spf=pass smtp.mailfrom=ragnatech.se; dkim=pass header.d=ragnatech.se header.i=@ragnatech.se header.a=rsa-sha256 header.s=fm2 header.b=DQzHdMNF; dkim=pass header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=enngiYI9; arc=none smtp.remote-ip=103.168.172.144 Received: from fout-a1-smtp.messagingengine.com (fout-a1-smtp.messagingengine.com [103.168.172.144]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AC0FB606A322 for ; Wed, 2 Dec 2026 16:12:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org AC0FB606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ragnatech.se Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ragnatech.se Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=ragnatech.se header.i=@ragnatech.se header.a=rsa-sha256 header.s=fm2 header.b=DQzHdMNF; dkim=pass (2048-bit key, unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=enngiYI9 Received: from phl-compute-01.internal (phl-compute-01.internal [10.202.2.41]) by mailfout.phl.internal (Postfix) with ESMTP id A39D7EC1148 for ; Wed, 2 Dec 2026 11:12:54 -0500 (EST) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-01.internal (MEProxy); Wed, 02 Dec 2026 11:12:54 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ragnatech.se; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm2; t=1796227974; x=1796314374; bh=TLivhJpbftO/PPWyuwyUJSk0UMDBdZwNL0m4rCEh528=; b= DQzHdMNFzTIf5+BU1wrMRr8IXzcRLzgsdUAMdatVVRlHORkG+S5D2IWdaT0jfiVz J3pDgM7GcR4R19l2/LnZSO2nfUlUWb0kmn74IAJBEkiEyOGJ0J/M+Gnr37m/q/yj kCeDsGn9kMFUf41/fMeszOk86W7ayrD9UbK9Yh9X5b6SJ7AETj+3ugqsi6tWwzEP voyqYOqJn96ga4MKwllcQ+Jq5ViSdG4dY701+JzUdeW3+7yzP1okPlcfFrtnDVB6 n1rYx+Y6acJONnnhaRcj4d0pmvFwwXZRjul9oajIhAHkvraXeACSdxujA6ydO26G HMXRz/kT9SViOoF8NeKeiA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1796227974; x= 1796314374; bh=TLivhJpbftO/PPWyuwyUJSk0UMDBdZwNL0m4rCEh528=; b=e nngiYI95Obd2WT2PKsMyoWZiBTxSJHlQu39K7elZHkUxhcCZGpNEXQICCGGoBDum xqKip/bex7nNvhMUFCRFg+PHlWyxV9qaLGrfe/f7cY90crTc4MdIaKrlpXHtsUVO WiVZOgEDqfIPCBU5vNhdZYTuhpxI2fGaLIRDEIgxT1WuTfmpbEFErbEHbUmvSjdG a06efEPOZNTkx42vH8KpA6e7RhUkz9lvwvhKSKdA275kP0rdefACSTD1DOrYptXP WfHe5m01gZnh99BgfYbvmOZjpxrslvcpvvmzXlHoMFwbiAYzUbxqVzbN25DwEoCg WQi7xy2vYqdtylU0ScizQ== X-DKIM2-Info: draft=ietf-dkim-dkim2-spec-09; repo=github.com/dkim2wg/interop; date=2026-11-03; sw=lmtpprox; action=sign d=ragnatech.se a=rsa-sha256; DKIM2-Signature: i=1; m=1; t=1796227974; d=ragnatech.se; mf=PG5pa2xhcy5zb2Rlcmx1bmRAcmFnbmF0ZWNoLnNlPg==; rt=PGxpbnV4LW1lZGlhQHZnZXIua2VybmVsLm9yZz4=; s=fm2:rsa-sha256:nchFFp0WmreQn+DjTo2dwzaLGCeaVDMdoK50ByC6JaRVwY1 dL556+w9JXDfmQd0mNvU9EebPQ8s/Gv0xT/d4ZezdHoYbjpJ3ncqdkDCtqtfmxq5 +PDklE77CtKhvQYK4aW90+UQ8dqXMAWWE2NX0QbFioSC4UfuHje157Dtumxe4iiY CW0cbkvpF0hdX4h9+OQMsN+fu2+yi4a/5FkCHDrkwRSw8e/Wgk0Pk+MQncADvheD mXh0oNvNRuxEbpjROOWUNpRvRyHQP26HSFo5js0OO42j/ktokcIzif0uyeAVxOVg 6rwGxmtivZ6RIA2MpmGmxNyG0w7PvYuhHR2aJBw==; X-DKIM2-Info: draft=ietf-dkim-dkim2-spec-09; repo=github.com/dkim2wg/interop; date=2026-11-03; sw=lmtpprox; action=mi-m=1; hc=13; hn=cc,content-disposition,content-transfer-encoding, content-type,date,feedback-id,from,in-reply-to,message-id, mime-version,references,subject,to; Message-Instance: m=1; h=sha256:YSE23UA20PmVl2hDu7AyrAa5refUF8UFKEIKeafGvcA=:+g3JP8zpc1AinZM4mfTPs/UQFi8UVhLXeXl4nkt2zyI=; X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTEMRn4V6wBvdbSCSo8AB6bx0YUIWgKA+lSYCs6mUXYfdV/xKf46L5Kcxf6HCvrFIY 84VHQIkz+pDxM73fRZ2EVNMpdMHDBN4okks59e81MjcaNyAx2e661wRMVeyvS5T+rvywpv C4z+DAjZN8FhsUCwS4z5DNVtxfIUXz9BP63iDPyDj4PRosIDGqdIg/9V4tNa1HP13+4jnE JWMbYn37EPsv7Ez0LuHaai5Gn2lVlnVHOQRUPZ5ABN/rR7BrzB8HZ29gmOEXi1xqgY1sUS rw0BfbLp+gj1wSC8RY30Z6eeR7AtQjqBijIGzEWY5QYLFWBkmrs8dpkow/H0zmlFUdyOEG W4vNiAwVrQ7HFG3FcHsKT3RukYMcB59OjlQ9L+7J+KouxookC5fNJAtjdZ4vfLqzx06YEH em4AiFkM6pLNaVu2PA+MdUBMOqVUWTEm5pMQeroWoMYkUlAHFYq3YB8tRIOWEgEWx0LXZE WdsRqfaZug5FyuO28WEFLpNg/Bnuxu/T/1TyzTtYJnZyTTCEWYFPsdpmjgNPJwq9tJabTG sB6OtqnsEqLG1qUBq6Sx8SrZgspKzk9qP3HLl2NnbEBntlO0nw67h8+MDaXR06uAX8lOUd Li3+BfZBjfWcDAH/wrF+EPnrt6jIxLKoSS5VrnvwfsOHeJbLnjn2EKrmw26A X-ME-Proxy: Feedback-ID: i80c9496c:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 2 Dec 2026 11:12:53 -0500 (EST) Date: Wed, 2 Dec 2026 17:12:51 +0100 From: Niklas =?utf-8?Q?S=C3=B6derlund?= To: Hyeonjun Hong Cc: Jacopo Mondi , Jai Luthra , Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH] media: rppx1: Validate and process a copy of the parameters buffer Message-ID: <20261202161251.GF3157946@ragnatech.se> References: <20261202153137.701735-1-hyeonjunhong330@gmail.com> X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20261202153137.701735-1-hyeonjunhong330@gmail.com> Hi Hyeonjun, Thanks for your work. On 2026-12-03 00:31:37 +0900, Hyeonjun Hong wrote: > rppx1_params() validates the parameters buffer in place and then walks > it again to process the blocks. The buffer comes from a vb2 queue that > supports VB2_MMAP and VB2_DMABUF, so userspace can keep a mapping and > modify the content while the driver is using it. > > Everything that was validated can therefore change before it is used. > The loop in rppx1_params() reads data_size again on each iteration and > advances by a header.size that it reads again, so a larger data_size > makes the driver read past the end of the buffer, and a header.size of > 0 in a block that is not handled keeps the loop from advancing. > v4l2_isp_params_validate_buffer() itself reads data_size more than once. > > The other users of the v4l2-isp helpers, rkisp1, mali-c55 and c3-isp, > copy the buffer first and only use the copy. Do the same here. Can't this be fixed in the v4l2-isp helpers instead of fixing every user? > > Fixes: b562e72bdb98 ("media: rppx1: Add framework to support Dreamchip RPPX1 ISP") > Cc: stable@vger.kernel.org > Signed-off-by: Hyeonjun Hong > --- > How this was found and tested: > > - Found by comparing the callers of the v4l2-isp helpers, with the help > of an LLM (Claude). Same review pass as > https://lore.kernel.org/all/20261202151718.694973-1-hyeonjunhong330@gmail.com/ > but independent of that series. > - I do not have R-Car hardware. Tested only in a userspace model that > compiles the unmodified function bodies of rppx1_params() and the > v4l2-isp validation helpers with AddressSanitizer, while a second > thread flips data_size in the shared buffer. > Before: heap-buffer-overflow READ of size 2 right after the buffer, > in v4l2_isp_params_validate_buffer(), within the first second. I > could only reproduce it at -O0; at -O1 the compiler merges the reads. > I have not checked how many reads the arm64 kernel build ends up > with. > After: 400 million iterations without a report. > - Compile tested for arm64 with W=1. > - Not tested on hardware. > > This conflicts with "[PATCH 0/7] Introduce v4l2-isp reset buffers", > which changes the same function. I can rebase on top of it if that > series goes in first. > > The copy is allocated per call to keep the fix local to rppx1_params(). > The other drivers allocate it once in buf_init; that would need a > change in how rcar-isp and rppx1 share the buffer, which I can do in a > follow-up if preferred. > > .../platform/dreamchip/rppx1/rpp_params.c | 21 ++++++++++++++----- > 1 file changed, 16 insertions(+), 5 deletions(-) > > diff --git a/drivers/media/platform/dreamchip/rppx1/rpp_params.c b/drivers/media/platform/dreamchip/rppx1/rpp_params.c > index 44b0c2e673b7..241b92366a9d 100644 > --- a/drivers/media/platform/dreamchip/rppx1/rpp_params.c > +++ b/drivers/media/platform/dreamchip/rppx1/rpp_params.c > @@ -5,6 +5,8 @@ > * Copyright (C) 2026 Ragnatech AB > */ > > +#include > + > #include > #include > > @@ -49,13 +51,20 @@ int rppx1_params(struct rppx1 *rpp, struct vb2_buffer *vb, size_t max_size, > if (ret) > return ret; > > - cfg = vb2_plane_vaddr(&vbuf->vb2_buf, 0); > + /* > + * The buffer is shared with userspace, which can modify its content > + * at any time. Validate and process a copy. > + */ > + cfg = kmemdup(vb2_plane_vaddr(&vbuf->vb2_buf, 0), > + vb2_get_plane_payload(vb, 0), GFP_KERNEL); > + if (!cfg) > + return -ENOMEM; > > ret = v4l2_isp_params_validate_buffer(rpp->dev, vb, cfg, > rppx1_ext_params_blocks_info, > ARRAY_SIZE(rppx1_ext_params_blocks_info)); > if (ret) > - return ret; > + goto out_free; > > /* Walk the list of parameter blocks and process them. */ > block_offset = 0; > @@ -63,7 +72,6 @@ int rppx1_params(struct rppx1 *rpp, struct vb2_buffer *vb, size_t max_size, > const union rppx1_params_block *block = > (const union rppx1_params_block *)&cfg->data[block_offset]; > struct rpp_module *module; > - int ret; > > block_offset += block->header.size; > > @@ -107,13 +115,16 @@ int rppx1_params(struct rppx1 *rpp, struct vb2_buffer *vb, size_t max_size, > dev_err(rpp->dev, > "Error processing RPPX1 block type: 0x%04x\n", > block->header.type); > - return ret; > + goto out_free; > } > } > > /* Trigger update of shadowed registers after frame is done. */ > write(priv, RPPX1_RPP_HDR_UPD_REG, RPPX1_RPP_HDR_UPD_REGS_GEN_CFG_UPD); > > - return 0; > +out_free: > + kfree(cfg); > + > + return ret; > } > EXPORT_SYMBOL_GPL(rppx1_params); > > base-commit: 62dfd7c0e599b6f02392b117ee77a070796ad765 > -- > 2.34.1 > -- Kind Regards, Niklas Söderlund