From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.173 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796225526; b=AWTbDGxeX+tJujpk5OpPoxtL4LLx9ylmtGpuU/YYIaRkX377mxLck0qAaOkl1vSdPw2T ZtZXkuvtraKmURG5+WWaFqLI6dP3BPAtA0iF0umxcz2krDWyGV8PQEV81jOJZlY2NqZRd 8GafUZeSI4zZplT3Ak1L74Gg52lFOmwav3jrPHrjNsraO1UOUVi8yVJ8dkQlxCFjpwPio U9HRnpXWuYiDScv7dZDeoqm2fkGFN0K0xNEY1E+8pZM4z5f9jbdekn84q5OK6x9AvcCsb ZqxOs+Ak5Afx8ms7BVsbq7l20J6oaJ5rM7yUVS2JRSSx8NcEtOGJipPjZ9BHhorazlg== 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-Forwarded-Encrypted: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=rE7vn112pZAwNf1tA0VZCr1JmLcXYm1rgy7VuAM80ho0miB+jUds0sn2exBklVf6nYeg AKpdkckgR4NVX8wpEvDXnd2UudqiYFz5ZiuclsN/Qq2jIu83S2ENnnXBJ/nIar4/mh35l OyHSOAthSvCl8Y7VQjI+zC5V3vvMul1gf/PbWDg5ufF2InZBOwB0JDlgjri3FgIuxOTTB WnEnD90GHXVnlRl0r9OusHwFflb9WxN4xyjUNHt+eZPXonHMCkDeBLARFyVXcsu2t3MgI lxYTp041EFrT1+UyRghPrsFE9WzW+u7g++q9WJEXp6zsaOWAzobjYzDC8ZC0mL0p5/A== 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.173 Received: from mail-dy1-f173.google.com (mail-dy1-f173.google.com [74.125.82.173]) (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 E9CA8606A31A for ; Wed, 2 Dec 2026 15:32:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E9CA8606A31A 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-f173.google.com with SMTP id 5a478bee46e88-3866a784546so18317132eec.0 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=crUAYFPAYyF9vUopumJMXJcP9dx2HCR4K7aW6FZ2hDus2qtK6mJ04y9LQOLDHKilUw /TfRyIxu4KUlkgbSY/DZ4cWkuYnZ9iYi8F8Ry8JzUKsVK1woV5VpYl45mfEIgRqt2k/3 tntKNp4OHo53aLw9sKkG4BGsutTQ4IyYXTFiJGKDAbbxB9Jq1zryauFjqm+Msh38Ssqz 3qgzlJ4TlD0JeqT9r0I+dyzqFXoxXRBBEQEuEVRGQNk4YgO41RPbWCZRb1wM2eF2rBCH LP2NtxzZpCSUbQWHjhj1jQWdeGtPn+1+U2emY9PdiTPtoMYVpG/+dY2gJdsj+gjVWNhB 5zxQ== X-Forwarded-Encrypted: i=1; AL+hErGAMm7ozernuDHaosbk5CbtEKmb/GgGx+076ufScC1AXdOORtkcQ3O5XJLr4eb6ZzI6Md58mDo217CNkwY=@vger.kernel.org X-Gm-Message-State: APuU4Z/Uzbv8GVEjf5/MeREDWbekcrL7VVNu2IqljrUY1i9ecSSFCjYl qrTz+mG+JQY02Sl9bhykLUXMDRVgBksBMmQK9aETUjW8Qv18NeYkAN6F3fg0xw== X-Gm-Gg: AZFdTZdTJIqTqnTgKT166mhQ3M9wO6wqKBX7NmRFAxqj+c59/umomCs8R7TU7Lrim8K E/M8kLxiQhMJZ/54trbar341rMzUOF20O/VBueqkkg1DvyTbCHSl+Vm4VXinUrXU36PAm3RQNeP 0TVQ7Atzn7KKs13D+w2iwdeXowRS6+N+Pyf9xqenI8s0PmgZcuVkfm7lGSO7xtRzkgupxt+1169 kq8QrtVegIP+uPXqNLQauueIzox5lt4+XnG6Hlt+TK0lizAaQZQ1oSqKltRSr/x07ZDCKhVBAOd 78NkB7IljVEE3eAyNR0WWnf4pE95U1XUU0FMOFJxb7wwrVNFJJu/qwqSqJXbFu5nhyS3E6iLhVJ hm9PLFV3/hNBy1BdSZ1EpJw3wr9wv7OyiANizUgLKSNYA0qGxBYzkwU4qj2DT2Oq6c3OlrbiWnI HkrhYyo0pkFebVwoLbaKmzl88u0RFnjtpfqPms9ps32lYRZIcXMEkjZ6gDodi0xUQqBAEUoYNQa qUSxnwBdzjXzFg0hP2sJSZEr1dQiIFO3fWwk6Sh16qwK8ILYSjMkAj3a5LcpuyIieG7vsgOubGd 3lgVyPhpceryQYpM+STsEawZ0lSkXIyLp8jXTek2d0+F6N8dJ5+oVuU7KgFcWeQ2E155FLwc03G LnVv6WW+P+POYqg== 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-kernel@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