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 E162AEEB567 for ; Fri, 8 Sep 2023 18:22:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344405AbjIHSWU (ORCPT ); Fri, 8 Sep 2023 14:22:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57170 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245225AbjIHSVD (ORCPT ); Fri, 8 Sep 2023 14:21:03 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AECF22717; Fri, 8 Sep 2023 11:19:16 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A2322C433CB; Fri, 8 Sep 2023 18:18:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1694197126; bh=YvR4knq0LQJhkdyDueZsyjbvvnvnk0YhCZr0x5mFc5U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Qa43kIakLZb4xCvsd/a+3fE74B20iSQ7D6zep1ONC5TwqIyQP56KIYXEpMIEWRS17 1tPxuQCfUeg/8o4fIgQyxVV7XWR9L1F+IFLU1xhRZ2+4ISCItwQBB9q1Kt1wIk9UeM MT88l8zOVk/oM8ZEHm120VMZ1a20PnoOtU0iMBlWO0rf9nloY+SH7GSooWvWhGpfQv mK2nDsMwqJMcCLK/wvk4VAnIUHr93HzBIjbAPLATMJLlxbPFCvJ/gn0IoNj+dZhBz3 txRqO1CW6HT4NR2Aj7/lYEGSuTS9T+e6fJ8KpjaR/i6AwN3fioNCWLL9E74Wnx4FYR xWLQgIncjXlJw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Mark O'Donovan , Herbert Xu , Sasha Levin , zohar@linux.ibm.com Subject: [PATCH AUTOSEL 6.1 13/26] crypto: lib/mpi - avoid null pointer deref in mpi_cmp_ui() Date: Fri, 8 Sep 2023 14:17:51 -0400 Message-Id: <20230908181806.3460164-13-sashal@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230908181806.3460164-1-sashal@kernel.org> References: <20230908181806.3460164-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.1.52 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mark O'Donovan [ Upstream commit 9e47a758b70167c9301d2b44d2569f86c7796f2d ] During NVMeTCP Authentication a controller can trigger a kernel oops by specifying the 8192 bit Diffie Hellman group and passing a correctly sized, but zeroed Diffie Hellamn value. mpi_cmp_ui() was detecting this if the second parameter was 0, but 1 is passed from dh_is_pubkey_valid(). This causes the null pointer u->d to be dereferenced towards the end of mpi_cmp_ui() Signed-off-by: Mark O'Donovan Signed-off-by: Herbert Xu Signed-off-by: Sasha Levin --- lib/mpi/mpi-cmp.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/mpi/mpi-cmp.c b/lib/mpi/mpi-cmp.c index c4cfa3ff05818..0835b6213235e 100644 --- a/lib/mpi/mpi-cmp.c +++ b/lib/mpi/mpi-cmp.c @@ -25,8 +25,12 @@ int mpi_cmp_ui(MPI u, unsigned long v) mpi_limb_t limb = v; mpi_normalize(u); - if (!u->nlimbs && !limb) - return 0; + if (u->nlimbs == 0) { + if (v == 0) + return 0; + else + return -1; + } if (u->sign) return -1; if (u->nlimbs > 1) -- 2.40.1