Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp3052514pxb; Mon, 18 Apr 2022 14:35:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwAXU2dqUSvz/ft4d1HFYC9XgYItZva/GgCjiWVM4QLt0+o0mTbq3K1uZgiZekeufvb1Ir8 X-Received: by 2002:aa7:d658:0:b0:41d:7875:74bf with SMTP id v24-20020aa7d658000000b0041d787574bfmr14530339edr.415.1650317724727; Mon, 18 Apr 2022 14:35:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650317724; cv=none; d=google.com; s=arc-20160816; b=smIy73LaQrNGdDgpUgqxT1QVZosOY2gt4PUzUlMAANluBlHZ0aVFz/ukbfv8bG5FOI rZIZ0oLm+5pNBlpW2Nkv8V/wUIn6C4eb41e0MWdmNJEf2hiYalDM3bA2NdogBSG8mlHs 5l3LesSO/4wZCqUaWw11/icxVj14oFKQcK6zUaeCZejTHkNvZDNZAIDbLVIQdzrw4MXp 8KFZZQew3GXNGY1W4BZMBj0qvKho/EEIZB2AVfMoB5lJncU3ZKcJOXn3OuaRO2BWeULv egrH5ReNYG+PfVDUt/dWIpJoP8w6pF7GCtrBixEjcQFCy5W8M6ZsCVjXOPtx/YBllVfR oaXQ== 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=77/0D9IGMV8vlt+Wkf5dhEXTel51buJv8XD++FPdyFA=; b=b89xp/98sER+8RCOdT8Jid+/tz7yS0BV+MmSh/hTEHTpU5/UaFteDVD61hYUYXe/5J D39eL4GKfgWbwhq9+fS5r5p+qF/DF+UPFn+/VsaXQYL7qWQ3Yg2wRhFhmFYAEgS4lF8j 8HIo36wFzwCBU6qQajWe4vtRkIqyPAYfiHcz2ENKxjktfLcsjERrZkXiGaV3pkUr6au5 LIHhzD0NMGpJgC6Lp7yiAPBvaAjssE7DG6bocMwhZ/g0rAF7L8xZvBl+Ti98G4y/N7UZ 9CayNL0qUW3qNwCXpBPy1/4I+fEowmT6NTLxoukejWTNL5VP269e+e+2FkZEd6jO94iM n9Fw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=wQaiV9ac; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f10-20020a50d54a000000b0041d7a88d1d3si7065825edj.552.2022.04.18.14.35.00; Mon, 18 Apr 2022 14:35:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=wQaiV9ac; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245578AbiDRODh (ORCPT + 99 others); Mon, 18 Apr 2022 10:03:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53462 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244780AbiDRNpk (ORCPT ); Mon, 18 Apr 2022 09:45:40 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B849205F5; Mon, 18 Apr 2022 06:00:25 -0700 (PDT) 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 E49BFB80E44; Mon, 18 Apr 2022 13:00:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2F26FC385A7; Mon, 18 Apr 2022 13:00:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1650286822; bh=Zmh5s7d09YAzmtjSG3+elX6lEV9DbTZeCH2PMpbnWLY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wQaiV9acO21j+8s0hg5u6xLv7D5sS2yNn67upcWAUHgGVA5K0vRULPmUIGgC8lme0 LyvI2zFXdSl96T79nP6e40qlTr8CqPQBqfFlhLshrIf6+VwdoB+cIP+PeugD2tuOfn mri6N5oxBkxbzREzEkJ34sfrLy1aeLRr9vtxA7ko= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jordy Zomer , Mike Snitzer , Sasha Levin Subject: [PATCH 4.14 216/284] dm ioctl: prevent potential spectre v1 gadget Date: Mon, 18 Apr 2022 14:13:17 +0200 Message-Id: <20220418121217.856428572@linuxfoundation.org> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220418121210.689577360@linuxfoundation.org> References: <20220418121210.689577360@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.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 [ Upstream commit cd9c88da171a62c4b0f1c70e50c75845969fbc18 ] It appears like cmd 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 Signed-off-by: Mike Snitzer Signed-off-by: Sasha Levin --- drivers/md/dm-ioctl.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c index 2f020401d5ba..ddfea5324b58 100644 --- a/drivers/md/dm-ioctl.c +++ b/drivers/md/dm-ioctl.c @@ -17,6 +17,7 @@ #include #include #include +#include #include @@ -1669,6 +1670,7 @@ static ioctl_fn lookup_ioctl(unsigned int cmd, int *ioctl_flags) if (unlikely(cmd >= ARRAY_SIZE(_ioctls))) return NULL; + cmd = array_index_nospec(cmd, ARRAY_SIZE(_ioctls)); *ioctl_flags = _ioctls[cmd].flags; return _ioctls[cmd].fn; } -- 2.35.1