Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Sofus Forstreuter" <sofus.c@icloud.com>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org,
	media-ci@linuxtv.org
Subject: Re: [PATCH v4 17/17] arm64: dts: apple: t6031: add avd nodes
Date: Sat, 28 Nov 2026 22:42:37 +0000	[thread overview]
Message-ID: <sashiko-outbox-239115@kernel.org> (raw)
In-Reply-To: <20261128-avd-v4-17-35ad7d52c842@icloud.com>

Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [Critical] media: apple: avd: out-of-bounds access in
  compute_tile_ids() on HEVC controls
- [High] media: apple: avd: missing dimension checks in
  avd_av1_set_prob() and calc_upscale()
- [Low] arm64: dts: apple: undocumented apple,t6031-dart compatible in
  iommu@2cd010000
- [Low] arm64: dts: apple: unpermitted dma-coherent property on
  video-codec@2cd070000
--

commit 3f6c99ab9326c07d26df77a52366b9ba23343102
Author: Sofus Forstreuter <sofus.c@icloud.com>

arm64: dts: apple: t6031: add avd nodes

This commit adds the Apple Video Decoder (AVD) and its corresponding DART
IOMMU nodes to the T6031 per-die devicetree include file.

> diff --git a/arch/arm64/boot/dts/apple/t6031-dieX.dtsi b/arch/arm64/boot/dts/apple/t6031-dieX.dtsi
> index 1624651c1d92c..4fc6d1575b761 100644
> --- a/arch/arm64/boot/dts/apple/t6031-dieX.dtsi
> +++ b/arch/arm64/boot/dts/apple/t6031-dieX.dtsi
> @@ -101,6 +101,39 @@ DIE_NODE(pinctrl_ap): pinctrl@2b3000000 {
>  		apple,npins = <200>;
>  	};
>  
> +	DIE_NODE(avd_dart): iommu@2cd010000 {
> +		compatible = "apple,t6031-dart", "apple,t8110-dart";

[Severity: Low]
Does apple,t6031-dart need to be documented in
Documentation/devicetree/bindings/iommu/apple,dart.yaml first? Without an
entry in the binding schema, dtbs_check fails on T6031, T6032, and T6034
device trees.

> +		reg = <0x2 0xcd010000 0x0 0x4000>;
> +		interrupt-parent = <&aic>;
> +		interrupts = <AIC_IRQ DIE_NO 1192 IRQ_TYPE_LEVEL_HIGH>;
> +		#iommu-cells = <1>;
> +		power-domains = <&DIE_NODE(ps_avd_sys)>;
> +	};
> +
> +	video-codec@2cd070000 {
> +		compatible = "apple,t6031-avd", "apple,t8122-avd";

[Severity: Critical]
Can enabling the AVD driver on T6031 allow unprivileged userspace with
access to /dev/video* to trigger heap out-of-bounds reads and writes in
compute_tile_ids() via crafted V4L2_CID_STATELESS_HEVC_SPS and
V4L2_CID_STATELESS_HEVC_PPS controls?

drivers/media/platform/apple/avd/avd-hevc.c:compute_tiles_non_uniform() {
	for (i = 0; i < num_cols - 1; i++) {
		column_width[i] = pps->column_width_minus1[i] + 1;
		sum += column_width[i];
	}
	column_width[i] = pic_in_cts_width - sum;

	for (i = 0, sum = 0; i < num_rows - 1; i++) {
		row_height[i] = pps->row_height_minus1[i] + 1;
		sum += row_height[i];
	}
	row_height[i] = pic_in_cts_height - sum;
}

When sum >= pic_in_cts_width or sum >= pic_in_cts_height, subtracting sum
underflows u16 column_width[i] or row_height[i] to up to 65535.
compute_bd() then produces col_bd and row_bd entries far exceeding the
picture CTB dimensions, causing compute_tile_ids() to index
y * pic_in_ctbs_width + x past the end of the heap arrays
ctb_addr_rs_to_ts and tile_ids (allocated with pic_in_ctbs_size elements
in avd_hevc_compute_tiles()).

In addition, avd_hevc_validate_sps() does not reject zero
sps->pic_width_in_luma_samples or sps->pic_height_in_luma_samples (which
makes pic_in_ctbs_size == 0 so kzalloc_objs() returns ZERO_SIZE_PTR for
ctb_addr_rs_to_ts and tile_ids), nor does it bound
sps->log2_min_luma_coding_block_size_minus3 + 3 +
sps->log2_diff_max_min_luma_coding_block_size before
avd_hevc_compute_tiles() shifts and divides by max_cu_width.

[Severity: High]
Does enabling the AVD driver also expose an out-of-bounds kernel memory
write in avd_av1_set_prob() and a division by zero in calc_upscale() when
userspace submits crafted V4L2_CID_STATELESS_AV1_FRAME or
V4L2_CID_STATELESS_H264_SPS controls?

drivers/media/platform/apple/avd/avd-av1.c:avd_av1_set_prob() {
	...
	memcpy(vaddr + AVD_AV1_CDFS_OFFSET(length, dst->av1.color_size),
	       av1_ctx->bufs.probs.cpu, sizeof(struct avd_av1_cdfs));
}

Neither avd_av1_try_ctrl() nor avd_av1_run_preamble() validates
frame->frame_width_minus_1 + 1 and frame->frame_height_minus_1 + 1
against ctx->decoded_fmt.fmt.pix_mp.width and height. When the frame
dimensions exceed the capture buffer format dimensions,
update_dec_buf_info() computes dst->av1.color_size larger than the plane
length, so AVD_AV1_CDFS_OFFSET(length, dst->av1.color_size) underflows
and avd_av1_set_prob() writes sizeof(struct avd_av1_cdfs) bytes before
vaddr (or wraps width/height to 0 in set_refs() when
frame_width_minus_1 == U32_MAX, dividing by zero).

Furthermore, set_header() calls calc_upscale() without checking that
frame->upscaled_width is non-zero, dividing by upscaled_plane_w == 0 when
frame->upscaled_width == 0. Similarly, avd_h264_validate_sps() does not
validate (sps->pic_width_in_mbs_minus1 + 1) * 16 and
(sps->pic_height_in_map_units_minus1 + 1) * 16 against the allocated
format dimensions before stream_hdr() programs the hardware with the SPS
dimensions.

> +		reg = <0x2 0xcd070000 0x0 0x4000>,
> +		      <0x2 0xcd080000 0x0 0x10000>,
> +		      <0x2 0xcd090000 0x0 0x14000>,
> +		      <0x2 0xcd0a4000 0x0 0x4000>,
> +		      <0x2 0xcd100000 0x0 0x10000>;
> +		reg-names = "piodma", "code", "sram", "mbox", "ctrl";
> +		interrupt-parent = <&aic>;
> +		interrupts = <AIC_IRQ DIE_NO 1185 IRQ_TYPE_LEVEL_HIGH>,
> +			     <AIC_IRQ DIE_NO 1186 IRQ_TYPE_LEVEL_HIGH>,
> +			     <AIC_IRQ DIE_NO 1187 IRQ_TYPE_LEVEL_HIGH>,
> +			     <AIC_IRQ DIE_NO 1188 IRQ_TYPE_LEVEL_HIGH>,
> +			     <AIC_IRQ DIE_NO 1189 IRQ_TYPE_LEVEL_HIGH>,
> +			     <AIC_IRQ DIE_NO 1190 IRQ_TYPE_LEVEL_HIGH>,
> +			     <AIC_IRQ DIE_NO 1191 IRQ_TYPE_LEVEL_HIGH>;
> +		interrupt-names = "mbox0", "mbox1", "mbox2", "mbox3",
> +				  "flag0", "flag1", "piodma";
> +		iommus = <&DIE_NODE(avd_dart) 0>, <&DIE_NODE(avd_dart) 1>;
> +		power-domains = <&DIE_NODE(ps_avd_sys)>;
> +		resets = <&DIE_NODE(ps_avd_sys)>;
> +		dma-coherent;
> +	};

[Severity: Low]
Is dma-coherent allowed by
Documentation/devicetree/bindings/media/apple,avd.yaml? That binding sets
additionalProperties: false without listing dma-coherent, which causes
dtbs_check to fail on video-codec@2cd070000.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261128-avd-v4-0-35ad7d52c842@icloud.com?part=17

      reply	other threads:[~2026-11-28 22:42 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-28 22:02 [PATCH v4 00/17] media: apple: add avd driver Sofus Forstreuter
2026-11-28 22:02 ` [PATCH v4 01/17] dt-bindings: media: add apple,avd Sofus Forstreuter
2026-11-28 22:08   ` sashiko-bot
2026-11-28 22:02 ` [PATCH v4 02/17] media: v4l2: Add P210 pixel format Sofus Forstreuter
2026-11-28 22:02 ` [PATCH v4 03/17] media: v4l2: Add Apple interchange pixel formats Sofus Forstreuter
2026-11-28 22:02 ` [PATCH v4 04/17] media: v4l2-ctrls: validate AV1 context_update_tile_id Sofus Forstreuter
2026-11-28 22:39   ` sashiko-bot
2026-11-28 22:02 ` [PATCH v4 05/17] media: v4l2-ctrls: validate vp9 tile_rows_log2 Sofus Forstreuter
2026-11-28 22:08   ` sashiko-bot
2026-11-28 22:02 ` [PATCH v4 06/17] media: apple: add avd driver Sofus Forstreuter
2026-11-28 22:42   ` sashiko-bot
2026-11-28 22:02 ` [PATCH v4 07/17] media: apple: avd: add h264 support Sofus Forstreuter
2026-11-28 22:43   ` sashiko-bot
2026-11-28 22:02 ` [PATCH v4 08/17] media: apple: avd: add vp9 support Sofus Forstreuter
2026-11-28 22:49   ` sashiko-bot
2026-11-28 22:02 ` [PATCH v4 09/17] media: apple: avd: add hevc support Sofus Forstreuter
2026-11-28 22:46   ` sashiko-bot
2026-11-28 22:02 ` [PATCH v4 10/17] media: apple: avd: add av1 support Sofus Forstreuter
2026-11-28 22:39   ` sashiko-bot
2026-11-28 22:02 ` [PATCH v4 11/17] arm64: dts: apple: t8103: add avd nodes Sofus Forstreuter
2026-11-28 22:36   ` sashiko-bot
2026-11-28 22:02 ` [PATCH v4 12/17] arm64: dts: apple: t8112: " Sofus Forstreuter
2026-11-28 22:21   ` sashiko-bot
2026-11-28 22:02 ` [PATCH v4 13/17] arm64: dts: apple: t8122: " Sofus Forstreuter
2026-11-28 22:37   ` sashiko-bot
2026-11-28 22:02 ` [PATCH v4 14/17] arm64: dts: apple: t600x: " Sofus Forstreuter
2026-11-28 22:35   ` sashiko-bot
2026-11-28 22:02 ` [PATCH v4 15/17] arm64: dts: apple: t602x: " Sofus Forstreuter
2026-11-28 22:20   ` sashiko-bot
2026-11-28 22:02 ` [PATCH v4 16/17] arm64: dts: apple: t6030: " Sofus Forstreuter
2026-11-28 22:42   ` sashiko-bot
2026-11-28 22:02 ` [PATCH v4 17/17] arm64: dts: apple: t6031: " Sofus Forstreuter
2026-11-28 22:42   ` sashiko-bot [this message]

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=sashiko-outbox-239115@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=media-ci@linuxtv.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=sofus.c@icloud.com \
    /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