Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp1458353pxv; Fri, 23 Jul 2021 08:47:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwyExr7Yf+/BKuf95Z4yj75w3FA5ifF+SMVIN5C9OZtDeysg40Xg/o2uF9mfNkeg+DBgVq8 X-Received: by 2002:a17:906:7a56:: with SMTP id i22mr5138690ejo.94.1627055230434; Fri, 23 Jul 2021 08:47:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627055230; cv=none; d=google.com; s=arc-20160816; b=qsLlCV9pbM8dmepsQmsrZ/zoBEPbn2LkQnf5gWBedkvG6N+/sTVFGzq4/s65EceEvW mUJrvNUOVtdPZckbgjNuHUiT4O8aumYSBI5UOLv+tWE/wUG6ttsYLiO5fAEdjXwKgSAp X3SoAVwtzeXqMIiIHvx2M7GLZv9jT2Q4J6CJzGYt2SF5bLpTfMkjcJCSdyXzzQ74doeq iJKS0xPfprRJev+rDINZCXFfDPYoWiv9x5VfK3l6Lc9lK4sN9PhrJ8Famv71ej+5yxkE BzCh5WWGimENfdPf59X7E4HSMQsa+g5vtsbgYz4X9jDS71pGrh0F/vgR+lWf4zr0ujXV hBxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=MxVR7QBEyTfN1hnb1Wicv5TmcbuEV53/UXScU9RVW0Y=; b=o1k1hwbacLa5VA/Vr+uCKJtczQvKZBcPz35EN0C7BNy5+TpqVELDqHMBa/iP4w/f5s Bh+wnpTDFsTZvZ1SqrM7sPNJWqDds2H8ALIVAEGrnlw0I1b7IFATnEPhaBdzS9YpBQJn 4N6g9zmxXqMwulp+kAW9kOrmeV5u8fkU9ZY9+Ns9EvenQLGs8BRi7YnslKGjc0SIOj0f cOhlQWDcWioy2gHGSWAj9iKS0O264x5PsuN0P0J8DB/XzJA/ivDPs18/tqMBwGa/U1G/ RhY3a4AENfe2TRTWBSw4XJEuigDcvHbh2M0vw+MdDmDGJhh33abv4vmaxEte7RFsB30c bfqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=d17zTnCr; 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 s24si522522edw.244.2021.07.23.08.46.46; Fri, 23 Jul 2021 08:47:10 -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=d17zTnCr; 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 S235610AbhGWPDb (ORCPT + 99 others); Fri, 23 Jul 2021 11:03:31 -0400 Received: from mail.kernel.org ([198.145.29.99]:48756 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235470AbhGWPDb (ORCPT ); Fri, 23 Jul 2021 11:03:31 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id CB88760C51; Fri, 23 Jul 2021 15:43:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1627055044; bh=vhxORIpUlFOlz7p1YyAS/UfRmjF+Aiod9z/B9WU45dc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=d17zTnCr9JLhnCtYCuiVILkQ+lwK4yTgpCMDm+HZhgUL/mnqy2h8bjllIojs4vPaJ eUGtkl3ObvGBORX+NHbXDO6EhN+HGiITJHk0hCN9WT+tLMWofcaWDTx3YAmyBCz32o jgYXraP9rkJtQeGvsXTw+nvcah7BUyv901yQ4JiN3F9sRnZ8cd3y2kjP0kz7LvCHs0 4O6Hmar785mEng8Serdnu6IW52cjza1755PERDNLtNqd1rtW8RfijvMO7MjPzPZLVk bbNidAUrC5hFS3euLftq0POnCYn/9kEdqKaq8dLw9no3Od/9gJBt1ldDhBKCiidOXi 6+1MdARmX0JHw== Date: Fri, 23 Jul 2021 21:13:50 +0530 From: Manivannan Sadhasivam To: Pavel Skripkin Cc: davem@davemloft.net, kuba@kernel.org, loic.poulain@linaro.org, bjorn.andersson@linaro.org, xiyou.wangcong@gmail.com, edumazet@google.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, syzbot+35a511c72ea7356cdcf3@syzkaller.appspotmail.com Subject: Re: [PATCH v2] net: qrtr: fix memory leaks Message-ID: <20210723154350.GB3739@thinkpad> References: <20210723122753.GA3739@thinkpad> <20210723153132.6159-1-paskripkin@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210723153132.6159-1-paskripkin@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jul 23, 2021 at 06:31:32PM +0300, Pavel Skripkin wrote: > Syzbot reported memory leak in qrtr. The problem was in unputted > struct sock. qrtr_local_enqueue() function calls qrtr_port_lookup() > which takes sock reference if port was found. Then there is the following > check: > > if (!ipc || &ipc->sk == skb->sk) { > ... > return -ENODEV; > } > > Since we should drop the reference before returning from this function and > ipc can be non-NULL inside this if, we should add qrtr_port_put() inside > this if. > > The similar corner case is in qrtr_endpoint_post() as Manivannan > reported. In case of sock_queue_rcv_skb() failure we need to put > port reference to avoid leaking struct sock pointer. > > Fixes: e04df98adf7d ("net: qrtr: Remove receive worker") > Fixes: bdabad3e363d ("net: Add Qualcomm IPC router") > Reported-and-tested-by: syzbot+35a511c72ea7356cdcf3@syzkaller.appspotmail.com > Signed-off-by: Pavel Skripkin Reviewed-by: Manivannan Sadhasivam Thanks, Mani > --- > > Changes in v2: > Added missing qrtr_port_put() in qrtr_endpoint_post() as Manivannan > reported. > > --- > net/qrtr/qrtr.c | 6 +++++- > 1 file changed, 5 insertions(+), 1 deletion(-) > > diff --git a/net/qrtr/qrtr.c b/net/qrtr/qrtr.c > index b34358282f37..a8b2c9b21a8d 100644 > --- a/net/qrtr/qrtr.c > +++ b/net/qrtr/qrtr.c > @@ -514,8 +514,10 @@ int qrtr_endpoint_post(struct qrtr_endpoint *ep, const void *data, size_t len) > if (!ipc) > goto err; > > - if (sock_queue_rcv_skb(&ipc->sk, skb)) > + if (sock_queue_rcv_skb(&ipc->sk, skb)) { > + qrtr_port_put(ipc); > goto err; > + } > > qrtr_port_put(ipc); > } > @@ -850,6 +852,8 @@ static int qrtr_local_enqueue(struct qrtr_node *node, struct sk_buff *skb, > > ipc = qrtr_port_lookup(to->sq_port); > if (!ipc || &ipc->sk == skb->sk) { /* do not send to self */ > + if (ipc) > + qrtr_port_put(ipc); > kfree_skb(skb); > return -ENODEV; > } > -- > 2.32.0 >