Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1580623imu; Wed, 9 Jan 2019 22:29:34 -0800 (PST) X-Google-Smtp-Source: ALg8bN5aqdP7XKCKX0cYZp/h8yo1Jp8Y/QdV0tNt89N3OoCDnpLdcgygthYhvEfFKme5aGqlcKu7 X-Received: by 2002:a17:902:6e0f:: with SMTP id u15mr8981394plk.175.1547101774275; Wed, 09 Jan 2019 22:29:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547101774; cv=none; d=google.com; s=arc-20160816; b=bOxNaqg+RmE0Tkkx6d8DJE4WAuj21BNHGryuvDaRYvGoT6ene8GgxIogPzn/A0/q6w Did0spALjShjMRGc4jxnUjAZUciU2CYdVF1rr+HNieAxsV7cEXMC+0EKxKBSlF8pPkWr 4lYxl0grX/E1KsYRdraA1lYV2tQrHNQ7quWOIdEurTOjMEBWXCqoArU7UGeHxiLEJRIj 8UJSG/oPqBHaffCMutJRqLfNJG3U/1hZ8eG0mO/qen/l0kyv55Z5fJYLvBCQN+Fh+Vrb OnNIkzZltRlQuH19AAwsp0I9znx+2S3XMNPYPq5fo5ibOINBNRwL2dpUrR1uFvxTaVS1 Fejg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature; bh=Uqep5P12TmNJRbDpNJ38z4+WnFaCIQ/6dfEgnqnIVCU=; b=XYD3/tuUSriOCgvxLGMUxZkA9u7EZUlBFwg77JEiHwZOtk9qD6Eo4Jz4jNhvJu1R3j KBlPFVV8fSNWv/r4o4RLfcpp7iPex6Opc+Vq6SitoCtGDruZiUeYNLuOgCswU9H1U+cy b7May5TMY5/brZ57vLyQAVbKaYnzWiOhUroZ49AnkSXuIlciAtRXv5CpkiK+RamHoaGf D3lB0B+Myt+VUD2e5LcJX2wtyl0KrvyVsW50z+xtIPWCSKp98YnqdLCDNbL+CHY0sc1d JmgUsYzolzV0WYHIKk2lxwQsQ47Jsp0Lq4LIkJI5/rRjB1FaAAu/WoIO0wx8LVYQb1um Vw1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ESlhdUQp; 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 97si69460491ple.389.2019.01.09.22.29.19; Wed, 09 Jan 2019 22:29:34 -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=ESlhdUQp; 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 S1727269AbfAJG1f (ORCPT + 99 others); Thu, 10 Jan 2019 01:27:35 -0500 Received: from mail-pf1-f196.google.com ([209.85.210.196]:33136 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726338AbfAJG1f (ORCPT ); Thu, 10 Jan 2019 01:27:35 -0500 Received: by mail-pf1-f196.google.com with SMTP id c123so4875062pfb.0; Wed, 09 Jan 2019 22:27:34 -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:mime-version:content-disposition :user-agent; bh=Uqep5P12TmNJRbDpNJ38z4+WnFaCIQ/6dfEgnqnIVCU=; b=ESlhdUQpSVrVl6UjPIHJprxQTwAxcUKZf+HRCE+TrPSxd3kch7zC2hhzmu/lDZxfQX ELnBHZkHxtPmBR+mMNXPCzAmu/nZzazCFua4tUNfxY7tVIxhMariWppDrnIgLEaiKmKV MY7O/l8RSbNYO5RswniB1EF0KKmkvjT7g1OWaUdc2g0Xy1ZM2r3qhhDh430LBhsLFax3 Egv2p0ealXSWQI74wreKnAQiFUG0LAx7usnFlVnCCC01ENEktaRj3mTgTe1nkcf9Tf1a tjBul/sgTFCUAwfgpqIQZfda2WnkE1xerQh2mKM9i6/zZ50M+tqf92BjLGhAcRYcTrfG 4VUw== 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:mime-version :content-disposition:user-agent; bh=Uqep5P12TmNJRbDpNJ38z4+WnFaCIQ/6dfEgnqnIVCU=; b=L6YqooNQGhMBydFuYY57hzRopgPGlv1Go0XzXkRSvw7cTlcPw8Kd9zQ7Tllsq6S5Tu GNB9RnYkHxcf/ar/DUUKHqpSfhinst0VdrVy5Yd659nQlw3/gw6Ap6dmBtujk+9Kfg+L Cl6qMZ1M3uJI3op6aOJBSG7FlDdFshpi4hjfaj4VdWKheBmsmzWGj6JgQkCHPpkddeaU wi7KEnzcMzrUWBxhcxbHqhIrmebA1GI2kr49cx5sD7gtxzSzyEfzSLRIYY3IxIBorn6B ctuOl4H72QgjrW5JoUIVuBz+ijbTr1ZNHS+jXFCu0tNQzZ0WD2KAeFfFdG32BnLIikgO p6jQ== X-Gm-Message-State: AJcUukc8Yy2OD1fb9gYgAHcpQ6qmgIIFT8w6x7p2X2QZ4dgpfnNyNvF3 aWU3eZUoJgxlWmD6eEEuN04= X-Received: by 2002:a63:bc02:: with SMTP id q2mr8304277pge.116.1547101654087; Wed, 09 Jan 2019 22:27:34 -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 h134sm149229455pfe.27.2019.01.09.22.27.32 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 09 Jan 2019 22:27:33 -0800 (PST) Date: Wed, 9 Jan 2019 22:27:31 -0800 From: Myungho Jung To: Doug Ledford , Jason Gunthorpe , Parav Pandit Cc: linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] RDMA/cma: Rollback source IP address if failing to acquire device Message-ID: <20190110062727.GA25844@myunghoj-Precision-5530> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 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 | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/drivers/infiniband/core/cma.c b/drivers/infiniband/core/cma.c index 63a7cc00bae0..8cd113b0ddfb 100644 --- a/drivers/infiniband/core/cma.c +++ b/drivers/infiniband/core/cma.c @@ -2963,13 +2963,22 @@ 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)); + /* + * 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. + */ + addr = cma_src_addr(id_priv); + memcpy(&old_addr, addr, rdma_addr_size(addr)); + 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 +2989,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