From patchwork Thu Apr 6 04:25:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Saravanan Vajravel X-Patchwork-Id: 13202852 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 7663FC7618D for ; Thu, 6 Apr 2023 04:26:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232797AbjDFE0G (ORCPT ); Thu, 6 Apr 2023 00:26:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231696AbjDFE0E (ORCPT ); Thu, 6 Apr 2023 00:26:04 -0400 Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9072D7AAC for ; Wed, 5 Apr 2023 21:26:03 -0700 (PDT) Received: by mail-pj1-x102b.google.com with SMTP id mp3-20020a17090b190300b0023fcc8ce113so41707540pjb.4 for ; Wed, 05 Apr 2023 21:26:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1680755163; x=1683347163; h=mime-version:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=SR3Rk1MtedXhtg26U+8+OSNXS80zF5zmlSqQIur/4+o=; b=LWFjYwhw7bXCqrmIPok1nuXz8PSxQHXSjHMyYegDdMUvWio+lj86Kppoa0CEdM7CNw RdGZ1z3tFLTIexIpo6U86S2rzQMxzrb3qmiVeaCnbHhcaD0bw0jpznh98/pEpZySeh0a 7ObVKwF6XFW3LF7ZI5QpAWojea1/DD27ObaW4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680755163; x=1683347163; h=mime-version:message-id:date:subject:cc:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=SR3Rk1MtedXhtg26U+8+OSNXS80zF5zmlSqQIur/4+o=; b=u/26y1YDxQEn/wAngc1vPLyArQDSBRR2GSNaBYmgSEs1vdmmh5RuVvT90OQ0dDMJFe DFGva902sE0/CaOj0GqQjPMXLXQVEe2PE+uF3FoK+fJpicOLycCWYjh2/inu4azZdB9X AeU1EsRWLpMZAvvQHeiDs6FvGwFqBRr8ekQdtaXK6OjcK2whHx4eujpRcarAarioK/iB wCqz8dmgh6VHmzuefC6L2z2U3KXgclb+iOFHpg3nLl9p7lF7ncGCS9yehnx4mgu89AFj Gb+CVV59ILUpTzPQhzOMQc9LXNCmdkpIReb2Ezi8dGraBAM8rIOyOuEmjONBb0U793uf lBlg== X-Gm-Message-State: AAQBX9ei7Pc/kios/j3t35KS7Gp2n1rEOjmupnTkije6IAPNXFd/Rm4M AloG+M0tolwUJEEUnIdpDKUkEQ== X-Google-Smtp-Source: AKy350alKZPjCqOJQ3BWFA+kDx2IE4lC173ROymKm8I62VF3pMmpR1FXSQ5oXSftANUNEEPIbtVh+A== X-Received: by 2002:a17:903:1246:b0:1a2:9ce6:6483 with SMTP id u6-20020a170903124600b001a29ce66483mr9917125plh.64.1680755162593; Wed, 05 Apr 2023 21:26:02 -0700 (PDT) Received: from localhost.localdomain ([192.19.234.250]) by smtp.gmail.com with ESMTPSA id s7-20020a170902988700b0019f1027f88bsm309911plp.307.2023.04.05.21.25.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 21:26:01 -0700 (PDT) From: Saravanan Vajravel To: jgg@ziepe.ca, leon@kernel.org Cc: linux-rdma@vger.kernel.org, Saravanan Vajravel , Selvin Xavier , Kashyap Desai Subject: [PATCH v2 for-rc] RDMA/srpt: Add a check for valid 'mad_agent' pointer Date: Wed, 5 Apr 2023 21:25:49 -0700 Message-Id: <20230406042549.507328-1-saravanan.vajravel@broadcom.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org When unregistering MAD agent, srpt module has a non-null check for 'mad_agent' pointer before invoking ib_unregister_mad_agent(). This check can pass if 'mad_agent' variable holds an error value. The 'mad_agent' can have an error value for a short window when srpt_add_one() and srpt_remove_one() is executed simultaneously. In srpt module, added a valid pointer check for 'sport->mad_agent' before unregistering MAD agent. This issue can hit when RoCE driver unregisters ib_device Stack Trace: ------------ BUG: kernel NULL pointer dereference, address: 000000000000004d PGD 145003067 P4D 145003067 PUD 2324fe067 PMD 0 Oops: 0002 [#1] PREEMPT SMP NOPTI CPU: 10 PID: 4459 Comm: kworker/u80:0 Kdump: loaded Tainted: P Hardware name: Dell Inc. PowerEdge R640/06NR82, BIOS 2.5.4 01/13/2020 Workqueue: bnxt_re bnxt_re_task [bnxt_re] RIP: 0010:_raw_spin_lock_irqsave+0x19/0x40 Call Trace: ib_unregister_mad_agent+0x46/0x2f0 [ib_core] IPv6: ADDRCONF(NETDEV_CHANGE): bond0: link becomes ready ? __schedule+0x20b/0x560 srpt_unregister_mad_agent+0x93/0xd0 [ib_srpt] srpt_remove_one+0x20/0x150 [ib_srpt] remove_client_context+0x88/0xd0 [ib_core] bond0: (slave p2p1): link status definitely up, 100000 Mbps full duplex disable_device+0x8a/0x160 [ib_core] bond0: active interface up! ? kernfs_name_hash+0x12/0x80 (NULL device *): Bonding Info Received: rdev: 000000006c0b8247 __ib_unregister_device+0x42/0xb0 [ib_core] (NULL device *): Master: mode: 4 num_slaves:2 ib_unregister_device+0x22/0x30 [ib_core] (NULL device *): Slave: id: 105069936 name:p2p1 link:0 state:0 bnxt_re_stopqps_and_ib_uninit+0x83/0x90 [bnxt_re] bnxt_re_alloc_lag+0x12e/0x4e0 [bnxt_re] Fixes: a42d985bd5b2 ("ib_srpt: Initial SRP Target merge for v3.3-rc1") Reviewed-by: Selvin Xavier Reviewed-by: Kashyap Desai Signed-off-by: Saravanan Vajravel Reviewed-by: Bart Van Assche --- v1->v2: - Return pointer of mad_agent is stored in local pointer to verify if it is successfully registered drivers/infiniband/ulp/srpt/ib_srpt.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/drivers/infiniband/ulp/srpt/ib_srpt.c b/drivers/infiniband/ulp/srpt/ib_srpt.c index 3c3fae738c3e..b4cb88563bb2 100644 --- a/drivers/infiniband/ulp/srpt/ib_srpt.c +++ b/drivers/infiniband/ulp/srpt/ib_srpt.c @@ -549,6 +549,7 @@ static int srpt_format_guid(char *buf, unsigned int size, const __be64 *guid) */ static int srpt_refresh_port(struct srpt_port *sport) { + struct ib_mad_agent *mad_agent; struct ib_mad_reg_req reg_req; struct ib_port_modify port_modify; struct ib_port_attr port_attr; @@ -593,23 +594,24 @@ static int srpt_refresh_port(struct srpt_port *sport) set_bit(IB_MGMT_METHOD_GET, reg_req.method_mask); set_bit(IB_MGMT_METHOD_SET, reg_req.method_mask); - sport->mad_agent = ib_register_mad_agent(sport->sdev->device, - sport->port, - IB_QPT_GSI, - ®_req, 0, - srpt_mad_send_handler, - srpt_mad_recv_handler, - sport, 0); - if (IS_ERR(sport->mad_agent)) { + mad_agent = ib_register_mad_agent(sport->sdev->device, + sport->port, + IB_QPT_GSI, + ®_req, 0, + srpt_mad_send_handler, + srpt_mad_recv_handler, + sport, 0); + if (IS_ERR(mad_agent)) { pr_err("%s-%d: MAD agent registration failed (%ld). Note: this is expected if SR-IOV is enabled.\n", dev_name(&sport->sdev->device->dev), sport->port, - PTR_ERR(sport->mad_agent)); + PTR_ERR(mad_agent)); sport->mad_agent = NULL; memset(&port_modify, 0, sizeof(port_modify)); port_modify.clr_port_cap_mask = IB_PORT_DEVICE_MGMT_SUP; ib_modify_port(sport->sdev->device, sport->port, 0, &port_modify); - + } else { + sport->mad_agent = mad_agent; } }