Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp141648pxy; Wed, 21 Apr 2021 21:28:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwQH9RhehkX5Dqpe7TwvKyjUUsSpVUzmULGviNbbvo4fpeCFVUEYN0wTyyRG5chFuZW4I23 X-Received: by 2002:aa7:d587:: with SMTP id r7mr1347642edq.388.1619065700136; Wed, 21 Apr 2021 21:28:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619065700; cv=none; d=google.com; s=arc-20160816; b=mqycTjiB/dwoZsUGRYBS1S2knXfn09bjQDFeLzqukxPnTpbgEh+bcv3abzWbJilh6l E/2DBhiTMwbhAtRl4K96RsVBXI+ttHNrfJhvdgSjejJGiY3oAspTK5iWz0hBJGRjoYDQ ZtlU+YNXaiJo9RHL9TgMADVnkUwANZBMiPIwqB1L80boHct0UCChKLQ1u9N93Vp61Tz7 HGjIMsQ+X5ftP01wzKms2iB6AqXCMp2lBw69rs9rCl3iIMzSNAgwg1ZYhZXxt5fme2HF eswtGpB1vXvrC0HhcTbw2CKskjvGTIv4SnKPEy4usaORJQa02u5DZs2d0qnEiroNPsvX YwNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=Dxf5FF/lGIB6IQyK+aU7gFJeRzsKK/7ZoNo7XeJU63M=; b=loNJcHzsOcoiIyoBbosht8i0SaWnhopKyq1pZRihZqXyqBCIBFSYNvDbBAGQjG8mw7 6rgxhAqBLCiH+Yn6pHNmkf7A2aTb/JFdYScgUdUS87Ug5UXWEQrZ5FLHpTMlrioyuiwK H81KRqmMjd1XlxNbyhfQE4KJgpoktoP9jAr8KB3kvLa5GpLwNyLcWTZWA65kE/594O7X kxa5wZMRuWWNaCQmas4TKGZyLFr1Xkk9jY8E/btnMETiAmXRiOVSWXCspZ+5GpDh3qB5 KdTuQ1lvWaZ7gdecmyuShUpxZrYZBmKbURafH4aLFcojxA4QkhFbuhrXiJ8evM7rOG+a 2gpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Q+rDhgjO; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 25si1052554ejy.309.2021.04.21.21.27.40; Wed, 21 Apr 2021 21:28:20 -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=@kernel.org header.s=k20201202 header.b=Q+rDhgjO; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229816AbhDVE0s (ORCPT + 99 others); Thu, 22 Apr 2021 00:26:48 -0400 Received: from mail.kernel.org ([198.145.29.99]:51720 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229441AbhDVE0r (ORCPT ); Thu, 22 Apr 2021 00:26:47 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id E640160698; Thu, 22 Apr 2021 04:26:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1619065573; bh=M9WEz3stHuTUGOfvNJEUfe/rwnc74K79vU61YmvGy0Y=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Q+rDhgjON4c6Nb4n2eD5hZDXOs2ZmfIz1ofKdwD4pMNcbPm7z5kZj5jSJX0iwsk8C HeFzHgtv96tefEI7bFgKNMsNTNzId6f8MlUtXLpZ0anZc3UMSfzEfFgR5mWBGiLh4X mOckdniayURhzzP2A41yXkTJEDxeWLffHa1xxB147y5g5vkl9uy7PX1lKAFB4ODiWP /hJDOArWoWIkuK6CsSl6ff0WGhw5XpXYP7f0hXcBvuru8StEt8Mws15v7654fiCZkK YJiD/u5d4+r7NtPD7MnnLN0RsQCZW1PfRMs2EpPYqQ5I5HPSKFHn7ZgcAV4OQVZW9f p6ag06Tz8ERkA== Date: Thu, 22 Apr 2021 09:56:04 +0530 From: Manivannan Sadhasivam To: Bjorn Andersson Cc: "David S. Miller" , Jakub Kicinski , linux-arm-msm@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] net: qrtr: Avoid potential use after free in MHI send Message-ID: <20210422042604.GB14470@work> References: <20210421174007.2954194-1-bjorn.andersson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210421174007.2954194-1-bjorn.andersson@linaro.org> User-Agent: Mutt/1.9.4 (2018-02-28) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Apr 21, 2021 at 10:40:07AM -0700, Bjorn Andersson wrote: > It is possible that the MHI ul_callback will be invoked immediately > following the queueing of the skb for transmission, leading to the > callback decrementing the refcount of the associated sk and freeing the > skb. > > As such the dereference of skb and the increment of the sk refcount must > happen before the skb is queued, to avoid the skb to be used after free > and potentially the sk to drop its last refcount.. > > Fixes: 6e728f321393 ("net: qrtr: Add MHI transport layer") > Signed-off-by: Bjorn Andersson Reviewed-by: Manivannan Sadhasivam Thanks, Mani > --- > net/qrtr/mhi.c | 8 +++++--- > 1 file changed, 5 insertions(+), 3 deletions(-) > > diff --git a/net/qrtr/mhi.c b/net/qrtr/mhi.c > index 2bf2b1943e61..fa611678af05 100644 > --- a/net/qrtr/mhi.c > +++ b/net/qrtr/mhi.c > @@ -50,6 +50,9 @@ static int qcom_mhi_qrtr_send(struct qrtr_endpoint *ep, struct sk_buff *skb) > struct qrtr_mhi_dev *qdev = container_of(ep, struct qrtr_mhi_dev, ep); > int rc; > > + if (skb->sk) > + sock_hold(skb->sk); > + > rc = skb_linearize(skb); > if (rc) > goto free_skb; > @@ -59,12 +62,11 @@ static int qcom_mhi_qrtr_send(struct qrtr_endpoint *ep, struct sk_buff *skb) > if (rc) > goto free_skb; > > - if (skb->sk) > - sock_hold(skb->sk); > - > return rc; > > free_skb: > + if (skb->sk) > + sock_put(skb->sk); > kfree_skb(skb); > > return rc; > -- > 2.29.2 >