diff mbox

IB/cma: Fix a race condition in iboe_addr_get_sgid()

Message ID 811914f1-3bcc-a0a4-e20a-86e8b5853ac7@acm.org (mailing list archive)
State Changes Requested
Headers show

Commit Message

Bart Van Assche Dec. 16, 2016, 1:39 p.m. UTC
Hello Moni,

Commit 7b85627b9f02 ("IB/cma: IBoE (RoCE) IP-based GID addressing") introduced code that
dereferences an RCU pointer without using rcu_read_lock(). Can you check whether the patch
below is the correct way to fix this?

Thanks,

Bart.

---
 include/rdma/ib_addr.h | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

Moni Shoua Dec. 18, 2016, 7:10 a.m. UTC | #1
On Fri, Dec 16, 2016 at 3:39 PM, Bart Van Assche
<bart.vanassche@gmail.com> wrote:
> Hello Moni,
>
> Commit 7b85627b9f02 ("IB/cma: IBoE (RoCE) IP-based GID addressing") introduced code that
> dereferences an RCU pointer without using rcu_read_lock(). Can you check whether the patch
> below is the correct way to fix this?
>
> Thanks,
>
> Bart.

Hi Bart
Fix looks good. Thanks

Reviewed-by: Moni Shoua <monis@mellanox.com>
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Doug Ledford Dec. 18, 2016, 6:39 p.m. UTC | #2
On 12/18/2016 2:10 AM, Moni Shoua wrote:
> On Fri, Dec 16, 2016 at 3:39 PM, Bart Van Assche
> <bart.vanassche@gmail.com> wrote:
>> Hello Moni,
>>
>> Commit 7b85627b9f02 ("IB/cma: IBoE (RoCE) IP-based GID addressing") introduced code that
>> dereferences an RCU pointer without using rcu_read_lock(). Can you check whether the patch
>> below is the correct way to fix this?
>>
>> Thanks,
>>
>> Bart.
> 
> Hi Bart
> Fix looks good. Thanks
> 
> Reviewed-by: Moni Shoua <monis@mellanox.com>

Bart, can you please resend this patch with a proper commit message and
a SOB tag?
diff mbox

Patch

diff --git a/include/rdma/ib_addr.h b/include/rdma/ib_addr.h
index 931a47ba4571..1beab5532035 100644
--- a/include/rdma/ib_addr.h
+++ b/include/rdma/ib_addr.h
@@ -205,10 +205,12 @@  static inline void iboe_addr_get_sgid(struct rdma_dev_addr *dev_addr,
 
 	dev = dev_get_by_index(&init_net, dev_addr->bound_dev_if);
 	if (dev) {
-		ip4 = (struct in_device *)dev->ip_ptr;
-		if (ip4 && ip4->ifa_list && ip4->ifa_list->ifa_address)
+		ip4 = in_dev_get(dev);
+		if (ip4 && ip4->ifa_list && ip4->ifa_list->ifa_address) {
 			ipv6_addr_set_v4mapped(ip4->ifa_list->ifa_address,
 					       (struct in6_addr *)gid);
+			in_dev_put(ip4);
+		}
 		dev_put(dev);
 	}
 }