From patchwork Mon Dec 19 17:00:05 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 9480613 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E2C5F60237 for ; Mon, 19 Dec 2016 17:28:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D80D528402 for ; Mon, 19 Dec 2016 17:28:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CC58128406; Mon, 19 Dec 2016 17:28:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8901828402 for ; Mon, 19 Dec 2016 17:28:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932480AbcLSR2J (ORCPT ); Mon, 19 Dec 2016 12:28:09 -0500 Received: from ant-001.se.1eurohost.be ([5.134.1.73]:33237 "EHLO ant-001.se.1eurohost.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932362AbcLSR2I (ORCPT ); Mon, 19 Dec 2016 12:28:08 -0500 X-Greylist: delayed 1667 seconds by postgrey-1.27 at vger.kernel.org; Mon, 19 Dec 2016 12:28:08 EST Received: from vz23.stone-is.net ([87.238.162.216]) by sf2.bxl.stone.is with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.86) (envelope-from ) id 1cJ1IG-0002A2-3r; Mon, 19 Dec 2016 18:00:11 +0100 Received: from exp-402881.sandisk.com (178-117-55-239.access.telenet.be [178.117.55.239]) by vz23.stone-is.net (Postfix) with ESMTPSA id 49ACC120C42C; Mon, 19 Dec 2016 18:00:06 +0100 (CET) To: Doug Ledford Cc: Moni Shoua , Or Gerlitz , Roland Dreier , Bart Van Assche , "linux-rdma@vger.kernel.org" From: Bart Van Assche Subject: [PATCH] IB/cma: Fix a race condition in iboe_addr_get_sgid() Message-ID: <75d773f7-d8f2-a77d-6c7a-4991d71f0c9f@acm.org> Date: Mon, 19 Dec 2016 18:00:05 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 MIME-Version: 1.0 X-PPP-Message-ID: <20161219170006.966809.9421@vz23.stone-is.net> X-PPP-Vhost: bartvanassche.be X-Filter-ID: s0sct1PQhAABKnZB5plbIYrcAt68paBzxGNV4bZScc8DDDH9IcRzs4ldqK5vEMwbuZt+PpRPW1h0 yigPev+a+2kG1OIbu2MikMVjnNIeIB9yut37UOlU4mPqYejW/BoVblChMMSZmn/NxJIznw0LNrEq TTutvxiC1pgLkFO0HPz7GGohucAfUo250aIFceYU0KE9ogagsBltlGTmxMsBD1Pw8YjUZw3cRhww /cuY6EiwPzzr8somZk13zDg+j1zPzvoZzcizRKK5fh6I1hBDwyvsrtcsx09ah36U/q5pnKW7L1v3 k7AN9r7f59pElRgL/GDbeNeXIGJ0SFVWDF28vGoisV1nhW4d+K4c5RUPYjI8CVsONrMJuGzuoGnK TKcyK2pdLEl+TSrLYa983uv3ymHkxtgg6vFpnSEvG49LtdZXQ5s2NtDl9B/T0RFFk68QPTsFbogS dwQvsBMKNBm+EcOpyKA69LF1Ge2GaGfxmfo5bRHEitsys43ceNyofLHeCvr9lIa9hK0SnDaXxQ2p dPKx47lkycPnXbTCdHmFQFDBLgzQHr3Ro16N8S68q1BkT39psctcwWDKxwyFMAGaocqF3gAZ4eiD RXAEZmw8uXqjWe8KkFY3zSGKWInLuhTGMpWS5ipO+v0dC8rg8K+I9XqhQCQm9eGirX3t6nHShE9A k/yMWZcHPkY8NF6NjVhZmCi28BM7wFBma/Q67819kAEiRQv+PVjjwa+Z5RFCOMQ3DAZAnbFuee88 sdmlVvJtB5hQ6nsDvccjqgmDvD9Wh1vzUCEAj+90XJqaqSvAp+I= X-Report-Abuse-To: spam@sf1.bxl.stone.is X-Originating-IP: 87.238.162.216 X-SpamExperts-Domain: 1eurohost.be X-SpamExperts-Username: vz23 Authentication-Results: bxl.stone.is; auth=pass (plain) smtp.auth=vz23@1eurohost.be X-SpamExperts-Outgoing-Class: ham X-SpamExperts-Outgoing-Evidence: SB/global_tokens (0.00758567883731) X-Classification: not-spam/statistical-method1-global_tokens X-Recommended-Action: accept Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Bart Van Assche Code that dereferences the struct net_device ip_ptr member must be protected with an in_dev_get() / in_dev_put() pair. Hence insert calls to these functions. Fixes: commit 7b85627b9f02 ("IB/cma: IBoE (RoCE) IP-based GID addressing") Signed-off-by: Bart Van Assche Reviewed-by: Moni Shoua Cc: Or Gerlitz Cc: Roland Dreier Cc: --- include/rdma/ib_addr.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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); } }