Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp2920380pxb; Tue, 24 Aug 2021 10:37:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxvwkQUu7wNeEK2/13K6FQOk9SXwKThzhxdbU+vZ8aSWmNYIwDLQlBAAuPMKqOBVhlCBBkH X-Received: by 2002:a5d:9617:: with SMTP id w23mr31630876iol.115.1629826649076; Tue, 24 Aug 2021 10:37:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629826649; cv=none; d=google.com; s=arc-20160816; b=aRZ1ssmAAV9GDA8XRU7sjTpFGfw47dKtu4ZW9y+8XochiLdeDI6lbD/687u+vmu+pw fjdmjHBdcHUqWqwJ45VNamwxfT7AVc8+vUx1uGQYyepRFu1JrXwOOgHgoWk4Rs4KG4Kj Dmivvy53NhrLwoPOb8CFKHhJU0HOzNO1Lho769Bv6uLMVzCdYV4LnW+VNfm0SlEJZwQV UrPRwW9uce3ILopfzZOVZmu0B+oGebMDHVFlBxNzcz7J1OX4ryCY9srQUUVRe9CGmBYo 9xU/r6vXd7AOfL+4qp3SdM4uhtL8Rta7Z87pI3aiDpVzka76fSRsXp1AhqXwaRSFDSoi B2lA== 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=hDTSuGuQHDxJAfP1AzqeGACxS3DdDYTnLhw3BWXxRM4=; b=hIrfYnOTRXs5AhPz7u0WQZHGKAK0Nxnm6EHoq+EU64OJ8AN/phZMo72IqGGJVrTZ6s BKXoTDF1Lods4oysECYDpIi/BNyg32nZh8n9v56VcBmUq1zPleE6b5rSEXq0CWNP5rpe XAPibyD5LEDXU18npNf9kt1KOVtQcohbSymhygJhQiXHUCJ5dbH3ycKKqzuCfLzACeo3 zturB8cpAlRjpaxIYI5J7Y7+2tk43IiA5pHL4n19c3EttHd5Zws5iMhwVKegZd5DCwHP ohsOzSg8fpb8Ea1aUlDtKb3neiILkmMlRoFcAgtjAv/FcgnOaCysOk34soCN2ZwEyJbs YFVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=dqEOlHCG; 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 g3si20092573ila.102.2021.08.24.10.37.17; Tue, 24 Aug 2021 10:37:29 -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=dqEOlHCG; 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 S241760AbhHXRhQ (ORCPT + 99 others); Tue, 24 Aug 2021 13:37:16 -0400 Received: from mail.kernel.org ([198.145.29.99]:39354 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241713AbhHXRdW (ORCPT ); Tue, 24 Aug 2021 13:33:22 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2D1D36140F; Tue, 24 Aug 2021 17:06:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1629824784; bh=0QBw3X+/7FcbUQy85rd/5wiIH5Zq6mw0kscR9OvRReU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dqEOlHCGGXjh4eVkul0TOuvwW3BvE7oai5+hcz4Bx9qPhrSed62GtGnIW/YDjVbvI NdB7cSQylzrwWjpC0WPwboLKBS9cboPhm7C1N6WOeAWNVtMYpajIZI0eUZlNodFG6i tMkvrCjkbH5ANEacdeiYPr/YR4LtwEMuWN+YJXyVApgqoszRYq3xWOcmz0pNRjxeoT Bhdxgj0GOcL18sMUo/U2e9S1sIQhiE1e7Byu4SMljR2dDeROPyBrDYk5oTD+pmphoA xOKEkGnw8jcC7X0xlviIJtYaH7ACDGOMaPP9I4jB7C4N0C5ev0zzfSp3qaoBsMyXIm eJF3hUwYMJ0lw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Yang Yingliang , Hulk Robot , Nikolay Aleksandrov , Jakub Kicinski , Sasha Levin Subject: [PATCH 4.9 07/43] net: bridge: fix memleak in br_add_if() Date: Tue, 24 Aug 2021 13:05:38 -0400 Message-Id: <20210824170614.710813-8-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210824170614.710813-1-sashal@kernel.org> References: <20210824170614.710813-1-sashal@kernel.org> MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v4.x/stable-review/patch-4.9.281-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-4.9.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 4.9.281-rc1 X-KernelTest-Deadline: 2021-08-26T17:06+00:00 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Yang Yingliang [ Upstream commit 519133debcc19f5c834e7e28480b60bdc234fe02 ] I got a memleak report: BUG: memory leak unreferenced object 0x607ee521a658 (size 240): comm "syz-executor.0", pid 955, jiffies 4294780569 (age 16.449s) hex dump (first 32 bytes, cpu 1): 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ backtrace: [<00000000d830ea5a>] br_multicast_add_port+0x1c2/0x300 net/bridge/br_multicast.c:1693 [<00000000274d9a71>] new_nbp net/bridge/br_if.c:435 [inline] [<00000000274d9a71>] br_add_if+0x670/0x1740 net/bridge/br_if.c:611 [<0000000012ce888e>] do_set_master net/core/rtnetlink.c:2513 [inline] [<0000000012ce888e>] do_set_master+0x1aa/0x210 net/core/rtnetlink.c:2487 [<0000000099d1cafc>] __rtnl_newlink+0x1095/0x13e0 net/core/rtnetlink.c:3457 [<00000000a01facc0>] rtnl_newlink+0x64/0xa0 net/core/rtnetlink.c:3488 [<00000000acc9186c>] rtnetlink_rcv_msg+0x369/0xa10 net/core/rtnetlink.c:5550 [<00000000d4aabb9c>] netlink_rcv_skb+0x134/0x3d0 net/netlink/af_netlink.c:2504 [<00000000bc2e12a3>] netlink_unicast_kernel net/netlink/af_netlink.c:1314 [inline] [<00000000bc2e12a3>] netlink_unicast+0x4a0/0x6a0 net/netlink/af_netlink.c:1340 [<00000000e4dc2d0e>] netlink_sendmsg+0x789/0xc70 net/netlink/af_netlink.c:1929 [<000000000d22c8b3>] sock_sendmsg_nosec net/socket.c:654 [inline] [<000000000d22c8b3>] sock_sendmsg+0x139/0x170 net/socket.c:674 [<00000000e281417a>] ____sys_sendmsg+0x658/0x7d0 net/socket.c:2350 [<00000000237aa2ab>] ___sys_sendmsg+0xf8/0x170 net/socket.c:2404 [<000000004f2dc381>] __sys_sendmsg+0xd3/0x190 net/socket.c:2433 [<0000000005feca6c>] do_syscall_64+0x37/0x90 arch/x86/entry/common.c:47 [<000000007304477d>] entry_SYSCALL_64_after_hwframe+0x44/0xae On error path of br_add_if(), p->mcast_stats allocated in new_nbp() need be freed, or it will be leaked. Fixes: 1080ab95e3c7 ("net: bridge: add support for IGMP/MLD stats and export them via netlink") Reported-by: Hulk Robot Signed-off-by: Yang Yingliang Acked-by: Nikolay Aleksandrov Link: https://lore.kernel.org/r/20210809132023.978546-1-yangyingliang@huawei.com Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- net/bridge/br_if.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/net/bridge/br_if.c b/net/bridge/br_if.c index 4718c528e100..794fba20afbc 100644 --- a/net/bridge/br_if.c +++ b/net/bridge/br_if.c @@ -520,6 +520,7 @@ int br_add_if(struct net_bridge *br, struct net_device *dev) err = dev_set_allmulti(dev, 1); if (err) { + br_multicast_del_port(p); kfree(p); /* kobject not yet init'd, manually free */ goto err1; } @@ -624,6 +625,7 @@ err4: err3: sysfs_remove_link(br->ifobj, p->dev->name); err2: + br_multicast_del_port(p); kobject_put(&p->kobj); dev_set_allmulti(dev, -1); err1: -- 2.30.2