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 7D644C4707F for ; Fri, 1 Apr 2022 15:26:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355738AbiDAPYn (ORCPT ); Fri, 1 Apr 2022 11:24:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44938 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349362AbiDAOzT (ORCPT ); Fri, 1 Apr 2022 10:55:19 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3A0591EAD1; Fri, 1 Apr 2022 07:43:34 -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 E1F6DB824AF; Fri, 1 Apr 2022 14:43:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A58B0C3410F; Fri, 1 Apr 2022 14:43:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1648824211; bh=vMIrxN8NS9at+zw+nGyIwEGRnhBh6lCHfDXAkv+0+Lo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=o4VbNWsfq0ok3+9n0CEFvHGdGAyywlvj2Uw/KsfMjfbM9y3wLaKiAdyhE8gqYLFXc rEtiomEQnjeekgTRqPsPllWXOAGVrFaCM+DK8wkLFZaS5e3g/ea6Wloj7I8ZYwUy2k 8oKyZACDRwy9fv2ssE2L0XQkx9cutg4kNzmGfbxUo21P4l3g33+VdFKFl2azagIFP9 pRmJ1YTwHFEtexK4TuSt2UpJwTtNbjzmvG/spm/b06O0B5Hc7L5J3iJa7+4UFiAjuL PF5AILkF9ySTR/Z2QNoNi15yIqdLTrgCB2fkh5oLlEXgbnHXOaduOuTaHNc16e9bgj GQjDVQpoutqhw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Jordy Zomer , Jordy Zomer , Mike Snitzer , Sasha Levin , agk@redhat.com, snitzer@kernel.org, dm-devel@redhat.com Subject: [PATCH AUTOSEL 5.10 30/65] dm ioctl: prevent potential spectre v1 gadget Date: Fri, 1 Apr 2022 10:41:31 -0400 Message-Id: <20220401144206.1953700-30-sashal@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220401144206.1953700-1-sashal@kernel.org> References: <20220401144206.1953700-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit 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 1ca65b434f1f..b839705654d4 100644 --- a/drivers/md/dm-ioctl.c +++ b/drivers/md/dm-ioctl.c @@ -17,6 +17,7 @@ #include #include #include +#include #include @@ -1696,6 +1697,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.34.1