Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp10528419ybi; Thu, 25 Jul 2019 00:58:03 -0700 (PDT) X-Google-Smtp-Source: APXvYqwTcXJDxAq74XKzr9rsZjDDqnebWRirh339OHmIG6mTJhTkgZeI4yKEURnNqyMwTi8vsIlT X-Received: by 2002:a63:7c0d:: with SMTP id x13mr45485107pgc.360.1564041483741; Thu, 25 Jul 2019 00:58:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564041483; cv=none; d=google.com; s=arc-20160816; b=xSNU5PYol+7OzigSYNGSUrV7RrWCDC6jTRdcFJcMvksO1UmBmi4PAhxGO4+fxuFDZW zK3qp/BxTtA55pCsKWb2b1thEiCcxRcriAuJocXRk7PKT6RJQTcbV/haauD1P7xaXWsU GhBGC1vndjBWfIxmGGfHkvVYK6bSHqQx/pVUIQ9SEg1RRid8zUWtK5KwWLcj45QSoZCQ 6oLvbfQdnUw9xc8HiWUd2hRWju2o6IqUfslsW/9JyZ/JeJ7jB6/VMf+ijEhNLKiUgRyh P8vil1yLbJc+og0w3nhDnCEPjd4xM4C3YTaQDf6I12wXn7AVJuGOAxOATgR0AFfABiTG YQ5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=KH8RfAv26SVj9bzKj5wFlnu1bPzKftRawaY1t9p80Dk=; b=J/pquAM0pgKerV/yySJc30pbCd8weP3W4i9p4OIcZcxcv1ixbVDCOdUbeaBoZ10sTM HUq/ouzKmodGz9Y83OAV5ZBNtuEny6/asY7Xr8UwzYopUl5v3dAObcX9ncoE/U4Khvkq ssIblYofTn9Ag9beNihaEuFu2tor9paDxUY6QkH16Gv5+H6ng6YhYMZ+RvC4/dMwTEqJ 79WyCG2iOUS41Qsm0CjpSX7CYTYx1haCQrAAkI0J1u0eeVDao1eVll1s/7/LNWZD52MC bYD10XxNaE/Zvx11dvnK4+4RONN5FibSWHWbhJzcZJm2Po4PvcKaRMSZ/txeUHzUqVuA GFlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=xsLa4GUW; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id co12si15266972plb.197.2019.07.25.00.57.44; Thu, 25 Jul 2019 00:58:03 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=xsLa4GUW; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2392169AbfGXUFg (ORCPT + 99 others); Wed, 24 Jul 2019 16:05:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:56934 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405599AbfGXUF1 (ORCPT ); Wed, 24 Jul 2019 16:05:27 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 721D122BEB; Wed, 24 Jul 2019 20:05:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563998725; bh=RWDkj6XAKmq3XXr6cWD15HEkRUTqI2yjE//w6QAZ1uw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xsLa4GUWU1kIBtEdFgitEwvQ4co6nNIrGH2Tw7+uXneaBKOezwvenmjPnFVYPwc8V F3tPHv2yyP7cBEndIX9ol6s9syozBGCzihpf/6bE2b9kQ6Q7XCcxAOeMOm9a7qatTL SdoXLyv+AjmFGNzb9ZADZi0jPia/0pHnRfJzKF2A= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+722da59ccb264bc19910@syzkaller.appspotmail.com, Julian Anastasov , Simon Horman , Pablo Neira Ayuso , Sasha Levin Subject: [PATCH 4.19 093/271] ipvs: defer hook registration to avoid leaks Date: Wed, 24 Jul 2019 21:19:22 +0200 Message-Id: <20190724191703.193283768@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190724191655.268628197@linuxfoundation.org> References: <20190724191655.268628197@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit cf47a0b882a4e5f6b34c7949d7b293e9287f1972 ] syzkaller reports for memory leak when registering hooks [1] As we moved the nf_unregister_net_hooks() call into __ip_vs_dev_cleanup(), defer the nf_register_net_hooks() call, so that hooks are allocated and freed from same pernet_operations (ipvs_core_dev_ops). [1] BUG: memory leak unreferenced object 0xffff88810acd8a80 (size 96): comm "syz-executor073", pid 7254, jiffies 4294950560 (age 22.250s) hex dump (first 32 bytes): 02 00 00 00 00 00 00 00 50 8b bb 82 ff ff ff ff ........P....... 00 00 00 00 00 00 00 00 00 77 bb 82 ff ff ff ff .........w...... backtrace: [<0000000013db61f1>] kmemleak_alloc_recursive include/linux/kmemleak.h:55 [inline] [<0000000013db61f1>] slab_post_alloc_hook mm/slab.h:439 [inline] [<0000000013db61f1>] slab_alloc_node mm/slab.c:3269 [inline] [<0000000013db61f1>] kmem_cache_alloc_node_trace+0x15b/0x2a0 mm/slab.c:3597 [<000000001a27307d>] __do_kmalloc_node mm/slab.c:3619 [inline] [<000000001a27307d>] __kmalloc_node+0x38/0x50 mm/slab.c:3627 [<0000000025054add>] kmalloc_node include/linux/slab.h:590 [inline] [<0000000025054add>] kvmalloc_node+0x4a/0xd0 mm/util.c:431 [<0000000050d1bc00>] kvmalloc include/linux/mm.h:637 [inline] [<0000000050d1bc00>] kvzalloc include/linux/mm.h:645 [inline] [<0000000050d1bc00>] allocate_hook_entries_size+0x3b/0x60 net/netfilter/core.c:61 [<00000000e8abe142>] nf_hook_entries_grow+0xae/0x270 net/netfilter/core.c:128 [<000000004b94797c>] __nf_register_net_hook+0x9a/0x170 net/netfilter/core.c:337 [<00000000d1545cbc>] nf_register_net_hook+0x34/0xc0 net/netfilter/core.c:464 [<00000000876c9b55>] nf_register_net_hooks+0x53/0xc0 net/netfilter/core.c:480 [<000000002ea868e0>] __ip_vs_init+0xe8/0x170 net/netfilter/ipvs/ip_vs_core.c:2280 [<000000002eb2d451>] ops_init+0x4c/0x140 net/core/net_namespace.c:130 [<000000000284ec48>] setup_net+0xde/0x230 net/core/net_namespace.c:316 [<00000000a70600fa>] copy_net_ns+0xf0/0x1e0 net/core/net_namespace.c:439 [<00000000ff26c15e>] create_new_namespaces+0x141/0x2a0 kernel/nsproxy.c:107 [<00000000b103dc79>] copy_namespaces+0xa1/0xe0 kernel/nsproxy.c:165 [<000000007cc008a2>] copy_process.part.0+0x11fd/0x2150 kernel/fork.c:2035 [<00000000c344af7c>] copy_process kernel/fork.c:1800 [inline] [<00000000c344af7c>] _do_fork+0x121/0x4f0 kernel/fork.c:2369 Reported-by: syzbot+722da59ccb264bc19910@syzkaller.appspotmail.com Fixes: 719c7d563c17 ("ipvs: Fix use-after-free in ip_vs_in") Signed-off-by: Julian Anastasov Acked-by: Simon Horman Signed-off-by: Pablo Neira Ayuso Signed-off-by: Sasha Levin --- net/netfilter/ipvs/ip_vs_core.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c index 62c0e80dcd71..a71f777d1353 100644 --- a/net/netfilter/ipvs/ip_vs_core.c +++ b/net/netfilter/ipvs/ip_vs_core.c @@ -2218,7 +2218,6 @@ static const struct nf_hook_ops ip_vs_ops[] = { static int __net_init __ip_vs_init(struct net *net) { struct netns_ipvs *ipvs; - int ret; ipvs = net_generic(net, ip_vs_net_id); if (ipvs == NULL) @@ -2250,17 +2249,11 @@ static int __net_init __ip_vs_init(struct net *net) if (ip_vs_sync_net_init(ipvs) < 0) goto sync_fail; - ret = nf_register_net_hooks(net, ip_vs_ops, ARRAY_SIZE(ip_vs_ops)); - if (ret < 0) - goto hook_fail; - return 0; /* * Error handling */ -hook_fail: - ip_vs_sync_net_cleanup(ipvs); sync_fail: ip_vs_conn_net_cleanup(ipvs); conn_fail: @@ -2290,6 +2283,19 @@ static void __net_exit __ip_vs_cleanup(struct net *net) net->ipvs = NULL; } +static int __net_init __ip_vs_dev_init(struct net *net) +{ + int ret; + + ret = nf_register_net_hooks(net, ip_vs_ops, ARRAY_SIZE(ip_vs_ops)); + if (ret < 0) + goto hook_fail; + return 0; + +hook_fail: + return ret; +} + static void __net_exit __ip_vs_dev_cleanup(struct net *net) { struct netns_ipvs *ipvs = net_ipvs(net); @@ -2309,6 +2315,7 @@ static struct pernet_operations ipvs_core_ops = { }; static struct pernet_operations ipvs_core_dev_ops = { + .init = __ip_vs_dev_init, .exit = __ip_vs_dev_cleanup, }; -- 2.20.1