Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1552752pxb; Tue, 8 Feb 2022 22:03:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJwmebfXGAzr6m2CBKkcH7DyCJI6jFRENYk6HmKhcLmzgBmyHVvIfatMCFDjV7tUfoqlw2FN X-Received: by 2002:a63:8949:: with SMTP id v70mr703364pgd.496.1644386619990; Tue, 08 Feb 2022 22:03:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644386619; cv=none; d=google.com; s=arc-20160816; b=xmakrRNVRDD9FsIRJjTpJBYwpiaSGcdx7Ncn+fbtu5nyzhMo7+ip8KWLllGfQp4EZF VeVRk+xNZKZD1BLvUDUGjwvJyiXqW9tPQRFhgAIe+G87n9nygKieC5lWekt7yiXozFz0 ZViyT5yRCJDMgtBVOOm/uzDPG2A8opt0vdFFYfStABx6ZLVfzsQRDqieQXf5+ZRbu1+0 C4zXVfq40HgbfsneWAA+fljRuIrj10di5zXFEeNlS00P734pjO8zXXuSn49bnqkmjfuE 3APx9UHHwXJzaluISlijRoKIjNuXOb9FXX6UfdxAT7cakC9N3wiRHbzInD6BfWJ4xb/l en0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=AUC+WGTIlvFuA4gdD/V5E07HC9RgjGzP0rYST5TsTqE=; b=BrHV3pbvpwU3mrkL09or5WeU1TuR/wjjUfv0Ndk+04a+eSc0lDnDH9UsTLAcoZaZH4 h7Tg3ZMsXKUAUxMLrhNxai23B+dLOVnf63h+hvLGJLxKbRt4PRUdDLvad7a+an9dWWWr sUlVLN7vxuQbX9BNnXrn5FBXKSM3lvbvb3+CEskhG0InMEBCmD+U6vt1p1Ug5Jihi9DD Q2do7Jm6Gjt54eFzvchJk9mq8SLFSfvUmnrpdp8lbn/hTm3ms5JwPUeiiITmKJNUPw03 0bayofKOuaL8Jzb9QsPlpCfiBiwBt5BgMBfbHnp7bAtSDEUy+2JJbU+DWIZGrKd2C5RU HHbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=TQ96lTID; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id o12si13856428pll.457.2022.02.08.22.03.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 22:03:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=TQ96lTID; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B2D08C0DE7DD; Tue, 8 Feb 2022 21:52:16 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1388256AbiBGLnR (ORCPT + 99 others); Mon, 7 Feb 2022 06:43:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1385680AbiBGLcG (ORCPT ); Mon, 7 Feb 2022 06:32:06 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 49DC9C0401D2; Mon, 7 Feb 2022 03:31:51 -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 DD8A8B811A6; Mon, 7 Feb 2022 11:31:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C3824C004E1; Mon, 7 Feb 2022 11:31:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1644233508; bh=n9ts40NzW/gNgiYJSJZjAg4qmKmz5RkYXFbhssIVcNM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TQ96lTIDG8I5CUJToi1mE5Axn7Ph7YUezwQzkwh/7KoY/14LOKfhFXYPx1S0PkAcF WFeAesJCmUVZvXkrCZrFKiUphOWJVXkCY1bdcrV+HplUyOfX6EZQtW7F2Yjbari5zf IS23lqYytpfCwmZoYdbTFrrAJpn7Fd6KclrIts4I= 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.16 035/126] dma-buf: heaps: Fix potential spectre v1 gadget Date: Mon, 7 Feb 2022 12:06:06 +0100 Message-Id: <20220207103805.354301991@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220207103804.053675072@linuxfoundation.org> References: <20220207103804.053675072@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 @@ -135,6 +136,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];