Skip to content

Commit 1428cd7

Browse files
vladumrleon
authored andcommitted
IB/sa: Fix sa_local_svc_timeout_ms read race
When computing the delta, the sa_local_svc_timeout_ms is read without ib_nl_request_lock held. Though unlikely in practice, this can cause a race condition if multiple local service threads are managing the timeout. Fixes: 2ca546b ("IB/sa: Route SA pathrecord query through netlink") Signed-off-by: Vlad Dumitrescu <vdumitrescu@nvidia.com> Reviewed-by: Mark Zhang <markzhang@nvidia.com> Signed-off-by: Edward Srouji <edwards@nvidia.com> Link: https://patch.msgid.link/20250916163112.98414-1-edwards@nvidia.com Signed-off-by: Leon Romanovsky <leon@kernel.org>
1 parent 42f993d commit 1428cd7

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

drivers/infiniband/core/sa_query.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,14 +1074,15 @@ int ib_nl_handle_set_timeout(struct sk_buff *skb,
10741074
if (timeout > IB_SA_LOCAL_SVC_TIMEOUT_MAX)
10751075
timeout = IB_SA_LOCAL_SVC_TIMEOUT_MAX;
10761076

1077+
spin_lock_irqsave(&ib_nl_request_lock, flags);
1078+
10771079
delta = timeout - sa_local_svc_timeout_ms;
10781080
if (delta < 0)
10791081
abs_delta = -delta;
10801082
else
10811083
abs_delta = delta;
10821084

10831085
if (delta != 0) {
1084-
spin_lock_irqsave(&ib_nl_request_lock, flags);
10851086
sa_local_svc_timeout_ms = timeout;
10861087
list_for_each_entry(query, &ib_nl_request_list, list) {
10871088
if (delta < 0 && abs_delta > query->timeout)
@@ -1099,9 +1100,10 @@ int ib_nl_handle_set_timeout(struct sk_buff *skb,
10991100
if (delay)
11001101
mod_delayed_work(ib_nl_wq, &ib_nl_timed_work,
11011102
(unsigned long)delay);
1102-
spin_unlock_irqrestore(&ib_nl_request_lock, flags);
11031103
}
11041104

1105+
spin_unlock_irqrestore(&ib_nl_request_lock, flags);
1106+
11051107
settimeout_out:
11061108
return 0;
11071109
}

0 commit comments

Comments
 (0)