Received: by 2002:a25:2c96:0:0:0:0:0 with SMTP id s144csp1472816ybs; Mon, 25 May 2020 17:33:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz1rdrB0fDKRQhTmRFm5WUVWqrmv45zYUpj/JaPNettajPZ75OvQ0SyMee11IYQNvXOYmP2 X-Received: by 2002:a17:906:b31a:: with SMTP id n26mr20091967ejz.441.1590453223225; Mon, 25 May 2020 17:33:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590453223; cv=none; d=google.com; s=arc-20160816; b=rMOPBcjOssDB6jDRZW21FD/OqXg6yOS0ZijhwqDGX506LkigUTZMg9Guy1kePtezIZ buzheEsLianXOwaRfaqu2LHlQdc5yfx4qtL1MIOYlnBDWTSbxAbVQCmsHrFKEy6fm+TE 0tqXxqE696Wz269JLKiWXDyHE7/miHpD+Wa7/S7Uh+ke1ag5ZLtP2yCL1OqbXwt+NJKQ mUqJKrp0ARXeJbuX/Oo4OBpmwlayrl5dzu+haUrln+nDGJ6+JhmcMZ15Ebww5I1vdkRR hqHc1TolfGAG+HbXibXOT5IlVZweIiWRATU6yonIKrCAsljPFuIrjZ3ak359fCMs8yOk WDwg== 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=c4nWWXi8qCXT9b5o9GmVwjoEsDaKwahe7vf3tGdNZwE=; b=ECdWdxoWzwe1TXKMPByhlPtDNzOBBSvkoIFFQfmIjjOVjM8pFCfmVKd0+qQ6+eEJuw Q6lFtUnhgm7pg2EscIWpAbLc8yMnZkEXtc/iwuYDJnKWtla58CavrMosXR9hvJk4Z58O WNxT7nBTePPiiRfoGpcNCQCXnYOpFgy+Kp+7nzEeu2/sZNmSfrmY96PKWlPMkrknSqqC 4iUltLWLoBNgqb03h2td1aqVP27wobnGylN2NYDYwjrO/xlje9x/0oXI2bhwrtIu/C8V U8RMpndM4VOqe0pE5/0HnwhT4BxNlvBtxbFwZbvttMMl73yeIVdgPcZZi/J7R2+1wctf JvUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ziepe.ca header.s=google header.b=ZuhdvUk7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j60si11423309edc.8.2020.05.25.17.33.18; Mon, 25 May 2020 17:33:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@ziepe.ca header.s=google header.b=ZuhdvUk7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726580AbgEZAbN (ORCPT + 99 others); Mon, 25 May 2020 20:31:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725783AbgEZAbN (ORCPT ); Mon, 25 May 2020 20:31:13 -0400 Received: from mail-qv1-xf42.google.com (mail-qv1-xf42.google.com [IPv6:2607:f8b0:4864:20::f42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 15846C061A0E for ; Mon, 25 May 2020 17:31:12 -0700 (PDT) Received: by mail-qv1-xf42.google.com with SMTP id p4so8709710qvr.10 for ; Mon, 25 May 2020 17:31:12 -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=c4nWWXi8qCXT9b5o9GmVwjoEsDaKwahe7vf3tGdNZwE=; b=ZuhdvUk7sfvXRz7F/zug9z1Ai7NHAh6QTWSHAlrthly+E40qyNby2MBcN3J5zTcaJq qhxLhCyDuPQM3S4wCNwm8DlOKBcLPdH/d7LCkdG4ByrcPomg2WSxYh+Iq2Si6UfKN25H DKYH1/QdsGxp1B31R6qCgVWOz7P/qPTBUi0IFz5TgFfRgFEu4FbFcopVrtY/NVZb77fe Dhb95g0gYo/IB3YQ87cD2gnpWvnr7UOSovzkjkWYpAeOBIxWvgmxhWm09C306C6sgJMK SBAHugwgLhgR8kDfvdjYQE8T6nQNboRCt/zi64uE+qXpWPW2B+FxnR93C2/IZmS1oF2Y 0eog== 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=c4nWWXi8qCXT9b5o9GmVwjoEsDaKwahe7vf3tGdNZwE=; b=Y7sGduKFyKYxO2WGEtg2eEvmWoDJS5klEXG8JOTxcqFwQijzL5A6YjLAUdXehyGLyi skgS0OoO0vl0wbBVEjsC/NSLWFHZOPAAgFF20EF6ankRCX39nnXn84RY8lGWZOxZtsMe ZCl0/ce6u3Uo2jIHw34c3+jtE6Jn1k2a0XLL7uARnzO79zu+i07qeuh3oXk+epm2ay5X c2fa86t/Gds/8m60U0zMtr4cEXR2ism1ZB3Ur3fcXCF/nrPOlwhjnzbG0adYSc+X1hbF qzHRsdARjUtgQ1aGiRXTqh82b6cF0IHLe8Q9sn8jGJUi9EIgAlYFKLTJvQLu70S1Aymq LCbg== X-Gm-Message-State: AOAM532bb3oNXMA4O8s5qzyLjBGSjJ3O1guwuH9B9wOcURVdm4CVrujh izpl1VPYx+ar+ngTnQbE38wq8w== X-Received: by 2002:a0c:fb0e:: with SMTP id c14mr3846688qvp.63.1590453071286; Mon, 25 May 2020 17:31:11 -0700 (PDT) Received: from ziepe.ca (hlfxns017vw-156-34-48-30.dhcp-dynamic.fibreop.ns.bellaliant.net. [156.34.48.30]) by smtp.gmail.com with ESMTPSA id v69sm11854642qkb.96.2020.05.25.17.31.10 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 25 May 2020 17:31:10 -0700 (PDT) Received: from jgg by mlx.ziepe.ca with local (Exim 4.90_1) (envelope-from ) id 1jdNUs-0001vu-5D; Mon, 25 May 2020 21:31:10 -0300 Date: Mon, 25 May 2020 21:31:10 -0300 From: Jason Gunthorpe To: Divya Indi Cc: linux-kernel@vger.kernel.org, linux-rdma@vger.kernel.org, Kaike Wan , Gerd Rausch , =?utf-8?B?SMOla29u?= Bugge , Srinivas Eeda , Rama Nichanamatlu , Doug Ledford Subject: Re: [PATCH] IB/sa: Resolving use-after-free in ib_nl_send_msg. Message-ID: <20200526003110.GJ744@ziepe.ca> References: <1589469084-15125-1-git-send-email-divya.indi@oracle.com> <1589469084-15125-2-git-send-email-divya.indi@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1589469084-15125-2-git-send-email-divya.indi@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 Thu, May 14, 2020 at 08:11:24AM -0700, Divya Indi wrote: > static void ib_nl_set_path_rec_attrs(struct sk_buff *skb, > struct ib_sa_query *query) > { > @@ -889,6 +904,15 @@ static int ib_nl_make_request(struct ib_sa_query *query, gfp_t gfp_mask) > spin_lock_irqsave(&ib_nl_request_lock, flags); > list_del(&query->list); > spin_unlock_irqrestore(&ib_nl_request_lock, flags); > + } else { > + set_bit(IB_SA_NL_QUERY_SENT, (unsigned long *)&query->flags); > + > + /* > + * If response is received before this flag was set > + * someone is waiting to process the response and release the > + * query. > + */ > + wake_up(&wait_queue); > } As far as I can see the issue here is that the request is put into the ib_nl_request_list before it is really ready to be in that list, eg ib_nl_send_msg() has actually completed and ownership of the memory has been transfered. It appears to me the reason for this is simply because a spinlock is used for the ib_nl_request_lock and it cannot be held across ib_nl_send_msg(). Convert that lock to a mutex and move the list_add to after the success of ib_nl_send_msg() and this bug should be fixed without adding jaunty atomics or a wait queue. This is a 'racy error unwind' bug class... Jason