Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3091709rwb; Mon, 15 Aug 2022 17:55:38 -0700 (PDT) X-Google-Smtp-Source: AA6agR7TyA0V6Hnd+cEgfmeGb2dSSo/oyFDYO5iRbeC7eWMZdO+jX848hvML1FqNN8LDNF8gdYWe X-Received: by 2002:a17:906:8a45:b0:730:9715:369d with SMTP id gx5-20020a1709068a4500b007309715369dmr11815967ejc.105.1660611337887; Mon, 15 Aug 2022 17:55:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660611337; cv=none; d=google.com; s=arc-20160816; b=PBm/z3TB7vIjS4ROQgxqgJLs1NwGc1e01JWRiMBe8nu5keeTMn60Y/e4D+r4WwxN5L 0nPet6kgj8hk1uWIcO0edeUyq8Vf6/sE8AqRnUKfRCUn2AevDrES/XqC/0Zg0waxU/WN E3XmdcpV/vqjT4P6p59iZqtC5aQtWiyyBEjw71poNcGag8Lu+i0mSC2O0y0eakml+INi q2y9G7pPWMfN24FNzTFRosXJghXdiJzRB0qPOOyEqjODq0UmqrSxZmXFDQ5U+bIwVFaS VcvPA5CAvFI3vB9ZbWZvOM+/g/i6JXqjYCW0TvaN7z33sOk1UVEkCPQRxtpnVVAscePW yHgA== 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=/ryVvYdcKfO1CoHuJRhk7iMTe59pdOgo6pDWbE27HsQ=; b=FPIZkJBVsmJz0yTMTZoqepHmdSCuC1zCXiufAoF2qG6svNPJv/f7LSKDCX5KAW/7tu P3C8RIx8/dQmAyXqa13uKZlZxoW1QoTIh46QqqBXvnnGcfYro2pkLAoxpp3B+vqn9bo7 GTWydgRqrbuKwh0mog9BtxFE6UeyAquvmTgWtPg85tBks26ocVHVBr0ywjW96qZJ9yE5 vw178uVv0C+9w6L67w/6Tw1xYX8jPpdgcuY5P9JXcnfUXMm3gCd3fM9KiFyTZeEI68Kb H7sSLads+UwYTlGTWBxtEnpoUhWKRF9GzQKEvGFrGasvSX579FwXX0cvc0a+FyQkZMRb vhvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=GyEB22cP; 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 ne18-20020a1709077b9200b0073860fb87ddsi2732673ejc.487.2022.08.15.17.55.11; Mon, 15 Aug 2022 17:55:37 -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=GyEB22cP; 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 S1344695AbiHPAcE (ORCPT + 99 others); Mon, 15 Aug 2022 20:32:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229939AbiHPAaK (ORCPT ); Mon, 15 Aug 2022 20:30:10 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D003F183122; Mon, 15 Aug 2022 13:35: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 5A490B811A5; Mon, 15 Aug 2022 20:34:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id ABC55C433C1; Mon, 15 Aug 2022 20:34:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660595695; bh=0DD4p/4boBuJc0WUfW/tRCXt/2UI7dH2bDTdd2p/vnw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GyEB22cPDCcCbpDtTbQeSYL3whCy8qeACyAlObdHy55YyPESp+a0SHGaS8w56gDGS bhmQZ7nJnFAa4SGOGPSFy84bsNfu0FYQRGVrKCqInY34UXFnYioe6YJ1mgxFlKduoN VpHv2wVccF/g4dsCHml/+er2IU3n+Czv4iWE+h/Q= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Zhu Yanjun , Bob Pearson , Md Haris Iqbal , Leon Romanovsky , Sasha Levin Subject: [PATCH 5.19 0828/1157] RDMA/rxe: Fix BUG: KASAN: null-ptr-deref in rxe_qp_do_cleanup Date: Mon, 15 Aug 2022 20:03:04 +0200 Message-Id: <20220815180512.603314197@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180439.416659447@linuxfoundation.org> References: <20220815180439.416659447@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 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: Zhu Yanjun [ Upstream commit 37da51efe6eaa0560f46803c8c436a48a2084da7 ] The function rxe_create_qp calls rxe_qp_from_init. If some error occurs, the error handler of function rxe_qp_from_init will set both scq and rcq to NULL. Then rxe_create_qp calls rxe_put to handle qp. In the end, rxe_qp_do_cleanup is called by rxe_put. rxe_qp_do_cleanup directly accesses scq and rcq before checking them. This will cause null-ptr-deref error. The call graph is as below: rxe_create_qp { ... rxe_qp_from_init { ... err1: ... qp->rcq = NULL; <---rcq is set to NULL qp->scq = NULL; <---scq is set to NULL ... } qp_init: rxe_put{ ... rxe_qp_do_cleanup { ... atomic_dec(&qp->scq->num_wq); <--- scq is accessed ... atomic_dec(&qp->rcq->num_wq); <--- rcq is accessed } } Fixes: 4703b4f0d94a ("RDMA/rxe: Enforce IBA C11-17") Link: https://lore.kernel.org/r/20220705225414.315478-1-yanjun.zhu@linux.dev Signed-off-by: Zhu Yanjun Reviewed-by: Bob Pearson Reviewed-by: Md Haris Iqbal Signed-off-by: Leon Romanovsky Signed-off-by: Sasha Levin --- drivers/infiniband/sw/rxe/rxe_qp.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/infiniband/sw/rxe/rxe_qp.c b/drivers/infiniband/sw/rxe/rxe_qp.c index 22e9b85344c3..b79e1b43454e 100644 --- a/drivers/infiniband/sw/rxe/rxe_qp.c +++ b/drivers/infiniband/sw/rxe/rxe_qp.c @@ -804,13 +804,15 @@ static void rxe_qp_do_cleanup(struct work_struct *work) if (qp->rq.queue) rxe_queue_cleanup(qp->rq.queue); - atomic_dec(&qp->scq->num_wq); - if (qp->scq) + if (qp->scq) { + atomic_dec(&qp->scq->num_wq); rxe_put(qp->scq); + } - atomic_dec(&qp->rcq->num_wq); - if (qp->rcq) + if (qp->rcq) { + atomic_dec(&qp->rcq->num_wq); rxe_put(qp->rcq); + } if (qp->pd) rxe_put(qp->pd); -- 2.35.1