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 A1825C61DC7 for ; Thu, 27 Aug 2026 20:33:37 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E52A210F1A0; Thu, 27 Aug 2026 20:33:35 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.b="JBfuPI9R"; dkim-atps=neutral Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by gabe.freedesktop.org (Postfix) with ESMTPS id 1360F10F195 for ; Thu, 27 Aug 2026 20:33:24 +0000 (UTC) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 855A9601F0; Thu, 27 Aug 2026 20:33:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 11ADD1F00ACA; Thu, 27 Aug 2026 20:33:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1787862803; bh=euVg/tOwg5ulL53VFnnSZJZdeTLzg/FGZY1xwhIMPMY=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=JBfuPI9RdPMrhn3lVUSCqZyqwzvidM74e3isdluBD7J6yYxsCyX0qgY2Add2hOZuY DgOnuHK2loRzlARS1Qo6c8MqtgmfIQih7f2iJs2PGhtLVI3szs1/iFbFfJ8tsZ3y6s XkFrVjxPpFN2FvA+daaS7ud3IC84Drn54dBZlZOMolIuraFbaWWbc/YXbBVZUXkhGC I81zzsTczmTjJ6VswHCfDiQtfDS5zwp3JMJj3i6Ro2T6PDNF5JaEcd1EAQGo+uByiK Lrr54V584oMPbESYIk8wXhAhIEyrE5F44vLoAV6FRzvk5vKibdJWbkLCXqVt59nU/3 8AMG79mXYmOig== From: "Rob Herring (Arm)" Date: Thu, 27 Aug 2026 15:33:06 -0500 Subject: [PATCH 07/11] accel: ethosu: Factor buffer bounds checks MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260827-ethosu-fixes-v1-7-346f9ea8791c@kernel.org> References: <20260827-ethosu-fixes-v1-0-346f9ea8791c@kernel.org> In-Reply-To: <20260827-ethosu-fixes-v1-0-346f9ea8791c@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" Move the repeated command-stream buffer range validation into a helper in preparation for validating all weight and scale streams. Cc: stable@vger.kernel.org Assisted-by: LLM Signed-off-by: Rob Herring (Arm) --- drivers/accel/ethosu/ethosu_gem.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/drivers/accel/ethosu/ethosu_gem.c b/drivers/accel/ethosu/ethosu_gem.c index eda9f42239be..9fce7caeeb9a 100644 --- a/drivers/accel/ethosu/ethosu_gem.c +++ b/drivers/accel/ethosu/ethosu_gem.c @@ -259,6 +259,22 @@ static u64 feat_matrix_length(struct ethosu_device *edev, return addr; } +static int buffer_size(struct ethosu_validated_cmdstream_info *info, + struct buffer *buf, s8 region) +{ + u64 end; + + if (region < 0 || buf->base == U64_MAX || buf->length == U32_MAX) + return -EINVAL; + + if (check_add_overflow(buf->base, (u64)buf->length, &end)) + return -EINVAL; + + info->region_size[region] = max(info->region_size[region], end); + + return 0; +} + static int calc_sizes(struct drm_device *ddev, struct ethosu_validated_cmdstream_info *info, u16 op, struct cmd_state *st, @@ -303,24 +319,16 @@ static int calc_sizes(struct drm_device *ddev, dev_dbg(ddev->dev, "op %d: W:%d:0x%llx-0x%llx\n", op, st->weight[0].region, st->weight[0].base, st->weight[0].base + st->weight[0].length - 1); - if (st->weight[0].region < 0 || st->weight[0].base == U64_MAX || - st->weight[0].length == U32_MAX) + if (buffer_size(info, &st->weight[0], st->weight[0].region)) return -EINVAL; - info->region_size[st->weight[0].region] = - max(info->region_size[st->weight[0].region], - st->weight[0].base + st->weight[0].length); } if (scale) { dev_dbg(ddev->dev, "op %d: S:%d:0x%llx-0x%llx\n", op, st->scale[0].region, st->scale[0].base, st->scale[0].base + st->scale[0].length - 1); - if (st->scale[0].region < 0 || st->scale[0].base == U64_MAX || - st->scale[0].length == U32_MAX) + if (buffer_size(info, &st->scale[0], st->scale[0].region)) return -EINVAL; - info->region_size[st->scale[0].region] = - max(info->region_size[st->scale[0].region], - st->scale[0].base + st->scale[0].length); } len = feat_matrix_length(edev, info, &st->ofm, st->ofm.width, -- 2.53.0