Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.180 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796225526; b=mH9X2dGeD2kPcM89s2OMXNrue5JTV9ijAZ2jizIYo1KhyS2hdKNmO9B1VRvOUQ+FsojX nHm3t8b91eUcqg0DBhDa6OP9BaqonSqloOYKUkoFM/lbhqR2CTiT+JmT//CNWP04huGKT CNKKLb1tzrXwyrN6Q6NOpebwYHa6OZRvhfg4Dm5XzO9l0OBp5iwBN+PFQLVsOu9WpcmdC ZM17LPSsYtX/YG3Sx7acFFGkVepXppmF7/QKOozYMRDyaAzqvg66lc4CCIg8iUumCfaAc ZdXR+FaAERkfkyso38YZjwJmi8O6HazkfKVy1nnc09paR7JFd087zLxX37e+6FISjcA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796225526; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject: Date:Message-Id:X-Mailer:MIME-Version:Content-Transfer-Encoding; bh=wLlOt5BqAudSBvCLwms4UVeNEtVGtQJzGXsy/KkAsNQ=; b=3r9ZL70i3bWhqGvyKObvisKDMkqN7It/WJZO6YWrrMltiCaG7FkF+uDMHWvleDaBONbK 2khvjTVrTNivWBTi27qUGhh/ssydPW5eVMJy4B38AK9w903lCTkfJse558Rp9z76D2UkW 4gjNcu+71ChfwFOIZ64q/GQiU4OIjwtpZPDjMgrqus+yARmzH1GD33E9D9yELynSm+WcB syYVggKNghi0Qk6lGiP0Sh1mgBrI0cygvb2eR7x4rddPv51MTp2DJA48p74cTemkXh7aS F3oYaK13TvBKUNcMd8IcLFimjfXs0Ybzj5g7kdetJFFWHz3yjtkG85GSsmkZpDIlrCQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b="g+dp/QUl"; arc=none smtp.remote-ip=74.125.82.180 Received: from mail-dy1-f180.google.com (mail-dy1-f180.google.com [74.125.82.180]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F1054606A322 for ; Wed, 2 Dec 2026 15:32:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org F1054606A322 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.a=rsa-sha256 header.s=20260707 header.b=g+dp/QUl Received: by mail-dy1-f180.google.com with SMTP id 5a478bee46e88-386ab9ab619so19991539eec.1 for ; Wed, 02 Dec 2026 07:32:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796225525; x=1796830325; 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=wLlOt5BqAudSBvCLwms4UVeNEtVGtQJzGXsy/KkAsNQ=; b=g+dp/QUlXYqCGFGm6gPKQ4nVC9oTMYuwIin2lcvQF4EsnyahCHCfXEXsE0Rmx5NiQg AY/sMcBjStf6G6N40rHDfRx4PGY6z0IB/OQRBDYLYg5hG6Uk2wnuY2SpbsOG6/Shz4je vprBUF4J02+LCe4SUb4vTGTfYitbqZedNbhRVsB/4qSdzcBgIR5zKDPqD+eXH6t2FkcH s0kkFIdUK90NvgF5Tn0Oco/nFRKga02KxwPY45KRTzcjlehd9zaPlzLhWcRNtOQFkd6G nDerg6cSpYT9VMDm1kdpH7LUjb77kKP+N06vBXI1JEpOK1q85PwxSyuqHCW2p5PshD2A YzSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796225525; x=1796830325; 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=wLlOt5BqAudSBvCLwms4UVeNEtVGtQJzGXsy/KkAsNQ=; b=WQOnxc8o3WhdjCclXG5F2IOKTPkl9ZiR+UXJr4TQKUeiY+nQ5lQQK+bdbJU/xv7ONh sjrDfgIVD+hV+ET8XBxNBwFsdlUkhgKErpjtjCLaetV2SuvYmRKzZ6+CAFBif8+EDpk9 1yMBw1pCuPYKO7ygOKj8oGhKoPMGCPZyR2JEhnYrxVwQxFEMIEy+0IB4vNzA3yHjED5v y+g7qG3MUyWSttTT6htaefQPAOx0Dac9cx5gH9ipOSaPIr/yE2qr8bO07WNxEAleV/iV YMDfLObryZO1QP0gkJDtvUXdMrLmUUAxExKK6cj26s7YQGws3Vbf5h6+hKwol/Nz5K2+ n+Wg== X-Gm-Message-State: APuU4Z/DLUnvNwdsdRMe/okmtbASr/jBctIW7PGCVnMz58RmjGLl3o6q yUCFqNYx+X6tbAs0Cpej4nkrcZR5am12srr1kuw2/lEjxjJzfDWJk2Mo X-Gm-Gg: AZFdTZdAI+hP0hl4g7QiTvZrtMdCbgqepkyk9qP//l25+ltMCDStAvNMv8KnIuWVebG okPov2j15tjebZO1Qka0Qdwp/5XdXBsm/3pwUBEAbb0NVxZXZEdN0udF+TEscdpITPRZvRhVN3u bBBynBY5sz/ktl6pR+07JOo5opJJtGsBP8zyGYDQxsWpSaoYBgbd08/iRiaXitrnrDN2V2EpWG8 bN5gknF57AH2oix6ooLZ4Pe4eIE5XMidi3OJYOk22g23G33sIA/ExM2+YTAXmmAyft/JLu+lUzn L81CvWb09zKtX17JGfMt/eNbD85h+GKnX7dUGg2c/f1wxxD+iSP27eyHCeOGM14j+kxdC1bHWaU vVn5bnU39OwEw59mcQ3ejQTAru2AIRESX8cEkswhzpTdSYdkzIjq97b8Aqr4lQ8yGghxdCJxOj0 0AEdXV11MfsVTj5sRogAkV6n9umlVA+lUES2PftpEEynO/N/8pHnEIJy+umlHokH7ziybmkATQB QPUrDi2QmfahUSeeBoEzoSXY3iTYXFm8xwNIIATOPMIGGo5xF1wxSKcixX/wV5FU0E14T4XeAx/ 4iG4QKYTlEws3pQSywBGWBRjFvM3dYoXLphWQkvw2OmI+IS4XDtEXy0MF9I0pRSO8CegJGLfpUy sD4XZFBzI+AuDZQ== X-Received: by 2002:a05:693c:60d4:b0:369:fe81:a575 with SMTP id 5a478bee46e88-3857111f203mr49152198eec.35.1796225524324; Wed, 02 Dec 2026 07:32:04 -0800 (PST) Received: from hyeonjun-ThinkPad-X13-Gen-1.. ([124.197.199.8]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-385666e7fc3sm106507398eec.8.2026.12.02.07.32.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2026 07:32:03 -0800 (PST) From: Hyeonjun Hong To: Jacopo Mondi , Jai Luthra , =?UTF-8?q?Niklas=20S=C3=B6derlund?= , Mauro Carvalho Chehab Cc: linux-media@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH] media: rppx1: Validate and process a copy of the parameters buffer Date: Thu, 3 Dec 2026 00:31:37 +0900 Message-Id: <20261202153137.701735-1-hyeonjunhong330@gmail.com> X-Mailer: git-send-email 2.34.1 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-Transfer-Encoding: 8bit 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. 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