From: Sasha Levin <sashal@kernel.org>
To: patches@lists.linux.dev, stable@vger.kernel.org
Cc: Nas Chung <nas.chung@chipsnmedia.com>,
Michael Tretter <m.tretter@pengutronix.de>,
Sebastian Fricke <sebastian.fricke@collabora.com>,
Hans Verkuil <hverkuil@xs4all.nl>,
Sasha Levin <sashal@kernel.org>,
mchehab@kernel.org, linux-media@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH AUTOSEL 5.10 11/34] media: uapi: v4l: Change V4L2_TYPE_IS_CAPTURE condition
Date: Sun, 1 Jun 2025 19:43:35 -0400 [thread overview]
Message-ID: <20250601234359.3518595-11-sashal@kernel.org> (raw)
In-Reply-To: <20250601234359.3518595-1-sashal@kernel.org>
From: Nas Chung <nas.chung@chipsnmedia.com>
[ Upstream commit ad2698efce37e910dcf3c3914263e6cb3e86f8cd ]
Explicitly compare a buffer type only with valid buffer types,
to avoid matching a buffer type outside of the valid buffer type set.
Signed-off-by: Nas Chung <nas.chung@chipsnmedia.com>
Reviewed-by: Michael Tretter <m.tretter@pengutronix.de>
Signed-off-by: Sebastian Fricke <sebastian.fricke@collabora.com>
Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
**YES** This commit should be backported to stable kernel trees based on
the following analysis: ## Code Change Analysis The commit fixes a
logical flaw in the `V4L2_TYPE_IS_CAPTURE` macro in
`include/uapi/linux/videodev2.h`. **Before the patch:** ```c #define
V4L2_TYPE_IS_CAPTURE(type) (!V4L2_TYPE_IS_OUTPUT(type)) ``` **After the
patch:** ```c #define V4L2_TYPE_IS_VALID(type) \ ((type) >=
V4L2_BUF_TYPE_VIDEO_CAPTURE && (type) <= V4L2_BUF_TYPE_META_OUTPUT)
#define V4L2_TYPE_IS_CAPTURE(type) \ (V4L2_TYPE_IS_VALID(type) &&
!V4L2_TYPE_IS_OUTPUT(type)) ``` ## The Bug and Its Impact The original
implementation has a critical flaw: **invalid buffer type values
incorrectly return true for `V4L2_TYPE_IS_CAPTURE`**. Here's why: 1. For
invalid buffer types (e.g., 0, 15, 100, 0x80), `V4L2_TYPE_IS_OUTPUT()`
returns false 2. The negation `!V4L2_TYPE_IS_OUTPUT()` makes these
invalid types appear as "capture" types 3. This can lead to incorrect
code paths being taken in media drivers throughout the kernel ## Why
This Should Be Backported 1. **Affects User-Facing API**: This is a UAPI
header that defines kernel-userspace interface behavior. Incorrect
behavior here can affect any V4L2 application. 2. **Potential
Security/Stability Risk**: The bug could lead to: - Wrong buffer
handling paths in media drivers - Potential out-of-bounds access or
incorrect memory management - Driver state corruption when invalid
buffer types are misclassified 3. **Small, Contained Fix**: The change
is minimal and contained to macro definitions with clear semantics. It
only adds proper validation without changing valid type behavior. 4.
**No Regression Risk**: The fix only affects the handling of invalid
buffer types, making them correctly return false instead of incorrectly
returning true. Valid buffer types retain their existing behavior. 5.
**Wide Impact**: Looking at the kernel tree, `V4L2_TYPE_IS_CAPTURE` is
used extensively in media drivers: -
`/drivers/media/v4l2-core/v4l2-mem2mem.c` - Multiple platform-specific
drivers (Samsung, Mediatek, Verisilicon, etc.) - Any incorrect behavior
propagates to all these drivers 6. **Consistent with Historical
Pattern**: Looking at similar commits like commit 4b837c6d7ee7 ("media:
v4l: uAPI: V4L2_BUF_TYPE_META_OUTPUT is an output buffer type"), UAPI
fixes for buffer type handling have been backported before. ## Backport
Criteria Met - ✅ **Fixes important bugs**: Corrects fundamental macro
logic affecting buffer type validation - ✅ **Minimal risk**: Only adds
validation, doesn't change existing valid behavior - ✅ **Small and
contained**: Changes only macro definitions in header file - ✅ **No
architectural changes**: Pure bug fix without feature additions - ✅
**Affects critical subsystem**: Media/V4L2 is widely used across many
device drivers The fix ensures that only valid buffer types (1-14) can
be classified as capture types, preventing potential mishandling of
invalid values throughout the media subsystem.
include/uapi/linux/videodev2.h | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
index a0671e510bc4a..1ee25344c0760 100644
--- a/include/uapi/linux/videodev2.h
+++ b/include/uapi/linux/videodev2.h
@@ -153,10 +153,18 @@ enum v4l2_buf_type {
V4L2_BUF_TYPE_SDR_OUTPUT = 12,
V4L2_BUF_TYPE_META_CAPTURE = 13,
V4L2_BUF_TYPE_META_OUTPUT = 14,
+ /*
+ * Note: V4L2_TYPE_IS_VALID and V4L2_TYPE_IS_OUTPUT must
+ * be updated if a new type is added.
+ */
/* Deprecated, do not use */
V4L2_BUF_TYPE_PRIVATE = 0x80,
};
+#define V4L2_TYPE_IS_VALID(type) \
+ ((type) >= V4L2_BUF_TYPE_VIDEO_CAPTURE &&\
+ (type) <= V4L2_BUF_TYPE_META_OUTPUT)
+
#define V4L2_TYPE_IS_MULTIPLANAR(type) \
((type) == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE \
|| (type) == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
@@ -170,7 +178,8 @@ enum v4l2_buf_type {
|| (type) == V4L2_BUF_TYPE_SDR_OUTPUT \
|| (type) == V4L2_BUF_TYPE_META_OUTPUT)
-#define V4L2_TYPE_IS_CAPTURE(type) (!V4L2_TYPE_IS_OUTPUT(type))
+#define V4L2_TYPE_IS_CAPTURE(type) \
+ (V4L2_TYPE_IS_VALID(type) && !V4L2_TYPE_IS_OUTPUT(type))
enum v4l2_tuner_type {
V4L2_TUNER_RADIO = 1,
--
2.39.5
next prev parent reply other threads:[~2025-06-01 23:44 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-01 23:43 [PATCH AUTOSEL 5.10 01/34] drm/amdgpu/gfx6: fix CSIB handling Sasha Levin
2025-06-01 23:43 ` [PATCH AUTOSEL 5.10 02/34] sunrpc: update nextcheck time when adding new cache entries Sasha Levin
2025-06-01 23:43 ` [PATCH AUTOSEL 5.10 03/34] drm/bridge: analogix_dp: Add irq flag IRQF_NO_AUTOEN instead of calling disable_irq() Sasha Levin
2025-06-01 23:43 ` [PATCH AUTOSEL 5.10 04/34] exfat: fix double free in delayed_free Sasha Levin
2025-06-01 23:43 ` [PATCH AUTOSEL 5.10 05/34] arm64/cpuinfo: only show one cpu's info in c_show() Sasha Levin
2025-06-01 23:43 ` [PATCH AUTOSEL 5.10 06/34] drm/msm/hdmi: add runtime PM calls to DDC transfer function Sasha Levin
2025-06-01 23:43 ` [PATCH AUTOSEL 5.10 07/34] media: uapi: v4l: Fix V4L2_TYPE_IS_OUTPUT condition Sasha Levin
2025-06-01 23:43 ` [PATCH AUTOSEL 5.10 08/34] drm/amd/display: Add NULL pointer checks in dm_force_atomic_commit() Sasha Levin
2025-06-01 23:43 ` [PATCH AUTOSEL 5.10 09/34] drm/msm/a6xx: Increase HFI response timeout Sasha Levin
2025-06-01 23:43 ` [PATCH AUTOSEL 5.10 10/34] drm/amdgpu/gfx10: fix CSIB handling Sasha Levin
2025-06-01 23:43 ` Sasha Levin [this message]
2025-06-01 23:43 ` [PATCH AUTOSEL 5.10 12/34] drm/amdgpu/gfx7: " Sasha Levin
2025-06-01 23:43 ` [PATCH AUTOSEL 5.10 13/34] ext4: ext4: unify EXT4_EX_NOCACHE|NOFAIL flags in ext4_ext_remove_space() Sasha Levin
2025-06-01 23:43 ` [PATCH AUTOSEL 5.10 14/34] jfs: fix array-index-out-of-bounds read in add_missing_indices Sasha Levin
2025-06-01 23:43 ` [PATCH AUTOSEL 5.10 15/34] media: rkvdec: h264: Use bytesperline and buffer height as virstride Sasha Levin
2025-06-01 23:43 ` [PATCH AUTOSEL 5.10 16/34] media: rkvdec: Initialize the m2m context before the controls Sasha Levin
2025-06-01 23:43 ` [PATCH AUTOSEL 5.10 17/34] sunrpc: fix race in cache cleanup causing stale nextcheck time Sasha Levin
2025-06-01 23:43 ` [PATCH AUTOSEL 5.10 18/34] ext4: prevent stale extent cache entries caused by concurrent get es_cache Sasha Levin
2025-06-01 23:43 ` [PATCH AUTOSEL 5.10 19/34] drm/amdgpu/gfx8: fix CSIB handling Sasha Levin
2025-06-01 23:43 ` [PATCH AUTOSEL 5.10 20/34] drm/amdgpu/gfx9: " Sasha Levin
2025-06-01 23:43 ` [PATCH AUTOSEL 5.10 21/34] jfs: Fix null-ptr-deref in jfs_ioc_trim Sasha Levin
2025-06-01 23:43 ` [PATCH AUTOSEL 5.10 22/34] drm/msm/dpu: don't select single flush for active CTL blocks Sasha Levin
2025-06-01 23:43 ` [PATCH AUTOSEL 5.10 23/34] drm/amdkfd: Set SDMA_RLCx_IB_CNTL/SWITCH_INSIDE_IB Sasha Levin
2025-06-01 23:43 ` [PATCH AUTOSEL 5.10 24/34] media: tc358743: ignore video while HPD is low Sasha Levin
2025-06-01 23:43 ` [PATCH AUTOSEL 5.10 25/34] media: platform: exynos4-is: Add hardware sync wait to fimc_is_hw_change_mode() Sasha Levin
2025-06-01 23:43 ` [PATCH AUTOSEL 5.10 26/34] nios2: force update_mmu_cache on spurious tlb-permission--related pagefaults Sasha Levin
2025-06-01 23:43 ` [PATCH AUTOSEL 5.10 27/34] PM: runtime: fix denying of auto suspend in pm_suspend_timer_fn() Sasha Levin
2025-06-01 23:43 ` [PATCH AUTOSEL 5.10 28/34] thermal/drivers/qcom/tsens: Update conditions to strictly evaluate for IP v2+ Sasha Levin
2025-06-01 23:43 ` [PATCH AUTOSEL 5.10 29/34] clocksource: Fix the CPUs' choice in the watchdog per CPU verification Sasha Levin
2025-06-01 23:43 ` [PATCH AUTOSEL 5.10 30/34] ACPICA: Avoid sequence overread in call to strncmp() Sasha Levin
2025-06-01 23:43 ` [PATCH AUTOSEL 5.10 31/34] ACPICA: utilities: Fix overflow check in vsnprintf() Sasha Levin
2025-06-01 23:43 ` [PATCH AUTOSEL 5.10 32/34] cpufreq: Force sync policy boost with global boost on sysfs update Sasha Levin
2025-06-01 23:43 ` [PATCH AUTOSEL 5.10 33/34] power: supply: bq27xxx: Retrieve again when busy Sasha Levin
2025-06-01 23:43 ` [PATCH AUTOSEL 5.10 34/34] ASoC: tas2770: Power cycle amp on ISENSE/VSENSE change Sasha Levin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250601234359.3518595-11-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=hverkuil@xs4all.nl \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=m.tretter@pengutronix.de \
--cc=mchehab@kernel.org \
--cc=nas.chung@chipsnmedia.com \
--cc=patches@lists.linux.dev \
--cc=sebastian.fricke@collabora.com \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®