From patchwork Fri Dec 16 13:39:12 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: 9477911 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 B9AE260827 for ; Fri, 16 Dec 2016 13:39:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AB2E52882F for ; Fri, 16 Dec 2016 13:39:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9BF7A2885A; Fri, 16 Dec 2016 13:39:44 +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.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID 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 3301E2882F for ; Fri, 16 Dec 2016 13:39:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759600AbcLPNjm (ORCPT ); Fri, 16 Dec 2016 08:39:42 -0500 Received: from mail-wm0-f66.google.com ([74.125.82.66]:33147 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757712AbcLPNjm (ORCPT ); Fri, 16 Dec 2016 08:39:42 -0500 Received: by mail-wm0-f66.google.com with SMTP id u144so5562263wmu.0 for ; Fri, 16 Dec 2016 05:39:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:message-id:date:user-agent:mime-version :content-transfer-encoding; bh=XYDdAEvvSCn1I/k3ojvEhoUb4ohBe1Ps91/urIXBnX0=; b=KFEA6WJhib7sazbclDkSYRAjCCoKc/ke2QWrNEp6OB6lD9iBVDktZpL6uz7rFRBRNo E32DPchMXDuCw+tv/CQbDTwAt6lU66hcqDyA4CBdzEp58Lqaht+m3BVveVCMUOq34TdE B4QLzzpAApaguGGyfRKoeRtuvGke/BHa7uVBR0Jtw/zCdEdyQyGHxpzZ/9ATRfAqinbv SFD4f1ehmcbx/+h2kAr/EdK1QiM/sFZ+yJopDAhqJoNmYydWAfYlhy5tmnblHf+YfVGK xHYcbG7+AG300zwgn756NmVv5htcYrJRiYgWmmva7ee334ErMY+WK/YiqF6gX8pZWeHM mmJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:message-id:date:user-agent :mime-version:content-transfer-encoding; bh=XYDdAEvvSCn1I/k3ojvEhoUb4ohBe1Ps91/urIXBnX0=; b=CFGg6qvJ0dOnFhNBNjatXtvByIs1z0XoSXK0FFLpcUXvKyvtLYaLJp9bsCaesKRoSk OPogIV7jt206PSCrUvJZwUVj/VE8MnENNH+g798gO5IzQexkLSdCJPHZ11OHed92ievA bhIIV3qSy7b2A2xl+lwE6z+CagMXwD+J7WZEQ2ZavU5OZbBVm6pLdg0tbSxvQ/ylGS+q rGe9Y7p4NeeMaD1MwoA1u5yI912ihbsv9wa10ledBAsr8NO6jakrckequ0dQ2X2gh6WT w4L9OAh2HiRE3m0f+x0V2QjFXA0mzuifbciDFb4O/t40q+EtSritftUgJeV/1ozmUxPq 4r+Q== X-Gm-Message-State: AIkVDXIC11LDUZg0bp8n35S8bELqsPBCnLV7VK4LcePloE5IcS2L7kCLTCm/xxR/3Z/EgQ== X-Received: by 10.28.41.5 with SMTP id p5mr3067743wmp.38.1481895553910; Fri, 16 Dec 2016 05:39:13 -0800 (PST) Received: from exp-402881.sandisk.com (178-117-55-239.access.telenet.be. [178.117.55.239]) by smtp.googlemail.com with ESMTPSA id u81sm3409964wmu.10.2016.12.16.05.39.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 16 Dec 2016 05:39:12 -0800 (PST) From: Bart Van Assche X-Google-Original-From: Bart Van Assche To: Moni Shoua Cc: "linux-rdma@vger.kernel.org" Subject: [PATCH] IB/cma: Fix a race condition in iboe_addr_get_sgid() Message-ID: <811914f1-3bcc-a0a4-e20a-86e8b5853ac7@acm.org> Date: Fri, 16 Dec 2016 14:39:12 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 MIME-Version: 1.0 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 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. Reviewed-by: Moni Shoua --- 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); } }