Received: by 2002:a05:6a10:c7c6:0:0:0:0 with SMTP id h6csp1639963pxy; Mon, 2 Aug 2021 06:52:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyJXh0yqUlHAl8BXZmnPCCFp8A7IkQL17nj4OJGGluzSmTv7j0Q+ZtGafb1PvFM8XjARhJc X-Received: by 2002:a92:4a0d:: with SMTP id m13mr1069803ilf.129.1627912343284; Mon, 02 Aug 2021 06:52:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627912343; cv=none; d=google.com; s=arc-20160816; b=USoJY0DgRsPu6m32rnHztBZd0t1jmpIE3qr2YrTmpyWLlpFKIl+x2AGrkkz0HQDMZp Lar/X7qGwu9p9dhxDrwMoA7IbCBsO9ICBZzX4u73OcHhM4QgLZcsnEjzVbXc9MtDalPW psiXwoJ6gfnIML6UPCQx3raBLPTDhj3xCgqYN/rZaZJxE8t7ocJOm2mxSOaDILayanrU 9D9fMRaO2EehXHM4LVbZGTryFgoU9IJ/EbLOaeUzWm/kdgVHvOOb52PZk3CPpwyBQmTC BYBHSRlPdC77nr0YQanOd4zODvJHQvn29ZyOMce7u7Ibl7dossbtCHvW20P74t5LPZKd dyMA== 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=7OzubxuCHn7IcGgeOL6kTqmeQCBTjXkXIE2l4+kcZ4k=; b=wfbgnngbwAnNH251t/uHwVU0UfEtIGn2EtdnOwyGaE8o1hvdYJzfBE4muuTmhLnFeR giVO7JQtyt+KlAyZZzr/yith/crnpLSFue89Wi1UtUSZkLdZ1EkJ2W/SWhjArYFGOY17 jca7PdDkoGg9UE1oPUdcIydz0G6p9dYfVf7WFmHsEqWgGzh+6UsKmxd6Gd3RVfFlFpO6 RZw9YxnFndGn0XFTrSu8yX4EfZ5yVMISvz9ZRoE3akJ5PURFfom5krcr+2c3vXDeqHa7 jkw+YUnv+1WkKDLrDwDT9qNaom28SQa85PTzBIS1Ync1sCff75wKAbWpJ0v+K+HGkDke W1/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=UIMasPlR; 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 d10si1945634jaq.37.2021.08.02.06.52.11; Mon, 02 Aug 2021 06:52:23 -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=UIMasPlR; 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 S234941AbhHBNuc (ORCPT + 99 others); Mon, 2 Aug 2021 09:50:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:57098 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234139AbhHBNrs (ORCPT ); Mon, 2 Aug 2021 09:47:48 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7EA4B610FC; Mon, 2 Aug 2021 13:47:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1627912048; bh=mYSAb2tblnHSTGfIlA7dILXS4txeVAS9pK0nlQbYLr4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UIMasPlRYJOUTaVXWCyfXhWzGgqTkIjb7dHZ/K4+sBczcQhv7lInebRtUB/tyntXo CpxQCvK5RBfo1bnjuLnJAZyFuNhF6VaTkM4hSizDoVukUre4/UAUM1wewaad9zxvCQ iU0f4iV9QSKfUBfb8lSktK+Av2cjff/AYSFiqFRE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hulk Robot , Yang Yingliang , "David S. Miller" , Sasha Levin Subject: [PATCH 4.9 07/32] net/802/garp: fix memleak in garp_request_join() Date: Mon, 2 Aug 2021 15:44:27 +0200 Message-Id: <20210802134333.158621637@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210802134332.931915241@linuxfoundation.org> References: <20210802134332.931915241@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: Yang Yingliang [ Upstream commit 42ca63f980842918560b25f0244307fd83b4777c ] I got kmemleak report when doing fuzz test: BUG: memory leak unreferenced object 0xffff88810c909b80 (size 64): comm "syz", pid 957, jiffies 4295220394 (age 399.090s) hex dump (first 32 bytes): 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 00 00 00 00 00 00 00 00 08 00 00 00 01 02 00 04 ................ backtrace: [<00000000ca1f2e2e>] garp_request_join+0x285/0x3d0 [<00000000bf153351>] vlan_gvrp_request_join+0x15b/0x190 [<0000000024005e72>] vlan_dev_open+0x706/0x980 [<00000000dc20c4d4>] __dev_open+0x2bb/0x460 [<0000000066573004>] __dev_change_flags+0x501/0x650 [<0000000035b42f83>] rtnl_configure_link+0xee/0x280 [<00000000a5e69de0>] __rtnl_newlink+0xed5/0x1550 [<00000000a5258f4a>] rtnl_newlink+0x66/0x90 [<00000000506568ee>] rtnetlink_rcv_msg+0x439/0xbd0 [<00000000b7eaeae1>] netlink_rcv_skb+0x14d/0x420 [<00000000c373ce66>] netlink_unicast+0x550/0x750 [<00000000ec74ce74>] netlink_sendmsg+0x88b/0xda0 [<00000000381ff246>] sock_sendmsg+0xc9/0x120 [<000000008f6a2db3>] ____sys_sendmsg+0x6e8/0x820 [<000000008d9c1735>] ___sys_sendmsg+0x145/0x1c0 [<00000000aa39dd8b>] __sys_sendmsg+0xfe/0x1d0 Calling garp_request_leave() after garp_request_join(), the attr->state is set to GARP_APPLICANT_VO, garp_attr_destroy() won't be called in last transmit event in garp_uninit_applicant(), the attr of applicant will be leaked. To fix this leak, iterate and free each attr of applicant before rerturning from garp_uninit_applicant(). Reported-by: Hulk Robot Signed-off-by: Yang Yingliang Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/802/garp.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/net/802/garp.c b/net/802/garp.c index b38ee6dcba45..5239b8f244e7 100644 --- a/net/802/garp.c +++ b/net/802/garp.c @@ -206,6 +206,19 @@ static void garp_attr_destroy(struct garp_applicant *app, struct garp_attr *attr kfree(attr); } +static void garp_attr_destroy_all(struct garp_applicant *app) +{ + struct rb_node *node, *next; + struct garp_attr *attr; + + for (node = rb_first(&app->gid); + next = node ? rb_next(node) : NULL, node != NULL; + node = next) { + attr = rb_entry(node, struct garp_attr, node); + garp_attr_destroy(app, attr); + } +} + static int garp_pdu_init(struct garp_applicant *app) { struct sk_buff *skb; @@ -612,6 +625,7 @@ void garp_uninit_applicant(struct net_device *dev, struct garp_application *appl spin_lock_bh(&app->lock); garp_gid_event(app, GARP_EVENT_TRANSMIT_PDU); + garp_attr_destroy_all(app); garp_pdu_queue(app); spin_unlock_bh(&app->lock); -- 2.30.2