Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1564679imu; Wed, 9 Jan 2019 22:06:01 -0800 (PST) X-Google-Smtp-Source: ALg8bN4lwGL6tZhXNJyo0f0GUmFccwHL6MID0pRQjx2tSpot+Cjrv6N6pqbLnOpDKnem6952rjxX X-Received: by 2002:a17:902:6502:: with SMTP id b2mr8933175plk.44.1547100361764; Wed, 09 Jan 2019 22:06:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547100361; cv=none; d=google.com; s=arc-20160816; b=HPu/mwz/+Qh81fb8h/vz0c9P40qoPLY6LqK0MILU72mHvjmqbD6NfbwhJfTk7HGJZN dV9uUjrcNuoKAVb7GQ86zOZtSfS1hFqxCEQSK36dQkcmeP8SfKkS95GEvFHVvvgNGc8F 8Dy2V1zYa2T302L0YC1EAk7Eq5fLr29ajAnHMCVnOx24A4SPYCjD/ZPnw7K8iefxHBv+ SnacwrWXqoxiDH1+e5pCTQsprYRK06m9sdNuWP9KBuesydY9VxmgnBsyfHgXpmeQPXl7 Yd222UPExbg70uMuj3CaIL5AhrpcTo/z3gL6l7/9/4UWvJ6G3HWi1eSId5iq+0IJuVi4 T/+g== 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=982cPaGh6qoCDS7JmKmkGypc9iou4pqbU2baxd2RFO8=; b=NbFyFxyxScUapcHj8d3IY+IwXzBXZ8JuHSk9G3LK2602XISH+s+lhO9jAF/VdDBTPh ydTuPsTcgnqqilMxvXXJtf9YAStYyPfpmktXtC6sqR1QwZ8JXl0ZHR2A1QdreDTF26r6 4UnHFOcokC0YxuTov/Lgn4SmvqscLiNFxIQlWbu4x+sbYzqrynNv4t+LvIkWe/uR3OAU cXKkTp+Gy3WBw2fTlzVLV0j3yU1+Hg9F+TnEZtrfdoQ26otb0pTNPFeLkTwTvXDnEOIY fiWPJSW2LIUv5+MJtn0xRmpXAzqrD49yMn7jZzLtXugs3VTEMy0XMH3S2keUG05FH3bh EVxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=KRrQtghy; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 1si9065247ply.409.2019.01.09.22.05.46; Wed, 09 Jan 2019 22:06:01 -0800 (PST) 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=@gmail.com header.s=20161025 header.b=KRrQtghy; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727334AbfAJGDa (ORCPT + 99 others); Thu, 10 Jan 2019 01:03:30 -0500 Received: from mail-pf1-f194.google.com ([209.85.210.194]:38731 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725536AbfAJGD3 (ORCPT ); Thu, 10 Jan 2019 01:03:29 -0500 Received: by mail-pf1-f194.google.com with SMTP id q1so4836949pfi.5; Wed, 09 Jan 2019 22:03:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=982cPaGh6qoCDS7JmKmkGypc9iou4pqbU2baxd2RFO8=; b=KRrQtghyp6oLwI8dabFLAnLVufOEU762ze9GTtnsEfWAzljQGC8hSCuST9+qH1AAHx UqRzu7Qrt432Z7kWl+zgoqsOUwAKDtNMiEQvEaHYpxiXgw3drt/VlKZgTXtTofnD4uVQ DL8/s6q5DbxXq3GsyNV+lezhXuE0rp/GJgQgrTdL+uYKZh3rnAKQmBT0n2rDAuYj6hE0 N+PEXYma28V4GgQsZC2ugi690DyrHwohHa98c5/+8oW4mYyYVUPQdjXsx1mxKUuPaJ3L ZLhjkW4XSQu57isFcDsWXrh0H4EpYrWFDdUU540zLuD6gyG4lGXKoP7RTRhEYOgp2YSy IYeg== 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=982cPaGh6qoCDS7JmKmkGypc9iou4pqbU2baxd2RFO8=; b=azQVtgOKpvwLRXQIfwe8sih/89b+I6VPw64JW9WiIqsJIVYk44NYloqDNqX8nqSjWN M0d4sBAucV0v9q6Ow7aLOEOUJ0iz8ILaMR+O3IywDjVAa50iJa37N2DYNav641VDe/F+ hZ+YNSeHDeZrsQTbRyrEqgKuPfh2EhpQLbjljoUsINzec7Db776NzGsxEY2erma60tD/ yXTEntapudWvcsKpK8jOGM1e4tTNJY1tqnVcgKNx7yi/0a3QwID4DqXLzY2Ukbnathrw dbnDBncYiIEBIXTZCQDzCWs9tzFUFka9mJvGyoNDDdjaM5F0VXS1zE4KdYOtySICI2Zz c3rQ== X-Gm-Message-State: AJcUukc0cPUFjuNXuA0iWmrI78c5suq0y0HHY/hfHYCKq+rVfCHuniVD PhSYziXQWl/u3scL55bn0jc= X-Received: by 2002:a62:7c47:: with SMTP id x68mr9042325pfc.209.1547100208826; Wed, 09 Jan 2019 22:03:28 -0800 (PST) Received: from myunghoj-Precision-5530 (cpe-76-176-3-80.san.res.rr.com. [76.176.3.80]) by smtp.gmail.com with ESMTPSA id 5sm140301201pfz.149.2019.01.09.22.03.27 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 09 Jan 2019 22:03:28 -0800 (PST) Date: Wed, 9 Jan 2019 22:03:25 -0800 From: Myungho Jung To: Parav Pandit Cc: Doug Ledford , Jason Gunthorpe , "linux-rdma@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH] RDMA/cma: Rollback source IP address if failing to acquire device Message-ID: <20190110060324.GA25523@myunghoj-Precision-5530> References: <20190104064537.GA352@myunghoj-Precision-5530> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 Wed, Jan 09, 2019 at 01:28:34PM +0000, Parav Pandit wrote: > > > > -----Original Message----- > > From: linux-rdma-owner@vger.kernel.org > owner@vger.kernel.org> On Behalf Of Myungho Jung > > Sent: Friday, January 4, 2019 12:46 AM > > To: Doug Ledford ; Jason Gunthorpe > > Cc: linux-rdma@vger.kernel.org; linux-kernel@vger.kernel.org > > Subject: [PATCH] RDMA/cma: Rollback source IP address if failing to acquire > > device > > > > If cma_acquire_dev_by_src_ip() returns error in addr_handler(), the device > > state changes back to RDMA_CM_ADDR_BOUND but the resolved source IP > > address is still left. After that, if rdma_destroy_id() is called after > > rdma_listen(), the device is freed without removed from listen_any_list in > > cma_cancel_operation(). Revert to the previous IP address if acquiring device > > fails. > > > > Reported-by: syzbot+f3ce716af730c8f96637@syzkaller.appspotmail.com > > Signed-off-by: Myungho Jung > > --- > > drivers/infiniband/core/cma.c | 8 +++++++- > > 1 file changed, 7 insertions(+), 1 deletion(-) > > > > diff --git a/drivers/infiniband/core/cma.c b/drivers/infiniband/core/cma.c > > index 63a7cc00bae0..d27c3b154e71 100644 > > --- a/drivers/infiniband/core/cma.c > > +++ b/drivers/infiniband/core/cma.c > > @@ -2963,13 +2963,17 @@ static void addr_handler(int status, struct > > sockaddr *src_addr, { > > struct rdma_id_private *id_priv = context; > > struct rdma_cm_event event = {}; > > + struct sockaddr *addr; > > + struct sockaddr_storage old_addr; > > > > mutex_lock(&id_priv->handler_mutex); > > if (!cma_comp_exch(id_priv, RDMA_CM_ADDR_QUERY, > > RDMA_CM_ADDR_RESOLVED)) > > goto out; > > > > - memcpy(cma_src_addr(id_priv), src_addr, > > rdma_addr_size(src_addr)); > > + addr = cma_src_addr(id_priv); > > + memcpy(&old_addr, addr, rdma_addr_size(addr)); > Please add a comment here in the patch, why we need to store the old src address and restore back. > /* > * Store the previous src address, so that if we fail to acquire matching rdma device, > * old address can be restored back, which helps to cancel the cma listen operation > * correctly. > */ > > + memcpy(addr, src_addr, rdma_addr_size(src_addr)); > > if (!status && !id_priv->cma_dev) { > > status = cma_acquire_dev_by_src_ip(id_priv); > > if (status) > > @@ -2980,6 +2984,8 @@ static void addr_handler(int status, struct sockaddr > > *src_addr, > > } > > > > if (status) { > > + memcpy(addr, &old_addr, > > + rdma_addr_size((struct sockaddr *)&old_addr)); > > if (!cma_comp_exch(id_priv, RDMA_CM_ADDR_RESOLVED, > > RDMA_CM_ADDR_BOUND)) > > goto out; > > -- > > 2.17.1 > > Reviewed-by: Parav Pandit Hi Parav, Thanks for review. Let me update and resubmit patch. Thanks, Myungho