From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9FFF0C79FAA for ; Tue, 8 Sep 2026 22:05:27 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C70F610EDC4; Tue, 8 Sep 2026 22:05:23 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.b="GJDWz+zH"; dkim-atps=neutral Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by gabe.freedesktop.org (Postfix) with ESMTPS id C481B10EDB7 for ; Tue, 8 Sep 2026 22:05:06 +0000 (UTC) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 9FD9344791; Tue, 8 Sep 2026 22:05:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 43FEE1F00A3D; Tue, 8 Sep 2026 22:05:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1788905106; bh=x1CU1YU3r6fb1ZoOvXn8W7FcD1J/3so288U26VwNAxk=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=GJDWz+zHAlm5DrOo/25nw6MPCjwXxJglSzCNHkRoRPgJNM0nMlEtewGPpm8ebFyRv 21u9+xQf/SM/ayQAtywjTfr9G1G8ng4+Qi1UwBO040nk9Kg6qJcjOXOfvn+sGEGd6o 8DfFb0tFQ19XYDxxIsv+p6IoeMOxfVsTmke55a4eVQGRTiAzyalFfru8mky23B1Qp5 mgEAh46DRBh13bx1kE3ZEmAgUySCanOHLWFPgW5JhYZKOabEP0l7V32DmPDacGcuqZ hMw6VDSQJHoZC/AdxTXxsfOu/NjWqV58/9YU84sxKB3uZbf7JJDwdm3nb7uw4dT2YG c7JxMNYgtCdhQ== From: "Rob Herring (Arm)" Date: Tue, 08 Sep 2026 17:04:48 -0500 Subject: [PATCH v3 11/22] accel: ethosu: Validate secondary streams MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260908-ethosu-fixes-v3-11-490fe215286f@kernel.org> References: <20260908-ethosu-fixes-v3-0-490fe215286f@kernel.org> In-Reply-To: <20260908-ethosu-fixes-v3-0-490fe215286f@kernel.org> To: Tomeu Vizoso , Oded Gabbay , Frank Li , Thomas Zimmermann Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org X-Mailer: b4 0.16-dev X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" The command-stream validator records the additional U65 scale and weight stream addresses and the U85 weight decoder addresses, but only checked stream 0 against its region buffer. Check every configured secondary stream against the matching weight or scale region before accepting a kernel operation. Fixes: 5a5e9c0228e6 ("accel: Add Arm Ethos-U NPU driver") Cc: stable@vger.kernel.org Assisted-by: LLM Signed-off-by: Rob Herring (Arm) --- v2: - Adjust for register state tracking --- drivers/accel/ethosu/ethosu_gem.c | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/drivers/accel/ethosu/ethosu_gem.c b/drivers/accel/ethosu/ethosu_gem.c index 6f6712f4efd1..abfb173e1008 100644 --- a/drivers/accel/ethosu/ethosu_gem.c +++ b/drivers/accel/ethosu/ethosu_gem.c @@ -436,13 +436,17 @@ static u64 feat_matrix_length(struct ethosu_device *edev, static int buffer_size(struct ethosu_validated_cmdstream_info *info, struct cmd_state *st, struct buffer *buf, s8 region, - u16 region_cmd, u16 base_cmd, u16 length_cmd) + u16 region_cmd, u16 base_cmd, u16 length_cmd, bool optional) { u64 end; + bool base_set = cmd_state_reg_is_set(st, base_cmd); + bool length_set = cmd_state_reg_is_set(st, length_cmd); + + if (optional && !base_set && !length_set) + return 0; if (region < 0 || !cmd_state_reg_is_set(st, region_cmd) || - !cmd_state_reg_is_set(st, base_cmd) || - !cmd_state_reg_is_set(st, length_cmd)) + !base_set || !length_set) return -EINVAL; if (check_add_overflow(buf->base, (u64)buf->length, &end)) @@ -507,7 +511,20 @@ static int calc_sizes(struct drm_device *ddev, st->weight[0].base + st->weight[0].length - 1); if (buffer_size(info, st, &st->weight[0], st->weight[0].region, NPU_SET_WEIGHT_REGION, NPU_SET_WEIGHT_BASE, - NPU_SET_WEIGHT_LENGTH)) + NPU_SET_WEIGHT_LENGTH, false)) + return -EINVAL; + + if (buffer_size(info, st, &st->weight[1], st->weight[0].region, + NPU_SET_WEIGHT_REGION, NPU_SET_WEIGHT1_BASE, + NPU_SET_WEIGHT1_LENGTH, true) || + buffer_size(info, st, &st->weight[3], st->weight[0].region, + NPU_SET_WEIGHT_REGION, NPU_SET_WEIGHT3_BASE, + NPU_SET_WEIGHT3_LENGTH, true)) + return -EINVAL; + if (!ethosu_is_u65(edev) && + buffer_size(info, st, &st->weight[2], st->weight[0].region, + NPU_SET_WEIGHT_REGION, NPU_SET_WEIGHT2_BASE, + NPU_SET_WEIGHT2_LENGTH, true)) return -EINVAL; } @@ -517,7 +534,13 @@ static int calc_sizes(struct drm_device *ddev, st->scale[0].base + st->scale[0].length - 1); if (buffer_size(info, st, &st->scale[0], st->scale[0].region, NPU_SET_SCALE_REGION, NPU_SET_SCALE_BASE, - NPU_SET_SCALE_LENGTH)) + NPU_SET_SCALE_LENGTH, false)) + return -EINVAL; + + if (ethosu_is_u65(edev) && + buffer_size(info, st, &st->scale[1], st->scale[0].region, + NPU_SET_SCALE_REGION, NPU_SET_SCALE1_BASE, + NPU_SET_SCALE1_LENGTH, true)) return -EINVAL; } -- 2.53.0