All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] netfilter/x_tables: go back to using vmalloc
@ 2025-09-22 19:48 Daniil Tatianin
  2025-09-22 19:48 ` [PATCH 1/3] netfilter/x_tables: go back to using vmalloc for xt_table_info Daniil Tatianin
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Daniil Tatianin @ 2025-09-22 19:48 UTC (permalink / raw)
  To: Pablo Neira Ayuso
  Cc: Daniil Tatianin, Jozsef Kadlecsik, Florian Westphal, Phil Sutter,
	David S. Miller, David Ahern, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Simon Horman, netfilter-devel, coreteam,
	linux-kernel, netdev

This series aims to replace most calls to kvmalloc whose size directly depends
on user input with vmalloc. This was actually the way xt_table_info was
previously allocated if it ended up being too large back in 2017 before it got
replaced with a call to kvmalloc in the
commit eacd86ca3b036 ("net/netfilter/x_tables.c: use kvmalloc() in xt_alloc_table_info()").

The commit that changed it did so because "xt_alloc_table_info()
basically opencodes kvmalloc()", which is not actually what it was
doing. kvmalloc() does not attempt to go directly to vmalloc if the
order the caller is trying to allocate is "expensive", instead it only
uses vmalloc as a fallback in case the buddy allocator is not able to
fullfill the request.

The difference between the two is actually huge in case the system is
under memory pressure and has no free pages of a large order. Before the
change to kvmalloc we wouldn't even try going to the buddy allocator for
large orders, but now we would force it to try to find a page of the
required order by waking up kswapd/kcompactd and dropping reclaimable memory
for no reason at all to satisfy our huge order allocation that could easily
exist within vmalloc'ed memory instead.

Revert the change to always call vmalloc, since this code doesn't really
benefit from contiguous physical memory, and the size it allocates is
directly dictated by the userspace-passed table buffer thus allowing it to
torture the buddy allocator by carefully crafting a huge table that fits
right at the maximum available memory order on the system.

This series also touches the allocation of entry_offsets, since they suffer
from the same issue.

Daniil Tatianin (3):
  netfilter/x_tables: go back to using vmalloc for xt_table_info
  netfilter/x_tables: introduce a helper for freeing entry offsets
  netfilter/x_tables: allocate entry_offsets with vcalloc

 include/linux/netfilter/x_tables.h |  1 +
 net/ipv4/netfilter/arp_tables.c    |  4 ++--
 net/ipv4/netfilter/ip_tables.c     |  4 ++--
 net/ipv6/netfilter/ip6_tables.c    |  4 ++--
 net/netfilter/x_tables.c           | 12 +++++++++---
 5 files changed, 16 insertions(+), 9 deletions(-)

-- 
2.34.1


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2025-09-23 12:23 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-22 19:48 [PATCH 0/3] netfilter/x_tables: go back to using vmalloc Daniil Tatianin
2025-09-22 19:48 ` [PATCH 1/3] netfilter/x_tables: go back to using vmalloc for xt_table_info Daniil Tatianin
2025-09-22 21:12   ` Eric Dumazet
2025-09-23 10:11     ` Daniil Tatianin
2025-09-23 11:36       ` Florian Westphal
2025-09-23 12:04         ` Daniil Tatianin
2025-09-23 12:22           ` Eric Dumazet
2025-09-22 19:48 ` [PATCH 2/3] netfilter/x_tables: introduce a helper for freeing entry offsets Daniil Tatianin
2025-09-22 19:48 ` [PATCH 3/3] netfilter/x_tables: allocate entry_offsets with vcalloc Daniil Tatianin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.