Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp262713imm; Wed, 12 Sep 2018 22:49:37 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbTAJv6Nm9RLjEmrC/3x2ICKT8HSWr9TwTzP0q7PwVEwdHtuxsYn+/mZ6FmCOBs6ztm4V2R X-Received: by 2002:a17:902:9a47:: with SMTP id x7-v6mr5585868plv.37.1536817777581; Wed, 12 Sep 2018 22:49:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536817777; cv=none; d=google.com; s=arc-20160816; b=fnmHysbHo2BI0P6CqjqBVmTs0LlFCvD0E2a3I7xFXxg/fQbpJOIa2W794XOoulBIkv ynOpy9+WKejQq6BDtyrnS5WHdAxGsts/uSbVs2FcRpncagIqvqCl/B5Vxy9nQyN5/OyX oyjAhyvG0LnOelo8rdXZ4pie6VvxiVWxACECOMR27wvSGbmkvG4gPvwSS+z0z6+UNtgO sXdUMMRbuj+4bUAdMI2ACcymVE2ZgoPGB27uaLEKB2VeqvZtLXlfmyd1XhenihjUJ9XM YjUZJan6g9glsqsNL70I4WMEnog9FFxF1nmvHMKhXEofX94u6c1kgOQ7pvr5Tr87Hjc6 qcRA== 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=s51v0nm6SXhm14T+ThGBP9yOS23zoVSgs4YvnbC+AlQ=; b=D4Px9smRWmkjPjuXiUmFZNwbNJGW5d1TergydgK0uB1wEnULVIrMZoMNIK4s0GKx3J k/eVPyOwc332n6jvB22eCoVCjTYDK/9UtRTYa1pslOjCiMwurUUZ+8aCn2fOI4m0Jk5B e2vHr4exbbfy0I38p6nVBtDwXoOFMcFuAFjEimD+IayhMqr2zy6gu8ui85AHfpRGtq8M S/2AD8awcYipuyeTrbVvkdIrUboam/kSiNuh8KnDbk+lko5Fg2dDIKehk+pAzaVGte0s 38MKkaobgr7Pf9xBEO5oyzvC37oEsDBYRWV/RAQevR4BZuubo+K9O8ptgAIatgLm7LcC UqXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=wovoEIIQ; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m5-v6si3442050pfb.104.2018.09.12.22.49.22; Wed, 12 Sep 2018 22:49:37 -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=@kernel.org header.s=default header.b=wovoEIIQ; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726945AbeIMK5P (ORCPT + 99 others); Thu, 13 Sep 2018 06:57:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:39096 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726570AbeIMK5P (ORCPT ); Thu, 13 Sep 2018 06:57:15 -0400 Received: from localhost (unknown [193.47.165.251]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D70E720861; Thu, 13 Sep 2018 05:49:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1536817758; bh=KbtETZ11+nmo0wPC+IU9DvqxUaflT9wzKN34GPWH7ic=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=wovoEIIQj751BM5xxGV0SauLOkWqlEJCRo7sJ+34oVT2gTEi1g1yDdc9lPxq7q2sM nA0lVA1It78z5y3RqVveLncXZ5P7fsBDtDQIGkcsFAbSSYJXuI8NKbFKTf0neLjD7y loc/tti3GOyd/Haro3VIXEyO+eVHpmEjvE/lhQKw= Date: Thu, 13 Sep 2018 08:49:15 +0300 From: Leon Romanovsky To: Cong Wang Cc: linux-kernel@vger.kernel.org, linux-rdma@vger.kernel.org, Jason Gunthorpe , Doug Ledford Subject: Re: [PATCH] ucma: fix a use-after-free in ucma_resolve_ip() Message-ID: <20180913054915.GF5257@mtr-leonro.mtl.com> References: <20180912232744.12693-1-xiyou.wangcong@gmail.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="XWOWbaMNXpFDWE00" Content-Disposition: inline In-Reply-To: <20180912232744.12693-1-xiyou.wangcong@gmail.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --XWOWbaMNXpFDWE00 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Wed, Sep 12, 2018 at 04:27:44PM -0700, Cong Wang wrote: > There is a race condition between ucma_close() and ucma_resolve_ip(): > > CPU0 CPU1 > ucma_resolve_ip(): ucma_close(): > > ctx = ucma_get_ctx(file, cmd.id); > > list_for_each_entry_safe(ctx, tmp, &file->ctx_list, list) { > mutex_lock(&mut); > idr_remove(&ctx_idr, ctx->id); > mutex_unlock(&mut); > ... > mutex_lock(&mut); > if (!ctx->closing) { > mutex_unlock(&mut); > rdma_destroy_id(ctx->cm_id); > ... > ucma_free_ctx(ctx); > > ret = rdma_resolve_addr(); > ucma_put_ctx(ctx); > > Before idr_remove(), ucma_get_ctx() could still find the ctx > and after rdma_destroy_id(), rdma_resolve_addr() may still > access id_priv pointer. Also, ucma_put_ctx() may use ctx after > ucma_free_ctx() too. > > ucma_close() should call ucma_put_ctx() too which tests the > refcnt and waits for the last one releasing it. The similar > pattern is already used by ucma_destroy_id(). > > Reported-and-tested-by: syzbot+da2591e115d57a9cbb8b@syzkaller.appspotmail.com > Reported-by: syzbot+cfe3c1e8ef634ba8964b@syzkaller.appspotmail.com > Cc: Jason Gunthorpe > Cc: Doug Ledford > Cc: Leon Romanovsky > Signed-off-by: Cong Wang > --- > drivers/infiniband/core/ucma.c | 2 ++ > 1 file changed, 2 insertions(+) > Thanks, Reviewed-by: Leon Romanovsky --XWOWbaMNXpFDWE00 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIcBAEBAgAGBQJbmfpbAAoJEORje4g2clinQaUP/0d6dV3SRWyPjtGDleFGTWZG xSFbQte4gMTtF2PODzDPFz8TsNinHYzq/8x7Vxpabx0h9eOPkJiIqp9Wo6oEaysm XB63Pw6+3FPRJWpDJyy365N80cNb0TMSQGs1gtbduU+Gpa4x7UapF4swstpSxsrd 9+2pGr+OcrQhq6kVwVxxrUF9dEiHFXbaA1aUZvcA400ISTjfZYCpoprB39g3DtwQ tmBKo6kaKjZaHSEE6Du18FwqTSYB2DU+MlsU5w3AJzEIGfj422dSMBwgeHz9KCJL vSfdXXoj3Se02NuVD3ccaxkI+mabscOx/jPUkqRnd29Uc0Y8oJW9xvu63yy4NlX3 uCeoSmdpA2gmukIFSj0VUyxBIYlaLPjhpuzIg4H1YWl//OlFNHEle4b5JVeL7ley lZzmLHY6aYHaat8lUtTZtoaIyam9o6tjgRheA4jK4QhLqdjtDptvJalI0QZWwY7c tp0cMEnyNNNNGBV98fg/eXznXdozi/v77XML+i9YjvPWRsfuZECFwXKKt1YC9O2e Fpsa5XBlYEc1/upWffiGhORLY5tbjYXDDlD8E6nWHRBG8wkBZUkBbNqLKtdISB+J VccJI+9/O7TxW8XSXqLvBzq1VEH1f7K6po0X0wTK5qqdcKXFTs+YWxPl8XidgcXc zgp5ff7BE5wDRapJJbYe =iuSW -----END PGP SIGNATURE----- --XWOWbaMNXpFDWE00--