From nobody Sun May 24 18:41:07 2026 Received: from mail-pj1-f43.google.com (mail-pj1-f43.google.com [209.85.216.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8AE9730C606 for ; Sat, 23 May 2026 19:10:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779563452; cv=none; b=lyt1lPnw47mY0OvQpqpaJ6Dey7CZL05pTI6WBNVFN9CMc1xFdb0h/zThT/0GuZDe6V65XaVEUr/XoieZfxHXiiaC9/3XaH865fOtE3f/hYk5oRfFLYthZXVGtGFlnqbjeu+8FQfM42CVPvmzbETY24YbhGef5EtdZvkUzJUb7t8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779563452; c=relaxed/simple; bh=wsG8L4uMeqqXkqDYMklZJ+D049NNE2kAtaY1+cVH4cs=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=OdRaLOoeSQZ1RMxCM4gwkdoTOX/pr2dzyLj2lnnHhq3nffxH2iRcxiKOFF7OMaaHIIOqKXYTVKE1xdvibLY9h2rC5VCvfHRdOTjz1Pz9kspb7y7dhTeqbIceUM0O3XKemYrfHRTmU1ugcdSZ+NfRHZ2247T7WlvraC00D4FrOFY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=K6sU/44q; arc=none smtp.client-ip=209.85.216.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="K6sU/44q" Received: by mail-pj1-f43.google.com with SMTP id 98e67ed59e1d1-3699cdeec05so3506646a91.3 for ; Sat, 23 May 2026 12:10:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779563451; x=1780168251; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=2pdcMudAXsnsf14xcsIygiiXlNDoLkCiV99tMYt+d3Q=; b=K6sU/44qC0GT8QZ5TkmAlu6H65p8gw6Wcaa4HVfrqWYJN+oA9sIO279pQppIZKQRn5 3Q/D/YN89y8bh601WRhtJeYTGe/7NOTvKzX7gAgc3DJ7u6Kvpf8fit1yynvLCWS6HRAS tzFzwXr9/0K4ea2+sCtG6Cx0q3oCngfkMxibzfZjD+depziFyh48i1hCIVDWMz7/tNLY P/hjRfF7OtPURBlnFxK/xS4cdKVAsIMrqlEHLUHOIDIpJ8B/72fxf8hFzvst5kKgJ1ci uCMdajmoFKAAdhWBGLMVDGMgEvbQ7Nks/zf1VSLAdqHNUIXHqlRKVmxquHL1NpXT76fp Fp9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779563451; x=1780168251; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=2pdcMudAXsnsf14xcsIygiiXlNDoLkCiV99tMYt+d3Q=; b=S7hIlJ4LLNc41Xtct53tMYI44edzAuprZKIUsyyGe/u3rtJvjaNC3OYZhrvn7KYaG+ CrBUFzJVXfBmEx9+jn/V7mwsQp+oXJxjUh/ZyoQGwFeUz8tsO23cYTqbwkoejtBWJgvP Rwcas02poJ0eeeJAmmRfNYuIA4b1li2Y0Sk3DncNKguTrsdpXi2y8zblYgRx+HifxJrD rDlR+25mA+xW70C7L6sYTXc8sSPvi442VU62xh+tNjGb7PDLydL2tJ0Nxln6xLlfRLaL 3+2F8mya38sv6/CclBMo0doR68obtas4y+bK/mXOcJMFl2UAKzwNXttdl3eXRSy8GXPq 6PKg== X-Forwarded-Encrypted: i=1; AFNElJ+xootkiNIYbCtBSi80778kG811P0hKLItZ2dAN9lfMrQN3ptGgW/8A8N4X+MYsNwNws1rBJXr1zgc97Uo=@vger.kernel.org X-Gm-Message-State: AOJu0YzAZV3VhiuDXjat5djQAUkuLuiv3WW8coL4qGPL898Y9Nv32O5p yTqYTi/KK+6Jg362oiEZenFikSq8SneaPDbdvJ7leZBRd1oEn1yoYYtjmb8HNU2MVGwrKQ== X-Gm-Gg: Acq92OFn1vXQxnVbiAPxKbgt4QTslOlbqClITLK8hQNCaRKV8foqiASMlrL1n/ooscH BPb482le7C+PUExLNr5yEPtz0qKXtKshXLjOOZMoiaVIkFj8WwUfhz/r6H9Bn5TTSsllAtvh4D+ 1dtkLcN6IE+SfnL7kj876VJwsjM24onn0wqMe7w5LvOObPfFu4thP5pHG+4EXmyFbRNiB+TE+DU lee5ko12uF+8Iye9/z/xv9MR7ILSCmHzuTSpEmqqSCaSWPT9xtZFprCq+EhN6a8KE8fms/s36iw ciC8ubmWhSh34folQwA+iMCjDv7Bv4V9l2dXXCB9G2p9B/zE9WENDPE8zB3Xsvg1xn/FAHJITY8 blE//nlOU+U6XJ1QoXX5KI4Qw+9oWWqUFGMzAzAG+CnUVi+yrN2gjcMT+v6abQIU+3DxJICdo9Z j9aGZhEkgEOE/buhLg80lztwN+F24Ubol8YATM4tGxpF/fe8n+lqCcJt5AHUSldbAW7Ffmv7Pas QRd9KoMFpnN2+8Psy8M2+GjrJbExjptbu1DfJYM6P7KDmlAdpw4SfKMW1YUD4E2//lnrdQFofUw 5W7leeO8Qgo= X-Received: by 2002:a17:90b:3dcd:b0:35f:bfdd:f5a1 with SMTP id 98e67ed59e1d1-36a677fd1ebmr7791851a91.13.1779563450705; Sat, 23 May 2026 12:10:50 -0700 (PDT) Received: from codespaces-78f0a7.mimvmn1ww3huhhjmzljqefhnig.rx.internal.cloudapp.net ([4.240.39.195]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-36a6f0baca7sm3151877a91.2.2026.05.23.12.10.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 May 2026 12:10:50 -0700 (PDT) From: Muhammad Bilal To: robh@kernel.org Cc: tomeu@tomeuvizoso.net, ogabbay@kernel.org, tzimmermann@suse.de, Frank.Li@nxp.com, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Muhammad Bilal Subject: [PATCH] accel/ethosu: fix OOB write in ethosu_gem_cmdstream_copy_and_validate() Date: Sat, 23 May 2026 19:08:43 +0000 Message-ID: <20260523190843.33977-1-meatuni001@gmail.com> 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: quoted-printable Content-Type: text/plain; charset="utf-8" The command stream parsing loop increments the index variable a second time when a 64-bit command word is encountered (bit 14 set), but does not re-check the loop bound before writing the second word: for (i =3D 0; i < size / 4; i++) { bocmds[i] =3D cmds[0]; if (cmd & 0x4000) { i++; bocmds[i] =3D cmds[1]; /* unchecked */ } } The buffer bocmds is backed by a DMA allocation of exactly size bytes from drm_gem_dma_create(ddev, size), giving valid indices [0, size/4-1]. When i =3D=3D size/4 - 1 on entry to an iteration and bit 14 of cmds[0] is set, bocmds[size/4-1] is written in bounds, i is then incremented to size/4, and bocmds[size/4] writes four bytes past the end of the allocation. Userspace controls both the buffer contents and the size argument via the ioctl, making this a userspace-triggerable heap out-of-bounds write. Fix by checking the incremented index against the buffer bound before the second write and returning -EINVAL if the buffer is too small to contain the extended command. Fixes: 5a5e9c0228e6 ("accel: Add Arm Ethos-U NPU driver") Cc: stable@vger.kernel.org Signed-off-by: Muhammad Bilal --- drivers/accel/ethosu/ethosu_gem.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/accel/ethosu/ethosu_gem.c b/drivers/accel/ethosu/ethos= u_gem.c index 7994e7073903..f526f4aedffd 100644 --- a/drivers/accel/ethosu/ethosu_gem.c +++ b/drivers/accel/ethosu/ethosu_gem.c @@ -387,6 +387,8 @@ static int ethosu_gem_cmdstream_copy_and_validate(struc= t drm_device *ddev, return -EFAULT; =20 i++; + if (i >=3D size / 4) + return -EINVAL; bocmds[i] =3D cmds[1]; addr =3D cmd_to_addr(cmds); } --=20 2.53.0