From patchwork Mon Jul 24 00:07:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark O'Donovan X-Patchwork-Id: 124570 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9010:0:b0:3e4:2afc:c1 with SMTP id l16csp1493972vqg; Sun, 23 Jul 2023 17:37:07 -0700 (PDT) X-Google-Smtp-Source: APBJJlHxFMV4Rp3OVxlqoTwq+20+JZMhnuhK02w+4Tv+3Q/f7l8RyXVFPtK73poY5558gKXu4Zdy X-Received: by 2002:a17:906:3f1e:b0:99b:504d:d9c7 with SMTP id c30-20020a1709063f1e00b0099b504dd9c7mr9204143ejj.67.1690159026818; Sun, 23 Jul 2023 17:37:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690159026; cv=none; d=google.com; s=arc-20160816; b=vIebnwkLK4eAmAICoGHJsDKSVdHflhSzGZ+2+Bvf+v4jymbm0h7t8Zs5mC3+7ytWQR k+PDBdDdxeXgETlJM7aBlSvDhchctjr/0DwxCTb8KjM/GfyBzgreFaQpzPpeAwTcQw+S nq3eQVJdKjDNHrf1vvhZBEce3jyIwn9I6brZ9zLRwT3BPQc4SpeHlAPR54AtXxthWb1F JuvuWoav9XQ9d+i6Xj5CngsEWplkP5qKYRpuTituJxwpYXOSlbcdcrL65k2ne83+aHso oN4FIRy1RA9mMxWcNjHLL/gqiLOisSr3OQ+ZF+PYfrQ8uiN+0QhMZes4TdTV4k8p21NA 5AoA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=JspPptF7F8DFVxZdcUlMlVQ6i6FW7Eq0nkwtmsjDzJI=; fh=GQ5Rg83Yurra7nbbGlhq23R/Y+ZNvW1QafzRyMU2QOU=; b=ycnykRUhLU3JdFI9t/1K/6FH9BcgNrPOELF0JpCJR5dhnCanOrXlkW6pQ1yBIYLUUS hEG9kP9UoqPuY0f2Sx4xLlkT7EnnUth0vVc5o+uQNuOK5/HY1mJbJIavfZc+Rj09ZpiI P6krvMJF+afrXy8+aE7h+SzlLYLdK5pOKmsRgcujXmOJOMc6v9WuRRQhahZXwgW1Smns VWa800lLSMmZY3hO/T9PiQs0ADre0Khrc1ns7UPVPZ32gri82NeTKVS8nI2jvMaxIBco wbXB3Mwc6QvH1fGCdz4yoIr6oCTPKnfDsTMKSK8sNQ8div3Y5+U1P6jxcwSsNajn4f+I 2aNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@posteo.net header.s=2017 header.b=sBBbeiak; 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=posteo.net Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v21-20020a170906565500b00997d315d050si5696350ejr.84.2023.07.23.17.36.43; Sun, 23 Jul 2023 17:37:06 -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=@posteo.net header.s=2017 header.b=sBBbeiak; 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=posteo.net Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229578AbjGXAQH (ORCPT + 99 others); Sun, 23 Jul 2023 20:16:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229468AbjGXAQF (ORCPT ); Sun, 23 Jul 2023 20:16:05 -0400 Received: from mout01.posteo.de (mout01.posteo.de [185.67.36.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 93AFDA1 for ; Sun, 23 Jul 2023 17:16:01 -0700 (PDT) Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id E40B3240027 for ; Mon, 24 Jul 2023 02:15:57 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1690157757; bh=Hg8+Ie5zk1+PShUsC8fZxv3X5pNkB2BeLLwMP1rWmCU=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version: Content-Transfer-Encoding:From; b=sBBbeiakXr27M7ivOxfE/BgSC+dbgyQWJJMeduwlCz6HZTxfBZHYRV2D1JHsAXwdF 3mzlRUB8qvyl09hcJQD9seimcZZLhvPPatkl1OeqYidSDrP8GlxjLkNIe4IegLlazT WcKsuqnaqjrEP6E249TBLKsaUo1xhRetVe+d8ay9cc2MpfXvPpaDXDutHScbL46oBa sCYfpNq7bKDLJFPm8LrvWP8frJiZ8sBA4vX5/onf+ydZOYifjntOrP5QkcLA3FdwWm 4OCan+DGBOjII2yncezKlhFDKbPwYwMkkO6HN7V0Du1qn6p40P1TUZAVx8QcUUrRj9 nNXIyvgnnvkPQ== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4R8LKl6WB3z6v1M; Mon, 24 Jul 2023 02:15:55 +0200 (CEST) From: Mark O'Donovan To: linux-kernel@vger.kernel.org Cc: ebiggers@google.com, herbert@gondor.apana.org.au, Mark O'Donovan Subject: [PATCH] lib/mpi: avoid null pointer deref in mpi_cmp_ui() Date: Mon, 24 Jul 2023 00:07:27 +0000 Message-Id: <20230724000727.3281733-1-shiftee@posteo.net> MIME-Version: 1.0 X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772260191874351744 X-GMAIL-MSGID: 1772260191874351744 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 --- 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 c4cfa3ff0581..0835b6213235 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)