Memory allocation issues after "sysctl: Convert to iter interfaces"

From: Ivan Babrou
Date: Wed Feb 24 2021 - 20:04:43 EST


Hello,

We started seeing allocation failures on procfs reads after
commit 4bd6a7353ee1 "sysctl: Convert to iter interfaces".

I haven't done a full bisect, but the decoded stacks point
squarely at the following piece of code which was introduced:

kbuf = kzalloc(count + 1, GFP_KERNEL);

Previously reading /proc/sys/net/core/somaxconn required order 1
and order 3 allocations from the kernel, which can be seen from:

$ sudo perf record -g -e kmem:mm_page_alloc_zone_locked -- \
cat /proc/sys/net/core/somaxconn

Now we see order 6 + order 6 allocations from cat, and even:

read(3, 0x7f8d9d3f3000, 131072) = -1 ENOMEM (Cannot allocate memory)

See the following gist for full allocation stacks on 5.4 and 5.10:

* https://gist.github.com/bobrik/dd03cce0aaeef5acd5faecc32bd44530

This seems like a regression, and unprivileged users being
able to force order 6 allocations onto the kernel doesn't feel good.