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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 24799C4707E for ; Mon, 7 Feb 2022 11:37:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1359846AbiBGL2r (ORCPT ); Mon, 7 Feb 2022 06:28:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34738 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1383602AbiBGLXD (ORCPT ); Mon, 7 Feb 2022 06:23:03 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4083DC043181; Mon, 7 Feb 2022 03:23:03 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id F1EEEB81028; Mon, 7 Feb 2022 11:23:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 291E6C004E1; Mon, 7 Feb 2022 11:22:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1644232980; bh=nEs+HGaOJHuIsOkXksCVRkggW7SHbU3hDrMDAHFVnfU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mTZnTUjrJCIDYQ7JyfE/Du5i7BbbYPVewhyc/oHAnDLI5PQq8+2qN77H9VcKlhDYS +kTiHRXrGP3NOyoXNgj3orZQrngb8wry3tkc9E2AJg04FwhBG+rPnQcb4p9fePIc2f 07MTBQIxFLqVyjSElDegKiKQ9Vrrpy+SwyjYDOBQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jordy Zomer , John Stultz , Sumit Semwal Subject: [PATCH 5.10 21/74] dma-buf: heaps: Fix potential spectre v1 gadget Date: Mon, 7 Feb 2022 12:06:19 +0100 Message-Id: <20220207103757.929587362@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220207103757.232676988@linuxfoundation.org> References: <20220207103757.232676988@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Jordy Zomer commit 92c4cfaee6872038563c5b6f2e8e613f9d84d47d upstream. 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 Fixes: c02a81fba74f ("dma-buf: Add dma-buf heaps framework") Cc: # v5.6+ Acked-by: John Stultz Signed-off-by: Sumit Semwal [sumits: added fixes and cc: stable tags] Link: https://patchwork.freedesktop.org/patch/msgid/20220129150604.3461652-1-jordy@pwning.systems Signed-off-by: Greg Kroah-Hartman --- drivers/dma-buf/dma-heap.c | 2 ++ 1 file changed, 2 insertions(+) --- 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 @@ -123,6 +124,7 @@ static long dma_heap_ioctl(struct file * if (nr >= ARRAY_SIZE(dma_heap_ioctl_cmds)) return -EINVAL; + nr = array_index_nospec(nr, ARRAY_SIZE(dma_heap_ioctl_cmds)); /* Get the kernel ioctl cmd that matches */ kcmd = dma_heap_ioctl_cmds[nr];