Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8B649606A31F for ; Sat, 28 Nov 2026 14:24:48 +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=ZFHYwMLt Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id CF53E10E752; Sat, 28 Nov 2026 14:24:42 +0000 (UTC) Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by gabe.freedesktop.org (Postfix) with ESMTPS id BA76F10E752 for ; Sat, 28 Nov 2026 14:24:36 +0000 (UTC) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 88DED41F9F; Sat, 28 Nov 2026 14:24:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 578D51F000C1; Sat, 28 Nov 2026 14:24:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795875876; bh=j5kXh0Gwpknl8pNanVkkZb5KqH8tJlGzZvML61eCuyQ=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=ZFHYwMLtJdtZ7HXAN/IjZYYpXi523wxXqm6PeftW4lNl0hdeFAoho8VMqHjfB/544 GUc9SaQBvNrFggKJNLqj4GEwz2b/tztAyGlY57iPzfujZjXu+OmhipY2jzwwrmSExM dW+/sZbLy8XDLrEVrvFFLLBkLUcbryV4ot0y5FVZBBXZMJJDwGKakWQs7Qng/6SSWZ xk72xjrXrHKYJvdxNzxaoKvHxC1VDlVD+sumftDxrEZFaWzkYaCRQhhQuTBm1TrMuV RmxVDL87chPmRNDAnrcj6NPtRXUlBRJj8QLuG4BxBx89xjG9ILO8X9OulNPd3rAj0w ex0m6Al3sClXg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH] accel/amdxdna: Validate command BO size and payload in amdxdna_ctx To: "Bilal Hashim" Cc: dri-devel@lists.freedesktop.org In-Reply-To: <20261128140537.1325-2-AeeSec@126.com> References: <20261128140537.1325-1-AeeSec@126.com> <20261128140537.1325-2-AeeSec@126.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sat, 28 Nov 2026 14:24:35 +0000 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: sashiko-reviews@lists.linux.dev Sender: "dri-devel" X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 X-Archived-By: Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] accel/amdxdna: double-fetch of command_count and header from shared BO - [Low] accel/amdxdna: missing Fixes trailers for command BO bounds checks -- commit f26ba1eb1e32cf2335021773851c47a44765f56d Author: Bilal Hashim > accel/amdxdna: Validate command BO size and payload in amdxdna_ctx > > Command BOs (`AMDXDNA_BO_SHARE`) are mapped into userspace and their > contents can be modified by userspace at any time before or during > command execution. Three helpers in `amdxdna_ctx.c` access `struct > amdxdna_cmd` fields in the mapped BO without complete bounds checks: > > 1. `amdxdna_cmd_get_cu_idx()` computes `num_masks =3D 1 + > FIELD_GET(AMDXDNA_CMD_EXTRA_CU_MASK, cmd->header)` (up to 4 `u32` > words) and reads `cmd->data[0..num_masks - 1]` without verifying that > `struct_size(cmd, data, num_masks) <=3D abo->mem.size`. > 2. `amdxdna_cmd_set_error()` calls `amdxdna_cmd_get_payload(abo, NULL)` > when `amdxdna_cmd_get_op(abo) =3D=3D ERT_CMD_CHAIN`. Passing `size =3D= NULL` > bypasses the payload length validation in `amdxdna_cmd_get_payload()`, > and `amdxdna_cmd_set_error()` then writes `cc->error_index` and reads > `cc->data[0]` without verifying that the payload is large enough to > hold a `struct amdxdna_cmd_chain` with at least one `data` entry. > Furthermore, `memset(cmd->data, 0xff, abo->mem.size - sizeof(*cmd))` > assumes `abo->mem.size >=3D sizeof(*cmd)`. > 3. `amdxdna_cmd_get_payload()` only validates `count` against > `abo->mem.size` when `size !=3D NULL`. If called with `size =3D=3D NUL= L`, > it returns `&cmd->data[num_masks]` without checking that the offset > lies within `abo->mem.size`. > > Harden `amdxdna_cmd_get_payload()`, `amdxdna_cmd_get_cu_idx()`, and > `amdxdna_cmd_set_error()` by validating the command BO size and payload > length before reading or writing `cmd->data` and `amdxdna_cmd_chain`. > > Signed-off-by: Bilal Hashim [Severity: Low] This fixes missing bounds and payload checks in the command helpers. Should the commit message include Fixes tags for the commits that introduced them: Fixes: aac243092b70 ("accel/amdxdna: Add command execution") Fixes: 89ff45359abb ("accel/amdxdna: Fill invalid payload for failed comm= and") > diff --git a/drivers/accel/amdxdna/amdxdna_ctx.c b/drivers/accel/amdxdna/= amdxdna_ctx.c > index 8601655cecdb5..06c9eabefac38 100644 > --- a/drivers/accel/amdxdna/amdxdna_ctx.c > +++ b/drivers/accel/amdxdna/amdxdna_ctx.c [ ... ] > @@ -168,21 +171,26 @@ int amdxdna_cmd_set_error(struct amdxdna_gem_obj *a= bo, > struct amdxdna_client *client =3D job->hwctx->client; > struct amdxdna_cmd *cmd =3D amdxdna_gem_vmap(abo); > struct amdxdna_cmd_chain *cc =3D NULL; > + u32 payload_len; > =20 > - if (!cmd) > + if (!cmd || abo->mem.size < sizeof(*cmd)) > return -ENOMEM; > =20 > cmd->header &=3D ~AMDXDNA_CMD_STATE; > cmd->header |=3D FIELD_PREP(AMDXDNA_CMD_STATE, error_state); > =20 > if (amdxdna_cmd_get_op(abo) =3D=3D ERT_CMD_CHAIN) { > - cc =3D amdxdna_cmd_get_payload(abo, NULL); > + cc =3D amdxdna_cmd_get_payload(abo, &payload_len); > + if (!cc || !cc->command_count || > + payload_len < struct_size(cc, data, cc->command_count)) > + return -EINVAL; > + > cc->error_index =3D (cmd_idx < cc->command_count) ? cmd_idx : 0; > abo =3D amdxdna_gem_get_obj(client, cc->data[0], AMDXDNA_BO_SHARE); [Severity: Medium] Can userspace bypass the new struct_size() check by modifying cc->command_count between reads? cc points into the userspace-mapped AMDXDNA_BO_SHARE buffer, and cc->command_count is read three times without READ_ONCE(). With payload_len =3D=3D sizeof(*cc), if a concurrent userspace thread changes cc->command_count from 1 to 0 between the !cc->command_count check and the struct_size(cc, data, cc->command_count) check, both checks pass and cc->data[0] is read past payload_len. cmd->header is likewise read multiple times from the shared BO across amdxdna_cmd_get_payload(), amdxdna_cmd_get_cu_idx(), and amdxdna_cmd_set_error(), so snapshotting both cc->command_count (as get_cmd_bos() in aie4_ctx.c does) and cmd->header into local variables with READ_ONCE() would avoid inconsistent reads. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261128140537.1325= -2-AeeSec@126.com?part=3D1