Received: by 2002:a05:6a10:c7c6:0:0:0:0 with SMTP id h6csp1647052pxy; Mon, 2 Aug 2021 07:02:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw/r+rX08Qsc9IqGs7jy9U52vANIRKebdRAbeisC1fyIz16vASM3mOvOcOhzuvS+8Awrm11 X-Received: by 2002:a05:6602:2595:: with SMTP id p21mr429515ioo.51.1627912932108; Mon, 02 Aug 2021 07:02:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627912932; cv=none; d=google.com; s=arc-20160816; b=QcfgLojmvlsHyFUFaxPjg1+SFz0bcx2wFHyScfS64dW8dhxSTmY3HxnrGD1WVcb8VE vkIDIok3xdh2s7R33AH6REXcy4tflXJG2nOgp3KpxGzev1eNT4NWnXMkbHGFMruBpAdN KILFtBIfmXQAApViCg9mlb1yHd7PyWZpUgshwBwSei6kwICcNMC2ko+t8oc0/alZr6KL 3sW5kNNp0yVfNgwZWWAJqaw3UWprBtC6cUttZ7pI2Rp2nuynImZ12U41wNd7pnE+v0dU 8VfQ8ZtGUBHGFzYriUYJfwkI/PLLXygvkN6hHLm7jzY4AoVfgwXIsYKQAOmKpBADJP9G 8pQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=cBULWAsO6GmvrEzLY+r2xicA65aoIBotmunlevhMH6Q=; b=UtxN3O8+NsioGq6a3NwyV7hiC2R8j5YGlM89ppRcH4zEuDvoGDWFzFkTXdAESQvQOt QjnGVZ8vjJGDa0Yl5WsCE+rDSf9daNuPs9rit9iGD6r2CBl8O5OyQrqrUUgB9b3CyXqI eKldtdhanNbOaG3quQi5zgFzT4sTx5Ylf9o9+I0p89g9xT2Rf7imCXlUl6naJSAdY2xb 72bza8xw7qT0gISs2JdkPg7q267sTPAyO9U8q3yCAOXGI50s0rKK+WttxpoBVr06zwzW A1c2IcxJyjblRMpl1P0E6fX2WkxX1uIzNfpS6VDzQaPYFNNYzov4ZKL1ooX53K5tyDdD UiDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=eb6zPvMo; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g13si14917270iow.65.2021.08.02.07.01.58; Mon, 02 Aug 2021 07:02:12 -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=@linuxfoundation.org header.s=korg header.b=eb6zPvMo; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236065AbhHBOAe (ORCPT + 99 others); Mon, 2 Aug 2021 10:00:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:34462 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236088AbhHBNy5 (ORCPT ); Mon, 2 Aug 2021 09:54:57 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 41E5E6113B; Mon, 2 Aug 2021 13:53:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1627912395; bh=asuzwGET+abjpttqE5PH41TBhsW/aFlWa/GRpDjujqs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eb6zPvMo5Mk+HBLksaPBdIZ1ARmYQzoKRTBmES2riUnrWh7RXQa5Tb4qUzoaFP1Di 9sZ5yOQ6WE9dMAbA6bcd3XDJHu4MTSqkfgvhJkV/crDMPh0XsKBna3fIosTGaNVOfy o2kOGT3N70kWE+Y8fpOlJVsxEQ4bbFmF/7Wi7xE0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Pavel Skripkin , Manivannan Sadhasivam , "David S. Miller" , Sasha Levin , syzbot+35a511c72ea7356cdcf3@syzkaller.appspotmail.com Subject: [PATCH 5.10 40/67] net: qrtr: fix memory leaks Date: Mon, 2 Aug 2021 15:45:03 +0200 Message-Id: <20210802134340.382419503@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210802134339.023067817@linuxfoundation.org> References: <20210802134339.023067817@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Pavel Skripkin [ Upstream commit 52f3456a96c06760b9bfae460e39596fec7af22e ] 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 Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- 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 0d9baddb9cd4..6826558483f9 100644 --- a/net/qrtr/qrtr.c +++ b/net/qrtr/qrtr.c @@ -504,8 +504,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); } @@ -830,6 +832,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.30.2