]> git.hungrycats.org Git - linux/commitdiff
ipmr: account multicast table and route memory
authorZihan Xi <zihanx@nebusec.ai>
Tue, 8 Sep 2026 11:58:39 +0000 (11:58 +0000)
committerJakub Kicinski <kuba@kernel.org>
Thu, 10 Sep 2026 15:48:44 +0000 (08:48 -0700)
A netadmin in a user+net namespace can create many IPv4 and IPv6
multicast routing tables with MRT_TABLE and MRT6_TABLE. Each unseen
id allocates an mr_table via the shared mr_table_alloc(), links it
into the per-net list, and leaves it until netns teardown. Those
objects were not charged to memcg, so the host unreclaimable slab
grows with the table count.

Account mr_table allocations with GFP_KERNEL_ACCOUNT and mark the
IPv4/IPv6 MFC caches SLAB_ACCOUNT. This matches the established
handling of IP addresses, routes and alternate interface names.

Unresolved MFC entries are still allocated from softIRQ with
GFP_ATOMIC and are not charged. They expire after 10 seconds and are
bounded by the socket receive queue; see commit 0079ad8e8dc3
("ipmr: remove hard code cache_resolve_queue_len limit").

Fixes: f0ad0860d01e ("ipv4: ipmr: support multiple tables")
Fixes: d1db275dd3f6 ("ipv6: ip6mr: support multiple tables")
Cc: stable@vger.kernel.org
Reported-by: Vega <vega@nebusec.ai>
Signed-off-by: Zihan Xi <zihanx@nebusec.ai>
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
Link: https://patch.msgid.link/050b58f7fc6b45da0fb12768ebb62d18fa46133d.1788784801.git.zihanx@nebusec.ai
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/ipv4/ipmr.c
net/ipv4/ipmr_base.c
net/ipv6/ip6mr.c

index e5f2b1c6150d2f6b2084c2ebaef6047db869cc87..b9c544d48c45219bd3a83b7e1fc5fa4cc4d5cb98 100644 (file)
@@ -3376,7 +3376,8 @@ int __init ip_mr_init(void)
 {
        int err;
 
-       mrt_cachep = KMEM_CACHE(mfc_cache, SLAB_HWCACHE_ALIGN | SLAB_PANIC);
+       mrt_cachep = KMEM_CACHE(mfc_cache,
+                               SLAB_HWCACHE_ALIGN | SLAB_PANIC | SLAB_ACCOUNT);
 
        err = register_pernet_subsys(&ipmr_net_ops);
        if (err)
index 867b24beded112150e7bb29620617390b05898c2..a0ec6d19a237ff3533443229c46e26aa9ed5d6da 100644 (file)
@@ -52,7 +52,7 @@ mr_table_alloc(struct net *net, u32 id,
        struct mr_table *mrt;
        int err;
 
-       mrt = kzalloc_obj(*mrt);
+       mrt = kzalloc_obj(*mrt, GFP_KERNEL_ACCOUNT);
        if (!mrt)
                return ERR_PTR(-ENOMEM);
        mrt->id = id;
index 3f2ed9b77deb51799f34e3826ae271d8d3e2a2dd..9d8116b5edb173e39d9d66ac119e5df05d683abe 100644 (file)
@@ -1427,7 +1427,7 @@ int __init ip6_mr_init(void)
 {
        int err;
 
-       mrt_cachep = KMEM_CACHE(mfc6_cache, SLAB_HWCACHE_ALIGN);
+       mrt_cachep = KMEM_CACHE(mfc6_cache, SLAB_HWCACHE_ALIGN | SLAB_ACCOUNT);
        if (!mrt_cachep)
                return -ENOMEM;