From nobody Mon Sep 29 22:37:13 2025 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 08883C00140 for ; Tue, 16 Aug 2022 00:35:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344515AbiHPAfS (ORCPT ); Mon, 15 Aug 2022 20:35:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39832 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354437AbiHPAbg (ORCPT ); Mon, 15 Aug 2022 20:31:36 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 204711863DF; Mon, 15 Aug 2022 13:36:26 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 02B05611FC; Mon, 15 Aug 2022 20:36:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E82B3C433C1; Mon, 15 Aug 2022 20:36:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660595785; bh=O4VsfSvrkHLPukgOIZyFQnOLBzYYT1KIKkld0aEIQnI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ELSqczw7XgTp12+gjCqvFzHxfOf/det56RUjwlmZlHpIlVJK1B9h8ZNbEC+I7+vWM Dtxwjog1In/iHTQ6GX7eM5l6h+/bqwPkD3+6Oxvj/9QJYVGUmFnk18/oohHIyBhDKm ngC8RUqPJvjcFNAT9fOVc0NFCHRjrc6jbG/pZ9R0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+833061116fa28df97f3b@syzkaller.appspotmail.com, Zhu Yanjun , Jason Gunthorpe , Sasha Levin Subject: [PATCH 5.19 0875/1157] RDMA/rxe: Fix error unwind in rxe_create_qp() Date: Mon, 15 Aug 2022 20:03:51 +0200 Message-Id: <20220815180514.457627236@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-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Zhu Yanjun [ Upstream commit fd5382c5805c4bcb50fd25b7246247d3f7114733 ] In the function rxe_create_qp(), rxe_qp_from_init() is called to initialize qp, internally things like the spin locks are not setup until rxe_qp_init_req(). If an error occures before this point then the unwind will call rxe_cleanup() and eventually to rxe_qp_do_cleanup()/rxe_cleanup_task() which will oops when trying to access the uninitialized spinlock. Move the spinlock initializations earlier before any failures. Fixes: 8700e3e7c485 ("Soft RoCE driver") Link: https://lore.kernel.org/r/20220731063621.298405-1-yanjun.zhu@linux.dev Reported-by: syzbot+833061116fa28df97f3b@syzkaller.appspotmail.com Signed-off-by: Zhu Yanjun Signed-off-by: Jason Gunthorpe Signed-off-by: Sasha Levin --- drivers/infiniband/sw/rxe/rxe_qp.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/infiniband/sw/rxe/rxe_qp.c b/drivers/infiniband/sw/rxe= /rxe_qp.c index 834f40ad00af..fd706dc3009d 100644 --- a/drivers/infiniband/sw/rxe/rxe_qp.c +++ b/drivers/infiniband/sw/rxe/rxe_qp.c @@ -174,6 +174,14 @@ static void rxe_qp_init_misc(struct rxe_dev *rxe, stru= ct rxe_qp *qp, =20 spin_lock_init(&qp->state_lock); =20 + spin_lock_init(&qp->req.task.state_lock); + spin_lock_init(&qp->resp.task.state_lock); + spin_lock_init(&qp->comp.task.state_lock); + + spin_lock_init(&qp->sq.sq_lock); + spin_lock_init(&qp->rq.producer_lock); + spin_lock_init(&qp->rq.consumer_lock); + atomic_set(&qp->ssn, 0); atomic_set(&qp->skb_out, 0); } @@ -233,7 +241,6 @@ static int rxe_qp_init_req(struct rxe_dev *rxe, struct = rxe_qp *qp, qp->req.opcode =3D -1; qp->comp.opcode =3D -1; =20 - spin_lock_init(&qp->sq.sq_lock); skb_queue_head_init(&qp->req_pkts); =20 rxe_init_task(rxe, &qp->req.task, qp, @@ -284,9 +291,6 @@ static int rxe_qp_init_resp(struct rxe_dev *rxe, struct= rxe_qp *qp, } } =20 - spin_lock_init(&qp->rq.producer_lock); - spin_lock_init(&qp->rq.consumer_lock); - skb_queue_head_init(&qp->resp_pkts); =20 rxe_init_task(rxe, &qp->resp.task, qp, --=20 2.35.1