From nobody Tue Jun 30 00:02:50 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0DCD2C433EF for ; Sat, 29 Jan 2022 15:06:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243207AbiA2PGq (ORCPT ); Sat, 29 Jan 2022 10:06:46 -0500 Received: from mta-13-4.privateemail.com ([198.54.127.109]:53839 "EHLO MTA-13-4.privateemail.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241780AbiA2PGm (ORCPT ); Sat, 29 Jan 2022 10:06:42 -0500 X-Greylist: delayed 1740 seconds by postgrey-1.27 at vger.kernel.org; Sat, 29 Jan 2022 10:06:41 EST Received: from mta-13.privateemail.com (localhost [127.0.0.1]) by mta-13.privateemail.com (Postfix) with ESMTP id D991818000BE; Sat, 29 Jan 2022 10:06:40 -0500 (EST) Received: from localhost.localdomain (unknown [10.20.151.172]) by mta-13.privateemail.com (Postfix) with ESMTPA id 3071B18000A5; Sat, 29 Jan 2022 10:06:37 -0500 (EST) From: Jordy Zomer To: linux-kernel@vger.kernel.org Cc: Jordy Zomer , Sumit Semwal , Benjamin Gaignard , Liam Mark , Laura Abbott , Brian Starkey , John Stultz , =?UTF-8?q?Christian=20K=C3=B6nig?= , linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org Subject: [PATCH] dma-buf: heaps: Fix potential spectre v1 gadget Date: Sat, 29 Jan 2022 16:06:04 +0100 Message-Id: <20220129150604.3461652-1-jordy@pwning.systems> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: ClamAV using ClamSMTP Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" It appears like nr could be a Spectre v1 gadget as it's supplied by a user and used as an array index. Prevent the contents of kernel memory from being leaked to userspace via speculative execution by using array_index_nospec. Signed-off-by: Jordy Zomer Acked-by: John Stultz --- drivers/dma-buf/dma-heap.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/dma-buf/dma-heap.c b/drivers/dma-buf/dma-heap.c index 56bf5ad01ad5..8f5848aa144f 100644 --- a/drivers/dma-buf/dma-heap.c +++ b/drivers/dma-buf/dma-heap.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -135,6 +136,7 @@ static long dma_heap_ioctl(struct file *file, unsigned = int ucmd, if (nr >=3D ARRAY_SIZE(dma_heap_ioctl_cmds)) return -EINVAL; =20 + nr =3D array_index_nospec(nr, ARRAY_SIZE(dma_heap_ioctl_cmds)); /* Get the kernel ioctl cmd that matches */ kcmd =3D dma_heap_ioctl_cmds[nr]; =20 --=20 2.27.0