Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796154953; b=xDrnibu/j0SdlP+CXH6joUp5Hv8FnwKznhNeoIiyC6zoLiaD75VE64+fN84NGj1E7jFy sJXLqe/zwfhk2fAO0uH5vYggQoi6KsJEPXJ+Ts/OW5oV8U53NEgbHEanQTUr7mFQ5XLiB wUVBBT6y2vvojjE4+1R0o4KhpcirLMtalPMowV8JnR+XqbbajgvhccqhzGrzUOgtXb2AM t8w7ke6t80Mi28mk4QG8Hqugx8NkBLkH0l35mtgvXax0ABedrBr2EtZn/DqPEVNwM4RSp OQYtMntr0bP1c+Jedm8i1TESl6zTbrj6AfSLR50w/fKPSr6MWHbYVxKmp8mwhh6IBJw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796154953; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=YIEFDrHOMSINFYHNdrKVnvy2WvTwrqNdsI3rx7q0AZY=; b=OmkfPJyBBCtaXbmXKbJAMOYuCdeUjw0jXd5ztOWWZnAzaREUKW9RGkls4g7vFYIG+FA8 2LlkxF/mPvALE0tAy08GxPopGcCUk7HvzgdJgLEOLF5uvrR2/OSJJH6vg+0kcaMtXQjJl MxYzT3U6P+BJIMmb6mom3KLbJqlhos8MRu+oY5YtpkjFAxHYAZBB86h95LPPkIT28itid nukM01uZUjjuod7/+Rj70M+qD7TodtDMCEX451knGReuiIoFvL3UbruHik4YAAaS9VkWy TXc9NhVDaYPG4gF3GZ+5lG83EgkX8OrMw7HGiDqhxY2CxNqiFGPxGblVB16BAPWqehg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=ijIZet67; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (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 EAE55606A31A for ; Tue, 1 Dec 2026 19:55:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=ijIZet67 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 39D8E1F000C1; Tue, 1 Dec 2026 19:55:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796154952; bh=YIEFDrHOMSINFYHNdrKVnvy2WvTwrqNdsI3rx7q0AZY=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=ijIZet67CAU1Miahb44pah0UkNIi2hLnZ3EaZeIiGeZ4VSBH0TbKLwvVKA0E2MTCM oTmoh/prIS7Cvft1P1CPKSEMUHrm+KCXIcPepVRGLBqYgWPhFB01iuK9BT/hAPFIA3 ZMiVn78HCDqMcYjOLau2e6x7xDWIhUeseJ8B6SPmDiL/k0IRhN1VRQZC4CYZ3Alu6Y e0sEpT4p2Iiz3Ci5VD8AceKGnw8yWzUb5DY5QRBYnQ5Slpspetf2WMFJDucb4aaz6d c+G9kOPnHGo0IYNKiEqECOx5xqnaXRn+mOJBTzceGdTecPT0XHNHRzaqUkpaNPeZwj QNhrE2agmgHLw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v13 3/6] media: virtio: Add extended controls support Reply-To: sashiko-reviews@lists.linux.dev To: "Brian Daniels" Cc: virtualization@lists.linux.dev, media-ci@linuxtv.org, "Michael S. Tsirkin" , "Eugenio Perez" In-Reply-To: <20261201192957.790894-4-briandaniels@google.com> References: <20261201192957.790894-1-briandaniels@google.com> <20261201192957.790894-4-briandaniels@google.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Tue, 01 Dec 2026 19:55:51 +0000 X-Mailing-List: virtualization@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 9 potential issues to consider: - [High] media: virtio: extra argument to vb2_destroy_framevec() breaks build - [High] media: virtio: framevecs leak in scatterlist_builder_free_framevecs() - [High] media: virtio: direct scatterlist DMA mapping of stack payloads - [Medium] media: virtio: framevec and pinned page leak on error returns - [Medium] media: virtio: premature count check and OOB read on compat copy - [Medium] media: virtio: SG index passed as descriptor index in ext_ctrls - [Low] media: virtio: gfp_mask=3D0 in __scatterlist_builder_add_userptr() - [Low] media: virtio: wrong function names in framevecs kernel-doc - [Low] media: virtio: __scatterlist_builder_add_userptr() converts -EFAULT to -EINVAL -- commit 4fae9864ea083a1ad259331dd3d9844ea7409d06 Author: Alexandre Courbot media: virtio: Add extended controls support This commit adds support for VIDIOC_G_EXT_CTRLS, VIDIOC_S_EXT_CTRLS, and VIDIOC_TRY_EXT_CTRLS by forwarding extended control arrays and pinned userspace payload scatterlists to the virtio-media host device. [Severity: Low] In drivers/media/virtio/scatterlist_builder.c, inside __scatterlist_builder_add_userptr() (lines 243-245 and 272-278), why does the error path convert -EFAULT from vb2_create_framevec() into -EINVAL? The function's kernel-doc states that it returns -EFAULT when @userptr is not a valid user address, and standard V4L2 extended control handling in v4l2-ctrls-api.c (ptr_to_user() and user_to_new()) returns -EFAULT for invalid control payload pointers. [Severity: Low] In drivers/media/virtio/scatterlist_builder.c, inside __scatterlist_builder_add_userptr() (line 289), should the gfp_mask argument to sg_alloc_table_from_pages() be GFP_KERNEL instead of 0? This runs in sleepable ioctl process context right after vb2_create_framevec(), and passing 0 disables reclaim under memory pressure. [Severity: High] In drivers/media/virtio/scatterlist_builder.c, inside __scatterlist_builder_add_userptr() (line 323) and scatterlist_builder_free_framevecs() (line 444), does passing a second boolean argument to vb2_destroy_framevec() break the build? vb2_destroy_framevec() in include/media/videobuf2-memops.h (line 39) only takes a single struct frame_vector * parameter. In addition, because vb2_destroy_framevec() does not mark pages dirty and user control buffers are pinned with write =3D true, scatterlist_builder_free_framevecs() needs to mark the pages in frame_vector_pages(vec) dirty with set_page_dirty_lock() before unpinning them. [Severity: High] In drivers/media/virtio/scatterlist_builder.c, inside scatterlist_builder_add_ext_ctrls() (lines 368-388) and scatterlist_builder_add_data() (lines 67-118), can passing ctrls and ctrls->controls to scatterlist_builder_add_data() map stack memory directly for DMA when always_use_shadow_buffer is false? video_usercopy() places struct v4l2_ext_controls in its stack-allocated sbuf[], and v4l_g_ctrl() and v4l_s_ctrl() allocate both struct v4l2_ext_controls and struct v4l2_ext_control on the kernel stack. Because stack addresses satisfy virt_addr_valid() (or is_vmalloc_addr() with CONFIG_VMAP_STACK), scatterlist_builder_add_data() maps them directly into builder->descs via sg_set_page() instead of bouncing them through builder->shadow_buffer, violating the DMA API rules against stack DMA. [Severity: High] In drivers/media/virtio/scatterlist_builder.c, inside scatterlist_builder_free_framevecs() (lines 439-451), does the condition guarding kfree(builder->framevecs) leak the array when builder->cur_framevec is 0? scatterlist_builder_allocate_framevecs() (line 418) allocates builder->framevecs whenever builder->num_framevecs > 0, while builder->cur_framevec starts at 0. If an error occurs before the first framevec is pinned (for example, when the first control with ctrl->size > 0 has an invalid user pointer), kfree(builder->framevecs) is skipped and builder->framevecs is reset to NULL. [Severity: Low] In drivers/media/virtio/scatterlist_builder.h, in the kernel-doc for struct scatterlist_builder (lines 28-31), the comment states that @framevecs is allocated in scatterlist_builder_add_ext_ctrls_userptrs() and freed in scatterlist_builder_retrieve_ext_ctrls(), whereas it is actually allocated in scatterlist_builder_allocate_framevecs() and freed in scatterlist_builder_free_framevecs(). [Severity: Medium] In drivers/media/virtio/virtio_media_ioctls.c, inside virtio_media_send_ext_controls_ioctl() (lines 281 and 295-299), does the response descriptor loop pass a builder.sgs[] index to scatterlist_builder_add_descriptor(), which expects a builder.descs[] index? When a vmalloc-backed payload (such as ctrls on a CONFIG_VMAP_STACK stack) spans two non-contiguous physical pages, scatterlist_builder_add_data() consumes multiple builder.descs[] entries for a single builder.sgs[] entry. Iterating i from 1 to end_ctrls_sg (which is builder.cur_sg) and calling scatterlist_builder_add_descriptor(&builder, i) then adds the second page of ctrls to builder.sgs[] a second time and omits ctrls->controls from the response chain. [Severity: Medium] In drivers/media/virtio/virtio_media_ioctls.c, inside virtio_media_send_ext_controls_ioctl() (lines 308-314 and 340-341), and drivers/media/virtio/scatterlist_builder.c, inside scatterlist_builder_retrieve_ext_ctrls() (lines 509-520), can the host bypass the ctrls->count validation or trigger an out-of-bounds read in compat mode? First, ctrls->count is checked against num_ctrls before scatterlist_builder_retrieve_ext_ctrls() copies the shadow buffer back into ctrls, so if ctrls was bounced through session->shadow_buf, scatterlist_builder_retrieve_ext_ctrls() overwrites ctrls->count with the unvalidated value from the device. Second, when ctrls->count > num_ctrls is detected at line 313, ctrls->count is not clamped back to num_ctrls before returning -ENOSPC; because VIDIOC_G_EXT_CTRLS, VIDIOC_S_EXT_CTRLS, and VIDIOC_TRY_EXT_CTRLS have INFO_FL_ALWAYS_COPY set, v4l2_compat_put_array_args() iterates up to ctrls->count even on error and reads past the end of array_buf (which was allocated for num_ctrls elements). [Severity: Medium] In drivers/media/virtio/virtio_media_ioctls.c, inside virtio_media_send_ext_controls_ioctl() (lines 313-314 and 337-338), do the early returns on ctrls->count > num_ctrls (-ENOSPC) and resp_len < sizeof(*ctrls) (-EINVAL) leak builder.framevecs and leave userspace pages permanently pinned? Both paths return directly instead of jumping to free_framevecs (line 343) to call scatterlist_builder_free_framevecs(&builder). --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261201192957.7908= 94-1-briandaniels@google.com?part=3D3