diff mbox series

[for-rc] RDMA/srpt: Add a check for valid 'mad_agent' pointer

Message ID 20230401063800.342432-1-saravanan.vajravel@broadcom.com (mailing list archive)
State Superseded
Headers show
Series [for-rc] RDMA/srpt: Add a check for valid 'mad_agent' pointer | expand

Commit Message

Saravanan Vajravel April 1, 2023, 6:38 a.m. UTC
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 <selvin.xavier@broadcom.com>
Reviewed-by: Kashyap Desai <kashyap.desai@broadcom.com>
Signed-off-by: Saravanan Vajravel <saravanan.vajravel@broadcom.com>
---
 drivers/infiniband/ulp/srpt/ib_srpt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Jason Gunthorpe April 3, 2023, 2:41 p.m. UTC | #1
On Fri, Mar 31, 2023 at 11:38:00PM -0700, Saravanan Vajravel wrote:
> 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.

Don't fix it like this, don't store err values in global pointers.

Jason
Saravanan Vajravel April 4, 2023, 6:11 a.m. UTC | #2
> On Fri, Mar 31, 2023 at 11:38:00PM -0700, Saravanan Vajravel wrote:
> > 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.

> Don't fix it like this, don't store err values in global pointers.
Ok. I will re-work on the fix.

-Saravanan
diff mbox series

Patch

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;