Received: by 2002:a17:90a:37a3:0:0:0:0 with SMTP id v32csp745497pjb; Fri, 21 Jun 2019 07:56:38 -0700 (PDT) X-Google-Smtp-Source: APXvYqwAHVfxs78sHL/v2AG9WLyFNUsqNxIPtP/YqziRzkimvs7G3BScTZxVq1RHOAcvlc6kzfEZ X-Received: by 2002:a63:6ec6:: with SMTP id j189mr19405053pgc.168.1561128998208; Fri, 21 Jun 2019 07:56:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561128998; cv=none; d=google.com; s=arc-20160816; b=wga/mxEljqrx9oSM7tlPcgh9zCIoIgezZR/uN+8MqCCMkm/NBJXGuV88oigpPUCUX+ ON/A6PpZwfpPujhevdATGyPTY1grVGUpW4e0ekOXt/CwceXwRuwjcLomeZ8n9DjT7U0r NvjcvrCpMFdImdhXozMHCO2PscOvRvUkuWYBfmmZrjUY/WIB8lCyK3BKRuQwmn7TfrSB RZVOn01ded4Y/SupdO624ZmXcTstMduzTpGIAvhzafXaF9JAgapIuiPVejMsnNt7cR6/ Yjj7bsYboTXEjHYw+yjEwQO5pA8QdluDoZQUeX9aaLBkbnTdliTxsBMagqlGlCnCPqO9 Ys6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=R6wGdifeYAUiKIP0GGBLBBUmTIFn7pweCX0GnLETICU=; b=vt4mb34578f/MeNwPClTwzg0F2sjsm5RCHK2kWDi/RvbXz7JEIGENXu8bNbA6926th C+jp/zIjKu1/5xm4VCqXkXKldUbrf4sNx7LO+/56yjIczl5ZjeZI4FUn1xkcf8xUXXfT pd/0umSAzWbIYYGR4x0IjI7rjFaCTWLxhEB4sXDPCupgaVMwR80Tdk+g7/6BqrOEcJif OwVb7B65g25M1FNonhVn4ag9vQYBw3e4PhNLdJlv92T0mpbaVECRgnnQ/X8i+O2TfxEK 1Klq08sR/t2VZoqnSUX3WXzeV2I+gq1K83RYJQFmqg9ARTifkaQEf1sz+Ezgv8LwCNR/ H1ew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ziepe.ca header.s=google header.b=PC43vDQr; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b9si2911331pjo.95.2019.06.21.07.56.23; Fri, 21 Jun 2019 07:56:38 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@ziepe.ca header.s=google header.b=PC43vDQr; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726368AbfFUO4G (ORCPT + 99 others); Fri, 21 Jun 2019 10:56:06 -0400 Received: from mail-qt1-f195.google.com ([209.85.160.195]:38292 "EHLO mail-qt1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726010AbfFUO4F (ORCPT ); Fri, 21 Jun 2019 10:56:05 -0400 Received: by mail-qt1-f195.google.com with SMTP id n11so7201905qtl.5 for ; Fri, 21 Jun 2019 07:56:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=R6wGdifeYAUiKIP0GGBLBBUmTIFn7pweCX0GnLETICU=; b=PC43vDQr0y9Pg1xdmHWeVytAX0ixGDJ2KVFtpgNjVmhFcr7lbZ/t7arGdgSs8On4Ak ohXY78wNEgZSyIcjb+KONvqeB3pqoKuDYW70mISNbDqa7lpE5pU4K3quOAsgO49Qywyv /Y+V1Au4AV7aqfEcLunnS5+kC4RjT1K+J/HNYLYNNNJ8knZASPBiDA5dSKl8/ubBkWfK CFCv6jpPDFaO7GdHIugMNa56NIMAf3wAjJhG3o9RBtaIwCLOxPpbHEQdK38zIy8t5lJt FK2vkXbIVTeXWMsQRMZB8VpadI3wrbanvwNdt65Chd6QoQlwOxyYaeUkJPH+6sSYCqmP KZxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=R6wGdifeYAUiKIP0GGBLBBUmTIFn7pweCX0GnLETICU=; b=aI47+SsvyvVODTcIQOV/J8PwF+J5i6E/JSJIPT82WeKwJz58lN5GLyVex+4ULCvCQX b3fZXuyQeCmJL2NnjUQUnmIYZmAvbbl0FCpdS3rZLCXHSnO+TPIKtuRAn+S46d0pCFNr Om95uklMVa9s4TYJoajO3rEUkjFsI2YFhQdZQipOAJYpHUwbUMtXBn8KpZxYuqlLq/8v ZT2br5wuiGPMTUYSTTbvSjZOTncwlQ4z0eWf+m3uHue85IttBSyywXqKZx4ow1LgzoPt ynC9qeViHZ0kO4lFhN5wCkVsWT9WO+fwjrnbrak8kgaklyaJ899T/KzXheBc+hDQkuwb nZ/A== X-Gm-Message-State: APjAAAXDBBqqN0Vq62KxbLZqy6650CFd24ILQtAlYhj7Tja6kxvkyZ+A B/kEfJfR0qfKJikgujfk0OBWRA== X-Received: by 2002:ac8:7349:: with SMTP id q9mr113636418qtp.151.1561128964914; Fri, 21 Jun 2019 07:56:04 -0700 (PDT) Received: from ziepe.ca (hlfxns017vw-156-34-55-100.dhcp-dynamic.fibreop.ns.bellaliant.net. [156.34.55.100]) by smtp.gmail.com with ESMTPSA id y29sm1546916qkj.8.2019.06.21.07.56.04 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 21 Jun 2019 07:56:04 -0700 (PDT) Received: from jgg by mlx.ziepe.ca with local (Exim 4.90_1) (envelope-from ) id 1heKxQ-00014G-1d; Fri, 21 Jun 2019 11:56:04 -0300 Date: Fri, 21 Jun 2019 11:56:04 -0300 From: Jason Gunthorpe To: Dag Moxnes Cc: dledford@redhat.com, leon@kernel.org, linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org, Parav Pandit Subject: Re: [PATCH] RDMA/core: Fix race when resolving IP address Message-ID: <20190621145604.GS19891@ziepe.ca> References: <1561126156-10162-1-git-send-email-dag.moxnes@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1561126156-10162-1-git-send-email-dag.moxnes@oracle.com> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 21, 2019 at 04:09:16PM +0200, Dag Moxnes wrote: > Use neighbour lock when copying MAC address from neighbour data struct > in dst_fetch_ha. > > When not using the lock, it is possible for the function to race with > neigh_update, causing it to copy an invalid MAC address. > > It is possible to provoke this error by calling rdma_resolve_addr in a > tight loop, while deleting the corresponding ARP entry in another tight > loop. > > Signed-off-by: Dag Moxnes > Change-Id: I3c5f982b304457f0a83ea7def2fac70315ed38b4 > drivers/infiniband/core/addr.c | 6 +++++- > 1 file changed, 5 insertions(+), 1 deletion(-) > > diff --git a/drivers/infiniband/core/addr.c b/drivers/infiniband/core/addr.c > index 2f7d141598..e4945fd1bb 100644 > +++ b/drivers/infiniband/core/addr.c > @@ -333,12 +333,16 @@ static int dst_fetch_ha(const struct dst_entry *dst, > if (!n) > return -ENODATA; > > + read_lock_bh(&n->lock) > if (!(n->nud_state & NUD_VALID)) { > - neigh_event_send(n, NULL); > ret = -ENODATA; > } else { > memcpy(dev_addr->dst_dev_addr, n->ha, MAX_ADDR_LEN); > } > + read_unlock_bh(&n->lock); > + > + if (ret) > + neigh_event_send(n, NULL); > > neigh_release(n); Can we write this with less spaghetti please, maybe: static int dst_fetch_ha(const struct dst_entry *dst, struct rdma_dev_addr *dev_addr, const void *daddr) { struct neighbour *n; int ret = 0; n = dst_neigh_lookup(dst, daddr); if (!n) return -ENODATA; read_lock_bh(&n->lock); if (!(n->nud_state & NUD_VALID)) { read_unlock_bh(&n->lock); goto out_send; } memcpy(dev_addr->dst_dev_addr, n->ha, MAX_ADDR_LEN); read_unlock_bh(&n->lock); goto out_release; out_send: neigh_event_send(n, NULL); ret = -ENODATA; out_release: neigh_release(n); return ret; } Also, Parav should look at it. Thanks, Jason