From patchwork Sat Apr 1 06:38:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Saravanan Vajravel X-Patchwork-Id: 13196755 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 64BB6C76196 for ; Sat, 1 Apr 2023 06:39:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233511AbjDAGjG (ORCPT ); Sat, 1 Apr 2023 02:39:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50068 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233525AbjDAGip (ORCPT ); Sat, 1 Apr 2023 02:38:45 -0400 Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9CD0620C01 for ; Fri, 31 Mar 2023 23:38:22 -0700 (PDT) Received: by mail-pj1-x1035.google.com with SMTP id r7-20020a17090b050700b002404be7920aso23773856pjz.5 for ; Fri, 31 Mar 2023 23:38:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1680331095; h=mime-version:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=tXE0+earW/yc9PR5Ch2dVMpBcTMVxdDOWwuUrgBYHMc=; b=N/maePfnCS8aULUtUFQcSP6WBroZnGY6BEBQLmcN+oNxBwagyetrky/v52UZ/FS9jf wijBQFSXF21C7/MoKpgAlVLGmhbpqToihnc5qF9DY1uiPnfBucS70U2srHdM+kVJS/HN TnQabD+mYDeiHv4wwhZiYZOi4GzEGIL7JnjlU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680331095; h=mime-version:message-id:date:subject:cc:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=tXE0+earW/yc9PR5Ch2dVMpBcTMVxdDOWwuUrgBYHMc=; b=AUdvW9TP5x4FsmP0UO4/RZFCJ+AdnvGV5gZMj6HjrlfH7p5sLodvrQMVQaDMwOsgnJ X9hLman+zH0gJeKtePhKZZlzzdi0Cv27r5GNPWXjmIKsFgfLnNC+gz933nUbChqJiWH6 k0nYSw0UtC2R0h4cXUUt4Jv1666dzXddT2TQI0eoGTYUbnqZB+hNYaZBMrXm/V25KGfg /cVs9HEBTlzbqu9ZIloCmFPZA6K1kkFoe3g0YaUMqZWCIppj3Lr8Nfib8DYAQeicTyKu OYr1tBf1EMzdrLyEo9q657gXwIApK9ESXZ8fJLBkK+1VoZxZ6GMo+qt0FfZUjiWDkK+D gTIg== X-Gm-Message-State: AAQBX9cGxvAqXT1Gui/+P45Dngr8ufganu1oy4/xQURYwYjhdXkjQlId zNv3iDVwv0XJ3phRX4WTZOzaYAsrUgIlscFoHtg= X-Google-Smtp-Source: AKy350Yayz0cgDl9CYvTZOvk5Jzq1b/HWs4eZLnBXSj0XujYX9jeXGs+lIEh9RaD025qMgvAi2uJ6A== X-Received: by 2002:a17:902:d503:b0:19d:1720:3873 with SMTP id b3-20020a170902d50300b0019d17203873mr35554888plg.57.1680331094610; Fri, 31 Mar 2023 23:38:14 -0700 (PDT) Received: from localhost.localdomain ([192.19.252.250]) by smtp.gmail.com with ESMTPSA id u8-20020a170902a60800b001a045f45d49sm2590060plq.281.2023.03.31.23.38.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Mar 2023 23:38:14 -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 for-rc] RDMA/srpt: Add a check for valid 'mad_agent' pointer Date: Fri, 31 Mar 2023 23:38:00 -0700 Message-Id: <20230401063800.342432-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 --- drivers/infiniband/ulp/srpt/ib_srpt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/infiniband/ulp/srpt/ib_srpt.c b/drivers/infiniband/ulp/srpt/ib_srpt.c index 3c3fae738c3e..07c24182b085 100644 --- a/drivers/infiniband/ulp/srpt/ib_srpt.c +++ b/drivers/infiniband/ulp/srpt/ib_srpt.c @@ -634,7 +634,7 @@ static void srpt_unregister_mad_agent(struct srpt_device *sdev, int port_cnt) for (i = 1; i <= port_cnt; i++) { sport = &sdev->port[i - 1]; WARN_ON(sport->port != i); - if (sport->mad_agent) { + if (!IS_ERR_OR_NULL(sport->mad_agent)) { ib_modify_port(sdev->device, i, 0, &port_modify); ib_unregister_mad_agent(sport->mad_agent); sport->mad_agent = NULL;