Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp1450058pxv; Fri, 23 Jul 2021 08:35:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxJIbWbeCYVoN56awYtzNpwjDIASXD6U/Cwg1dS+rROavcjYjWTHuzaL2OlDND+kXmU7meJ X-Received: by 2002:a92:c7d0:: with SMTP id g16mr3785731ilk.278.1627054513126; Fri, 23 Jul 2021 08:35:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627054513; cv=none; d=google.com; s=arc-20160816; b=gKUvhLqrlOZmBASobFYItidChhbgPnj1h0yYXCFgeG/d2Jf1MJ3naHKd519unoC3+I Dlq6AraT7xwbNef3wipz+OZ+lt+w95aBS5OrqBZhZ0aXp6BKZWhtEfdHy3uAlJtyafDv Kp1r+RvlBxrC46+ZKZbnyNnbxLEGaNnjgVLJ1ZNwMiEYME6uO1zid8sePQVig13ZksPH pKoeme7M29uUJ8P5fR8CdR4NBjp0d9yWuPSpY2M834gWftqqqHHhHKVj80lQHGQETQcU FKgf7Otc7yI09LPcR7zPqeGGP5fWbvp8xpedmzvqjFVH4ywOm8PrKQasizjo7glt5mtH uh8g== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=OaMQFsec0NzLLpOf7NP5EVhh2TGUHi54KtoO+USyjiE=; b=Nw9hKfszEmIOc7BXgJXWCgOAg3HecnMD+JhaSYWcMionGRIEIGCPJLSLgb6Ad+vtN1 UU7SIphqS31+tRrrfj+ytaeEP7UVj8b04M/uNAdOZhOWPxeITOugu+lea8g2TuO5mqlX mIwOKaG4GwDet67UxRrKvP59finQ3UUZ6p/CXBL4knI+kSwOtd2LCSmFhhp/961D/bmz K1KQ0EW9/MjSwLGIe6F4z9WDRKkaZu7FrXE7hsjTTWhflS24y+fsoyljL5rcw0ixaMfL JM3DZKjiXt3eFZssUnA2gASOrTxX6hMWUVghzB0EVhmbXD54nAt+JJDY5eQYvhLDB+GF uWPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=j+RE9f9M; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a16si13220206ioc.54.2021.07.23.08.35.00; Fri, 23 Jul 2021 08:35:13 -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=@gmail.com header.s=20161025 header.b=j+RE9f9M; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235555AbhGWOv3 (ORCPT + 99 others); Fri, 23 Jul 2021 10:51:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235438AbhGWOv1 (ORCPT ); Fri, 23 Jul 2021 10:51:27 -0400 Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [IPv6:2a00:1450:4864:20::12f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8FC27C061575; Fri, 23 Jul 2021 08:31:59 -0700 (PDT) Received: by mail-lf1-x12f.google.com with SMTP id d18so2718705lfb.6; Fri, 23 Jul 2021 08:31:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OaMQFsec0NzLLpOf7NP5EVhh2TGUHi54KtoO+USyjiE=; b=j+RE9f9M4jLFONDoyX5Okg929LQmJ3Kox7FDvip52TSOScBMfinmkWh38BHT7an6VR DuhsvVZ6715Jky8eWdQ/9vD7p9GQqtiReNOJcpPLQMBNe6cgm2nZTIohPrYdzdmZwzuu mtDyvkoAlIRwQIELBm0h0ITVFaEf30vDtNSDpJeQqehmlAZWZ790f8dd03QGDrEdBBGT 474uHCAcZkb9+sXV85pIZvc5SSxuNTD5gy+s4MK8aoZoYS74LucutTIMYAbtQvRpDOVD N+MwoH1DH7OGHzzqoUqNbUhymO7aXg7OIlGYAh4hH3XM3VIVLU0KBEbcgP1WQvYHO6tT WnWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OaMQFsec0NzLLpOf7NP5EVhh2TGUHi54KtoO+USyjiE=; b=Ao92k+yM2r7mLtcB59EpIyB3wT5K2+Ct3gm5QaLkzwiKJSymcmZOeymm9/CiUbW1cs bPhqvvuaFicr8+ERIpZKMkne7XO2NvPT4wfchMZuLunwjwa5mJhGM/m7Q6mfY0NDwVQM fzyrHMaOC+U0GXpRtZ4mhXjBCyQ5d8+T7XXbsMUt64SRuewpg5MEzIO+uBHrSuRZnZ8r RdVVDqY+YMM+q536o2/wi95+gdVFQw/bfdCWVIC2AC50XJCa0GnKA8ufpSBabGrOVDKE TNNKJo1bOS/G2+Na9oNtLJJHodQzbulMw7OA4nOQwz3QxiTNOOEd49vLLlmWEZlJ6kM4 L2vA== X-Gm-Message-State: AOAM532dX4mbS74pQd4fGbIK6i6mfbSZu+N56HKxo9dZhZeq4OVfMea7 4Jba4DCJEZ9PYhCX3OCYejA= X-Received: by 2002:ac2:4c13:: with SMTP id t19mr3551237lfq.394.1627054317862; Fri, 23 Jul 2021 08:31:57 -0700 (PDT) Received: from localhost.localdomain ([94.103.227.213]) by smtp.gmail.com with ESMTPSA id j26sm1630849lfh.71.2021.07.23.08.31.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Jul 2021 08:31:57 -0700 (PDT) From: Pavel Skripkin To: mani@kernel.org, davem@davemloft.net, kuba@kernel.org, loic.poulain@linaro.org, bjorn.andersson@linaro.org, xiyou.wangcong@gmail.com, edumazet@google.com Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Pavel Skripkin , syzbot+35a511c72ea7356cdcf3@syzkaller.appspotmail.com Subject: [PATCH v2] net: qrtr: fix memory leaks Date: Fri, 23 Jul 2021 18:31:32 +0300 Message-Id: <20210723153132.6159-1-paskripkin@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210723122753.GA3739@thinkpad> References: <20210723122753.GA3739@thinkpad> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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