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 11/17] arm64: dts: apple: t8103: add avd nodes
Date: Sat, 28 Nov 2026 22:36:04 +0000	[thread overview]
Message-ID: <sashiko-outbox-239104@kernel.org> (raw)
In-Reply-To: <20261128-avd-v4-11-35ad7d52c842@icloud.com>

Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [Critical] media: apple: avd: out-of-bounds heap accesses in
  compute_tile_ids()
- [Critical] media: apple: avd: missing input validation and stale state
  in avd-av1.c
- [Medium] arm64: dts: apple: t8103: undocumented dma-coherent on
  video-codec@269070000
- [Low] arm64: dts: apple: t8103: missing commit message description
  body
--

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

> arm64: dts: apple: t8103: add avd nodes
>
> Reviewed-by: Neal Gompa <neal@gompa.dev>
> Signed-off-by: Sofus Forstreuter <sofus.c@icloud.com>

[Severity: Low]
This commit message has no changelog body describing the added avd_dart
DART IOMMU and Apple Video Decoder nodes.

> diff --git a/arch/arm64/boot/dts/apple/t8103.dtsi b/arch/arm64/boot/dts/apple/t8103.dtsi
> index 5b68bf0df4e6b..a37f135af616d 100644
> --- a/arch/arm64/boot/dts/apple/t8103.dtsi
> +++ b/arch/arm64/boot/dts/apple/t8103.dtsi
> @@ -984,6 +984,39 @@ pinctrl_aop: pinctrl@24a820000 {
>  				     <AIC_IRQ 274 IRQ_TYPE_LEVEL_HIGH>;
>  		};
>  
> +		avd_dart: iommu@269010000 {
> +			compatible = "apple,t8103-dart";
> +			reg = <0x2 0x69010000 0x0 0x4000>;
> +			interrupt-parent = <&aic>;
> +			interrupts = <AIC_IRQ 547 IRQ_TYPE_LEVEL_HIGH>;
> +			#iommu-cells = <1>;
> +			power-domains = <&ps_avd_sys>;
> +		};
> +
> +		video-codec@269070000 {
> +			compatible = "apple,t8103-avd";
> +			reg = <0x2 0x69070000 0x0 0x4000>,
> +			      <0x2 0x69080000 0x0 0xc000>,
> +			      <0x2 0x6908c000 0x0 0xc000>,
> +			      <0x2 0x69098000 0x0 0x4000>,
> +			      <0x2 0x69100000 0x0 0x10000>;
> +			reg-names = "piodma", "code", "sram", "mbox", "ctrl";
> +			interrupt-parent = <&aic>;
> +			interrupts = <AIC_IRQ 540 IRQ_TYPE_LEVEL_HIGH>,
> +				     <AIC_IRQ 541 IRQ_TYPE_LEVEL_HIGH>,
> +				     <AIC_IRQ 542 IRQ_TYPE_LEVEL_HIGH>,
> +				     <AIC_IRQ 543 IRQ_TYPE_LEVEL_HIGH>,
> +				     <AIC_IRQ 544 IRQ_TYPE_LEVEL_HIGH>,
> +				     <AIC_IRQ 545 IRQ_TYPE_LEVEL_HIGH>,
> +				     <AIC_IRQ 546 IRQ_TYPE_LEVEL_HIGH>;
> +			interrupt-names = "mbox0", "mbox1", "mbox2", "mbox3",
> +					  "flag0", "flag1", "piodma";
> +			iommus = <&avd_dart 0>, <&avd_dart 1>;
> +			power-domains = <&ps_avd_sys>;
> +			resets = <&ps_avd_sys>;
> +			dma-coherent;
> +		};

[Severity: Medium]
Does dma-coherent on video-codec@269070000 fail make dtbs_check?
Documentation/devicetree/bindings/media/apple,avd.yaml sets
additionalProperties: false and does not list dma-coherent under
properties.

[Severity: Critical]
Can exposing video-codec@269070000 allow unprivileged userspace to trigger
out-of-bounds kernel heap reads and writes in the HEVC decoder via
compute_tile_ids()?

When an HEVC decode request runs avd_device_run() -> avd_hevc_run() ->
avd_hevc_compute_tiles(), compute_tiles_non_uniform() accumulates
unvalidated pps->column_width_minus1[i] + 1 and pps->row_height_minus1[i] +
1 into sum and assigns the final u16 entry as pic_in_cts_width - sum and
pic_in_cts_height - sum:

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;

	sum = 0;
	for (i = 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, the subtraction
underflows u16 and compute_bd() produces col_bd and row_bd entries
exceeding pic_in_ctbs_width and pic_in_ctbs_height.  compute_tile_ids()
then reads ctb_addr_rs_to_ts and writes tile_ids out of bounds on the
kernel heap.

In addition, neither std_validate_compound() nor avd_hevc_validate_sps()
rejects zero pic_width_in_luma_samples / pic_height_in_luma_samples or
out-of-range log2_min_luma_coding_block_size_minus3 /
log2_diff_max_min_luma_coding_block_size, so avd_hevc_compute_tiles() can
hit an undefined shift or divide by zero when computing max_cu_width before
avd_hevc_alloc_scratch() checks if (!max_cu_width), or allocate
ZERO_SIZE_PTR for ctb_addr_rs_to_ts and tile_ids.

[Severity: Critical]
Can the AVD driver's AV1 decoder in drivers/media/platform/apple/avd/avd-av1.c
write out of bounds in avd_av1_set_prob() when given unvalidated frame
dimensions?

Neither validate_av1_frame() nor avd-av1.c checks frame_width_minus_1 + 1
and frame_height_minus_1 + 1 against the CAPTURE buffer dimensions, so
dst->av1.color_size can exceed dst->base.vb.vb2_buf.planes[0].length and
underflow AVD_AV1_CDFS_OFFSET(), causing memcpy() in avd_av1_set_prob() to
write sizeof(struct avd_av1_cdfs) bytes before vaddr:

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));
}

In set_tiles(), assigning u32 tile_group->tile_row and tile_group->tile_col
to signed int allows values >= 0x80000000 to become negative, bypass the
V4L2_AV1_MAX_TILE_ROWS / V4L2_AV1_MAX_TILE_COLS upper-bound check, and
index tile_info arrays out of bounds.

In calc_upscale(), an unvalidated frame->upscaled_width of 0 yields
upscaled_plane_w == 0 and triggers an integer division by zero.

Finally, set_refs() declares alpha, beta, gamma and delta outside the
reference loop, so when avd_av1_dec_get_shear_params() returns early on
mat[2] <= 0, the iteration reuses stale shear parameters from an earlier
reference frame.

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

  reply	other threads:[~2026-11-28 22:36 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 [this message]
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

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-239104@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