The IPv4 and IPv6 multicast memberships of a socket and their source filter lists are allocated with sock_kmalloc(). It limits them with the socket's optmem_max budget, but does not charge them to the memory cgroup. IPv6 has no other limit on the number of memberships, so an unprivileged task can keep up to optmem_max (128 KiB by default) of them per socket outside its memory.max limit. Use GFP_KERNEL_ACCOUNT for these allocations. sock_kmalloc() itself is left alone: it also serves short-lived buffers, such as control messages in sendmsg(), and allocations made in softirq context. Other long-lived sock_kmalloc() users, such as TCP-MD5 and TCP-AO keys, IPv6 anycast memberships and IPv6 extension header options, are not changed here. The device records that the same joins create are handled in the next patch, which also has the measurements. Signed-off-by: Yingjie Wang --- net/ipv4/igmp.c | 6 +++--- net/ipv6/mcast.c | 9 +++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/net/ipv4/igmp.c b/net/ipv4/igmp.c index 446c49db1adf..1ed7192e7cd6 100644 --- a/net/ipv4/igmp.c +++ b/net/ipv4/igmp.c @@ -2388,7 +2388,7 @@ static int __ip_mc_join_group(struct sock *sk, struct ip_mreqn *imr, err = -ENOBUFS; if (count >= READ_ONCE(net->ipv4.sysctl_igmp_max_memberships)) goto done; - iml = sock_kmalloc(sk, sizeof(*iml), GFP_KERNEL); + iml = sock_kmalloc(sk, sizeof(*iml), GFP_KERNEL_ACCOUNT); if (!iml) goto done; @@ -2587,7 +2587,7 @@ int ip_mc_source(int add, int omode, struct sock *sk, struct if (psl) count += psl->sl_max; newpsl = sock_kmalloc(sk, struct_size(newpsl, sl_addr, count), - GFP_KERNEL); + GFP_KERNEL_ACCOUNT); if (!newpsl) { err = -ENOBUFS; goto done; @@ -2691,7 +2691,7 @@ int ip_mc_msfilter(struct sock *sk, struct ip_msfilter *msf, int ifindex) if (msf->imsf_numsrc) { newpsl = sock_kmalloc(sk, struct_size(newpsl, sl_addr, msf->imsf_numsrc), - GFP_KERNEL); + GFP_KERNEL_ACCOUNT); if (!newpsl) { err = -ENOBUFS; goto done; diff --git a/net/ipv6/mcast.c b/net/ipv6/mcast.c index da456f006f85..a9f2e474fad0 100644 --- a/net/ipv6/mcast.c +++ b/net/ipv6/mcast.c @@ -213,7 +213,8 @@ static int __ipv6_sock_mc_join(struct sock *sk, int ifindex, return -EADDRINUSE; } - mc_lst = sock_kmalloc(sk, sizeof(struct ipv6_mc_socklist), GFP_KERNEL); + mc_lst = sock_kmalloc(sk, sizeof(struct ipv6_mc_socklist), + GFP_KERNEL_ACCOUNT); if (!mc_lst) return -ENOMEM; @@ -427,7 +428,7 @@ int ip6_mc_source(int add, int omode, struct sock *sk, } else { newpsl = sock_kmalloc(sk, struct_size(newpsl, sl_addr, psl->sl_count - 1), - GFP_KERNEL); + GFP_KERNEL_ACCOUNT); if (!newpsl) { atomic_add(struct_size(psl, sl_addr, psl->sl_max), &sk->sk_omem_alloc); @@ -465,7 +466,7 @@ int ip6_mc_source(int add, int omode, struct sock *sk, i = psl ? psl->sl_count + 1 : 1; newpsl = sock_kmalloc(sk, struct_size(newpsl, sl_addr, i), - GFP_KERNEL); + GFP_KERNEL_ACCOUNT); if (!newpsl) { err = -ENOBUFS; goto done; @@ -559,7 +560,7 @@ int ip6_mc_msfilter(struct sock *sk, struct group_filter *gsf, if (gsf->gf_numsrc) { newpsl = sock_kmalloc(sk, struct_size(newpsl, sl_addr, gsf->gf_numsrc), - GFP_KERNEL); + GFP_KERNEL_ACCOUNT); if (!newpsl) { err = -ENOBUFS; goto done; -- 2.43.0