Received: by 2002:a05:6a10:c7c6:0:0:0:0 with SMTP id h6csp1638762pxy; Mon, 2 Aug 2021 06:50:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxDzRHQQFDt8UXBSQdVfD+dd9u9lJkZR+XPuk602aYPnn1kAhlFmXGk0ShWQCl6SO95UGgL X-Received: by 2002:a92:c0c3:: with SMTP id t3mr697913ilf.80.1627912244825; Mon, 02 Aug 2021 06:50:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627912244; cv=none; d=google.com; s=arc-20160816; b=JeIVkn6p5MXl2guhrIuxUG+qpLF7cc5jW9dkAldsl86XFcoRnXYMPLlLCuXRqABs7g hV4ap0COiz4wX3Ir7Mmux6MFbr5PTFl2sK9YANXBfZmawExCnCryTzK9G2OunidQZOa8 x82gXjYoeF8tRp82WVO4penOpMsITH1jQyQwtHsPS/CkycoGxFgyc0194hwfD8KdLJ0f NnGMUgfQ7QQNR5u1251ewRhnVZ194qnZz+LmjDzdF0ParQddENxojTa75ZMo19fO40ht VEoJQ0eAf/04LK6upiTAjjS13ia1P2OCk1QyARp6sbyv6duNA/QabpwHGVdKLpwolLGW KNRw== 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=Oc9RfDJ5Be9MW1Rp2aaEToMKYzU11wRt8gbdvnAhCBA=; b=IWeyvjp0/jBcntcev+JJKugCq+g5c7boJIgpqskdCMmsoA1O0W+kyKBgutt4ldK39M oz+qX+lMM2Ih5pIzZJGyjKO0V6XDIlxoztHBymKmBECCAmCJSBi9ewEXVJuHDZ2HTIHs d0XDBv/n0LCJjRN4qZZkjb7PgDrfna/2KknVxBxXCiuY/eoUWCM+Sbb5nKr+ipHKuW+U B0rg2820hVv/aOE9V8yrGq+uNiJSP/gZNckQfJnQnze9FVLlFrK1p00rFsADydUX1RBx mrkqWRBytKXTST6w1YPuG2jiS5dTZWmrFTHk0wABaY97sDkhTTFyL0XQpKmk7wD7U1S0 haOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=uLD6Fjgo; 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 j30si11648273ila.56.2021.08.02.06.50.33; Mon, 02 Aug 2021 06:50:44 -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=uLD6Fjgo; 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 S234512AbhHBNsz (ORCPT + 99 others); Mon, 2 Aug 2021 09:48:55 -0400 Received: from mail.kernel.org ([198.145.29.99]:57096 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233984AbhHBNrS (ORCPT ); Mon, 2 Aug 2021 09:47:18 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id B322960EBB; Mon, 2 Aug 2021 13:47:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1627912024; bh=gcRNNfMiXFcKk4tWGirTCkC3Ks8AkDuQgrrRNPgdTg0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uLD6Fjgozf7gJ2LQDL2LT6PLv6om3SZbpThaM9IfqYpNp6UssnuraoBfp8yJ3wMw8 wOcen74mL3NIuya5KvWamjOkUWdqbDEFIX/gNRtZYEWrnIRd9cQ/tHUV0Uni0ihGDv JH8lx47fmrlqsgsO3V6NepdkpqshN78jZzdw1saE= 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 06/32] net/802/mrp: fix memleak in mrp_request_join() Date: Mon, 2 Aug 2021 15:44:26 +0200 Message-Id: <20210802134333.129599408@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 996af62167d0e0ec69b938a3561e96f84ffff1aa ] I got kmemleak report when doing fuzz test: BUG: memory leak unreferenced object 0xffff88810c239500 (size 64): comm "syz-executor940", pid 882, jiffies 4294712870 (age 14.631s) 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 01 00 00 00 01 02 00 04 ................ backtrace: [<00000000a323afa4>] slab_alloc_node mm/slub.c:2972 [inline] [<00000000a323afa4>] slab_alloc mm/slub.c:2980 [inline] [<00000000a323afa4>] __kmalloc+0x167/0x340 mm/slub.c:4130 [<000000005034ca11>] kmalloc include/linux/slab.h:595 [inline] [<000000005034ca11>] mrp_attr_create net/802/mrp.c:276 [inline] [<000000005034ca11>] mrp_request_join+0x265/0x550 net/802/mrp.c:530 [<00000000fcfd81f3>] vlan_mvrp_request_join+0x145/0x170 net/8021q/vlan_mvrp.c:40 [<000000009258546e>] vlan_dev_open+0x477/0x890 net/8021q/vlan_dev.c:292 [<0000000059acd82b>] __dev_open+0x281/0x410 net/core/dev.c:1609 [<000000004e6dc695>] __dev_change_flags+0x424/0x560 net/core/dev.c:8767 [<00000000471a09af>] rtnl_configure_link+0xd9/0x210 net/core/rtnetlink.c:3122 [<0000000037a4672b>] __rtnl_newlink+0xe08/0x13e0 net/core/rtnetlink.c:3448 [<000000008d5d0fda>] rtnl_newlink+0x64/0xa0 net/core/rtnetlink.c:3488 [<000000004882fe39>] rtnetlink_rcv_msg+0x369/0xa10 net/core/rtnetlink.c:5552 [<00000000907e6c54>] netlink_rcv_skb+0x134/0x3d0 net/netlink/af_netlink.c:2504 [<00000000e7d7a8c4>] netlink_unicast_kernel net/netlink/af_netlink.c:1314 [inline] [<00000000e7d7a8c4>] netlink_unicast+0x4a0/0x6a0 net/netlink/af_netlink.c:1340 [<00000000e0645d50>] netlink_sendmsg+0x78e/0xc90 net/netlink/af_netlink.c:1929 [<00000000c24559b7>] sock_sendmsg_nosec net/socket.c:654 [inline] [<00000000c24559b7>] sock_sendmsg+0x139/0x170 net/socket.c:674 [<00000000fc210bc2>] ____sys_sendmsg+0x658/0x7d0 net/socket.c:2350 [<00000000be4577b5>] ___sys_sendmsg+0xf8/0x170 net/socket.c:2404 Calling mrp_request_leave() after mrp_request_join(), the attr->state is set to MRP_APPLICANT_VO, mrp_attr_destroy() won't be called in last TX event in mrp_uninit_applicant(), the attr of applicant will be leaked. To fix this leak, iterate and free each attr of applicant before rerturning from mrp_uninit_applicant(). Reported-by: Hulk Robot Signed-off-by: Yang Yingliang Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/802/mrp.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/net/802/mrp.c b/net/802/mrp.c index 72db2785ef2c..4ee3af3d400b 100644 --- a/net/802/mrp.c +++ b/net/802/mrp.c @@ -295,6 +295,19 @@ static void mrp_attr_destroy(struct mrp_applicant *app, struct mrp_attr *attr) kfree(attr); } +static void mrp_attr_destroy_all(struct mrp_applicant *app) +{ + struct rb_node *node, *next; + struct mrp_attr *attr; + + for (node = rb_first(&app->mad); + next = node ? rb_next(node) : NULL, node != NULL; + node = next) { + attr = rb_entry(node, struct mrp_attr, node); + mrp_attr_destroy(app, attr); + } +} + static int mrp_pdu_init(struct mrp_applicant *app) { struct sk_buff *skb; @@ -900,6 +913,7 @@ void mrp_uninit_applicant(struct net_device *dev, struct mrp_application *appl) spin_lock_bh(&app->lock); mrp_mad_event(app, MRP_EVENT_TX); + mrp_attr_destroy_all(app); mrp_pdu_queue(app); spin_unlock_bh(&app->lock); -- 2.30.2