RDMA/core: fix refcount bug in iwpm_get_nlmsg_request()
Subsystems (2)
PATCH 1/1 RDMA/core: fix refcount bug in iwpm_get_nlmsg_request()
iwpm_get_nlmsg_request() initializes refcount _after_ list_add_tail() making it accessible to global list where another CPU can kref_get() on nlmsg_request causing a refcount "addition on 0" bug. Fix this by initializing kref _before_ list_add_tail() so refcount for nlmsg_request can be incremented/decremented normally.
--- drivers/infiniband/core/iwpm_util.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/infiniband/core/iwpm_util.c +2 -2
@@ -313,13 +313,13 @@ struct iwpm_nlmsg_request *iwpm_get_nlmsg_request(__u32 nlmsg_seq, nlmsg_request = kzalloc_obj(struct iwpm_nlmsg_request, gfp);if (!nlmsg_request)return NULL ; +kref_init (&nlmsg_request->kref); +kref_get (&nlmsg_request->kref);spin_lock_irqsave (&iwpm_nlmsg_req_lock, flags);list_add_tail (&nlmsg_request->inprocess_list, &iwpm_nlmsg_req_list);spin_unlock_irqrestore (&iwpm_nlmsg_req_lock, flags); -kref_init (&nlmsg_request->kref); -kref_get (&nlmsg_request->kref); nlmsg_request->nlmsg_seq = nlmsg_seq; nlmsg_request->nl_client = nl_client; nlmsg_request->request_done =0 ;
Signature · 1 line
2.55.0
Quoted 20 lines · Jeffin Philip
iwpm_get_nlmsg_request()initializes refcount _after_list_add_tail()making it accessible to global list where another CPU cankref_get()onnlmsg_requestcausing a refcount "addition on 0" bug. Fix this by initializing kref _before_list_add_tail()so refcount fornlmsg_requestcan be incremented/decremented normally.Reported-by [email protected]Fixes 30dc5e63d6a5 ("RDMA/core: Add support for iWARP Port Mapper user space service")Signed-off-by Jeffin Philip <[email protected]>--- drivers/infiniband/core/iwpm_util.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/infiniband/core/iwpm_util.c +0
-0
drivers/infiniband/core/iwpm_util.c struct iwpm_nlmsg_request *iwpm_get_nlmsg_request(__u32 nlmsg_seq, · line 321
Quoted 9 lines
drivers/infiniband/core/iwpm_util.c +2
-0@@ -313,13 +313,13 @@ struct iwpm_nlmsg_request *iwpm_get_nlmsg_request(__u32 nlmsg_seq, nlmsg_request = kzalloc_obj(struct iwpm_nlmsg_request, gfp);if (!nlmsg_request)return NULL ; +kref_init (&nlmsg_request->kref); +kref_get (&nlmsg_request->kref);spin_lock_irqsave (&iwpm_nlmsg_req_lock, flags);list_add_tail (&nlmsg_request->inprocess_list, &iwpm_nlmsg_req_list);spin_unlock_irqrestore (&iwpm_nlmsg_req_lock, flags);
These three lines need to be the last in the function, i.e. all fields must be initialized, not just the refcount.
Thanks
Quoted 9 lines
drivers/infiniband/core/iwpm_util.c +0
-2-kref_init (&nlmsg_request->kref); -kref_get (&nlmsg_request->kref); nlmsg_request->nlmsg_seq = nlmsg_seq; nlmsg_request->nl_client = nl_client; nlmsg_request->request_done =0 ;Signature · 1 line
2.55.0
PATCH v2 1/1 RDMA/core: fix refcount bug in iwpm_get_nlmsg_request()
In reply to Jeffin Philipiwpm_get_nlmsg_request() initializes refcount _after_ list_add_tail() making it accessible to global list where another CPU can kref_get() on nlmsg_request causing a refcount "addition on 0" bug. Fix this by initializing kref _before_ list_add_tail() so refcount for nlmsg_request can be incremented/decremented normally. In addition, also initialize every field before list_add_tail().
---
Changelog:
Changes in v2:
Add list_add_tail() last after initializing every field as per Leon Romanovsky's
suggestion.
--- drivers/infiniband/core/iwpm_util.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/infiniband/core/iwpm_util.c +6 -5
@@ -313,19 +313,20 @@ struct iwpm_nlmsg_request *iwpm_get_nlmsg_request(__u32 nlmsg_seq, nlmsg_request = kzalloc_obj(struct iwpm_nlmsg_request, gfp);if (!nlmsg_request)return NULL ; +kref_init (&nlmsg_request->kref);kref_get (&nlmsg_request->kref); - -spin_lock_irqsave (&iwpm_nlmsg_req_lock, flags); -list_add_tail (&nlmsg_request->inprocess_list, &iwpm_nlmsg_req_list); -spin_unlock_irqrestore (&iwpm_nlmsg_req_lock, flags); - nlmsg_request->nlmsg_seq = nlmsg_seq; nlmsg_request->nl_client = nl_client; nlmsg_request->request_done =0 ; nlmsg_request->err_code =0 ;sema_init (&nlmsg_request->sem,1 );down (&nlmsg_request->sem); + +spin_lock_irqsave (&iwpm_nlmsg_req_lock, flags); +list_add_tail (&nlmsg_request->inprocess_list, &iwpm_nlmsg_req_list); +spin_unlock_irqrestore (&iwpm_nlmsg_req_lock, flags); +return nlmsg_request; }
Signature · 1 line
2.55.0
Quoted 12 lines · Jeffin Philip
iwpm_get_nlmsg_request()initializes refcount _after_list_add_tail()making it accessible to global list where another CPU cankref_get()onnlmsg_requestcausing a refcount "addition on 0" bug. Fix this by initializing kref _before_list_add_tail()so refcount fornlmsg_requestcan be incremented/decremented normally. In addition, also initialize every field beforelist_add_tail().Reported-by [email protected]Fixes 30dc5e63d6a5 ("RDMA/core: Add support for iWARP Port Mapper user space service")Signed-off-by Jeffin Philip <[email protected]>
Quoted 8 lines
---
Changelog:
Changes in v2:
Addlist_add_tail()last after initializing every field as per Leon Romanovsky's
suggestion.--- drivers/infiniband/core/iwpm_util.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
The patch doesn't apply and please send it as standalone patch and not as Reply-to.
Thanks