Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp443760imu; Fri, 4 Jan 2019 00:19:11 -0800 (PST) X-Google-Smtp-Source: AFSGD/XcDV5NepdhYiCaTxo4+JZDcrhn9yj/KiUAVHf5uVoDa7uCZAPzfuIQfxeJODRZNyW+2w/U X-Received: by 2002:a62:b80a:: with SMTP id p10mr51227158pfe.32.1546589951337; Fri, 04 Jan 2019 00:19:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546589951; cv=none; d=google.com; s=arc-20160816; b=VtwJlHy+OGlhEyeOteZbZfVjP8ycg/pKlyqAKeZI7O/yaWfTMgOFFGvMjn26qqDkJb QLW+Zz9PEgYtAqbZLi5xGNirUsHW/NVX8CAkbI0XHd6oSEr+AJQNleKzl0beC7f5DMfy s/+1y+EndoejdWqSJ5Y5P4CnhqaDOrfH4Wiv+WjlalI+Jt2d4R5E0ogroyTdiLmQmQZT 0EyUM5/2q4TX8B1AiGAf8zjg5YPmkhl/qP+ZqgeHtSRUJW5eMgnEV9MUY05eCW6OoC+e lNjalAVxKmf/V6nE2a6GabyK3CkLL2jb/CL2ST4sBxVf2hw6w801Vv9FwvCv/wtBtsQ2 PL4g== 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=LMUV/4YjWMvaS8Ac79zbRsjMFRoDchIM77+L6GMHAPo=; b=ayydJLLLUIrSTWlSGqe08LAhY0+dND4YwzVoOFjzS1RJmuQuutm+gWHw0fY5uNmiat mBFq6duynOlh6846mKRZLIvpbPzR3K7J0xRNcpdbJ3piB0lD7d5Nt6olqAZMzmtaGY3Q Me7t5bJEz318JU6LzwKfuvDAG/6NzRHyUiGaAFEdYJurjRj0RfQSlHN8R0EpkqK2Ijjz xQzZfEdk60TpJQ8QDMaQTTSoQdwQJcUAQWEn9cEsRtEeggQYNnFT10Ar9A3cBUBVQFTE dE/EFcDs3fqM+mpSIR8iEYiRNupHjTobAWWMKB91g6zRPgVetUujUVFg62JmYMC5MHUx Zg1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=UIoftdq2; 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 b34si4465088pld.305.2019.01.04.00.18.56; Fri, 04 Jan 2019 00:19:11 -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=UIoftdq2; 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 S1727374AbfADGpo (ORCPT + 99 others); Fri, 4 Jan 2019 01:45:44 -0500 Received: from mail-pl1-f195.google.com ([209.85.214.195]:40504 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725931AbfADGpo (ORCPT ); Fri, 4 Jan 2019 01:45:44 -0500 Received: by mail-pl1-f195.google.com with SMTP id u18so17000920plq.7; Thu, 03 Jan 2019 22:45:44 -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=LMUV/4YjWMvaS8Ac79zbRsjMFRoDchIM77+L6GMHAPo=; b=UIoftdq2t2r//NFdUy9J8kOrncKjZ0CiqmXSiPAkz8+FR7vLVoZN4OFkdFvtf0f2GT G5D3tZ6z55z1M88OFcG1bZdGYNcG9SpnyWAKPUpk/lyvW7qHp23jncXpI8KoL5XSyqRH yvXS7OPfdWbWgjXC7EbOlsY7l974pE8aa0Gm0BFZWCJDjqwYaDxnyAveW4FRYH3WaOkU XrlpCyYhKvy1dy0aGpyt23C9nxHA6sKsYlMgSUGotL1BKBmJ1tCZvCimIt4OAVNOnTbn lUfPVI37qmkhZxospPGjNUdyPH2xMQScQFthUGrZ6QK/BzvLwQiMcz8gUyxXMA7hIT/0 q++w== 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=LMUV/4YjWMvaS8Ac79zbRsjMFRoDchIM77+L6GMHAPo=; b=Winj5+XnaysnC21lxCDK7ZF5WWoVSkQjDCEnrMjPTuABLUdLu7PWb4ec1yiQoeOH3K R1/xlm9NtGJk/pLWnOWOU23YsiiYKASwdDmsWOJ6cD6XHDlZgODSs8qoicwFS70BQRzM fJBD6ExgZWPbe4YF6gv+U1u5/ncneTyRbnLYOfpAX1nSsqH3Jonu8oCK1oZNCIhZ7MpE sGqI2qvqhCmPWddVJEoa5OnYBB9FGNvtRdi85iA/EFQx52fTrpGCDx7OsPD7Chpk3LJg GOoPAp+uxlYyU1F0SpTASic+8uhGBOj5ZaMJ0cblHB3J+jaGANqf/WRG71oD4O3awP/7 /qtw== X-Gm-Message-State: AJcUuke3+4MtEy2FCDjyj3oxxU06RZ7V5RSrbPEkYDy9qF74E/fqyR+Z NTdh5GM4lMuRZWqaBP+D1Rc= X-Received: by 2002:a17:902:112c:: with SMTP id d41mr48152325pla.144.1546584343551; Thu, 03 Jan 2019 22:45:43 -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 x19sm98142138pfk.14.2019.01.03.22.45.42 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 03 Jan 2019 22:45:43 -0800 (PST) Date: Thu, 3 Jan 2019 22:45:40 -0800 From: Myungho Jung 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 Message-ID: <20190104064537.GA352@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 | 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)); + 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