From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 606193B27C9 for ; Wed, 13 May 2026 18:55:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778698503; cv=none; b=u1pRH4eF9CSX2NvJ4mec+/dJTR/3P/6AdmhjUFYIh9iF6XvA0CNO58XU4tvYGtyoc4iuzjNOj0AM6/+IQ9WJ+vNXopa41T1xotsbMK65JPWVHlG4bEvdN2IuriIofhJO/TUkXhdpHJnpWJPNbi9oebkIuZm5oNYN7LUhUEPl2rI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778698503; c=relaxed/simple; bh=mdi9g/KaPEC280U/FqLeU0lAH63bhv2L359Pq7ECmJg=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=g2cGdIm64PrFABeW01hwh0RsQG65cQsNEFBMcewyO+MtkpiuClFIUMs++Q8dyfuaUF4tx6GbUyxfAs+JArhPrkn+z+6o8ha44T4xbK4lW4nNck0Uw+vBUlI1wGg/i5rHm8a1DSnPx1BBLLzx8J3WK/hMRPk6b4zX0wPKYQkRpxM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=pNZpPezw; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="pNZpPezw" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D013CC2BCB7; Wed, 13 May 2026 18:55:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1778698503; bh=mdi9g/KaPEC280U/FqLeU0lAH63bhv2L359Pq7ECmJg=; h=From:To:Cc:Subject:Date:From; b=pNZpPezwJRjIZ6HCrsq9p4zZUFFQfNJUfFsF4KQ37g+S5LKQXGVNPiMcCa1vFlTWL k17ydn+Kvyr4N2lSoG8HIsPGm6x7nc1jtYZtPc+KGi3+yUfE1X5g8ipKEnH4g9sQuB F2id2NrODNu5dd4QL/VNO/W5RrOx3c1il+U2Tu6UvIB6pqLlIxfrPWmPd3/I9byFs+ IjrOGLyrIB0A78T7jQaFvmiQy0Cm5poOQkpUGUTHrnNCEJ14Vrk3D4wI+Ppo7wU6Cp aj7Vb/g4cDe/awwTNwX/S5AOv2gbuTNSM1pz7GW29IBk4G7Xz4UuOXPobiMgOZ5RGg K9e8XILhs80/Q== From: "Rob Herring (Arm)" To: Tomeu Vizoso , Oded Gabbay Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH] accel: ethosu: Validate SRAM size on submit Date: Wed, 13 May 2026 13:54:34 -0500 Message-ID: <20260513185434.1667045-1-robh@kernel.org> X-Mailer: git-send-email 2.53.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Regions with a BO are checked against the BO size, but the SRAM region is not. The SRAM region doesn't have a BO, but the command stream region size should be checked against the SRAM size. The job's "sram_size" isn't useful here because an evil userspace could lie about the size. Signed-off-by: Rob Herring (Arm) --- drivers/accel/ethosu/ethosu_job.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/drivers/accel/ethosu/ethosu_job.c b/drivers/accel/ethosu/ethosu_job.c index ec85f4156744..e7b07cdbcced 100644 --- a/drivers/accel/ethosu/ethosu_job.c +++ b/drivers/accel/ethosu/ethosu_job.c @@ -417,9 +417,21 @@ static int ethosu_ioctl_submit_job(struct drm_device *dev, struct drm_file *file struct drm_gem_object *gem; /* Can only omit a BO handle if the region is not used or used for SRAM */ - if (!job->region_bo_handles[i] && - (!cmd_info->region_size[i] || (i == ETHOSU_SRAM_REGION && job->sram_size))) - continue; + if (!job->region_bo_handles[i]) { + if (!cmd_info->region_size[i]) + continue; + if (i == ETHOSU_SRAM_REGION) { + if (cmd_info->region_size[i] <= edev->npu_info.sram_size) + continue; + + dev_err(dev->dev, + "cmd stream region %d size greater than SRAM size (%llu > %u)\n", + i, cmd_info->region_size[i], + edev->npu_info.sram_size); + ret = -EINVAL; + goto out_cleanup_job; + } + } if (job->region_bo_handles[i] && !cmd_info->region_size[i]) { dev_err(dev->dev, -- 2.53.0