Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp1313736pxv; Fri, 23 Jul 2021 05:29:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzGEc7Io346UZtAQZhYxT1Jzm10/oZWIQbTJIf/cNhO5Blykxx+MH5DxcPNfdZafQJAoSrA X-Received: by 2002:a6b:e70f:: with SMTP id b15mr3936626ioh.67.1627043399782; Fri, 23 Jul 2021 05:29:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627043399; cv=none; d=google.com; s=arc-20160816; b=sMACKhXnqT5Dcay+Hd3XPA5sp/w1qVrdx5rWjErKUPhKPnUWVhc3teldqT7pv7b249 VmaU620NrSqCfSI9mB8T3yKjsQHfv6H5WFku+mJfG0yFbc6QramvhMis9lcO/qZKGS6k 6X3g+eW9rHAOV2JPpKkcBO7K+gMI+w7IPee1eWqR8lbj+9Y5JVuKJPhJS3H+4pMziumT 2o7bi8U5IoTzNTw1OU/59AN7P6vStmhTBaQRhAWj17+55qya2D1JhffShHoLcixVLWSq nmuPxbYwfnJsYRXWTsexn8ixu9ZWg2Utaebr0G0MLIwa5FpBr31mupnPSgz1RxK1kpck 54KQ== 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=8II4urmUlenkUuvfftulp0hny6KgKhDocn78ereyKMQ=; b=oVqlWilR8DenCOfevq2LuYmUlN9X23fYIvRF1IhAxbu9Ry65EWAlE9GaIldGBXAQou ETzpGiCK0/EpB9FhMPp6MP+YqLmYXxYEDxg5ojg/NWvVk4hLF02lPQYHFCa4WYxVrO9t 236kWMp3WU5ypcSyYRXH7zP2l4Yy6zXdRx9zXn+VOZp3NXNst/mLNUhbc55SfHvSlL9q fh5dQ9u8uYwRmDLlRwyumsk22ksAVGqlcekZbZTZ+qRWquomwMeoMtFKAxIrPVwdMOkl vXZw3Grmoac1WqxRph69xkId0vjm9ztWOOYOpDYRo+bbqPYJ9OVkda/EnfrctJExBuiV Pggw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ClM4itRi; 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 f8si15704241ioz.70.2021.07.23.05.29.48; Fri, 23 Jul 2021 05:29:59 -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=ClM4itRi; 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 S234857AbhGWLrc (ORCPT + 99 others); Fri, 23 Jul 2021 07:47:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:55636 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234832AbhGWLra (ORCPT ); Fri, 23 Jul 2021 07:47:30 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 445F860E8C; Fri, 23 Jul 2021 12:27:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1627043284; bh=/hiAX5CAjW6tGqppGXooRjBKQ0fykryiFtk5xbyBL5w=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=ClM4itRigdwhpcbeJosSM1hJJCQiYijXqEk3LxM+YdmuKWCUCH8IdiJ3lGbpzfxqk pKfgrap4urO1oNLjGhtL6LzgSoPdbAMSyC7MX78P4GauiCg7BAkp7g0FsrW3zmzHSu Qa81UgbMGcjw2Aec6h/anR3ek2259WbMVLoEl8Fj6PdPPQVQxZTSer39iDunDlczIh z5RcHqPDHG36E/W7yjtjNj0p7RDo+MM05X/GMNwaktWmWfb30fmsBlvHmjfMNK5Q2D zUWAc056lCBP08V5ucxzraP/HxeO6vzZLJ/dtbGWRefNf41WnzMMqHe4xEw7wWtS2H lRmfmeuW9OZ7A== Date: Fri, 23 Jul 2021 17:57:53 +0530 From: Manivannan Sadhasivam To: Pavel Skripkin Cc: davem@davemloft.net, kuba@kernel.org, bjorn.andersson@sonymobile.com, courtney.cavin@sonymobile.com, linux-arm-msm@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, syzbot+35a511c72ea7356cdcf3@syzkaller.appspotmail.com Subject: Re: [PATCH] net: qrtr: fix memory leak in qrtr_local_enqueue Message-ID: <20210723122753.GA3739@thinkpad> References: <20210722161625.6956-1-paskripkin@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210722161625.6956-1-paskripkin@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jul 22, 2021 at 07:16:25PM +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. > > 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 It'd be good if this patch can be extended to fix one more corner case here: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/net/qrtr/qrtr.c#n522 Thanks, Mani > --- > net/qrtr/qrtr.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/net/qrtr/qrtr.c b/net/qrtr/qrtr.c > index e6f4a6202f82..d5ce428d0b25 100644 > --- a/net/qrtr/qrtr.c > +++ b/net/qrtr/qrtr.c > @@ -839,6 +839,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 >