mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH net] Fix clamp() of ip_vs_conn_tab on small memory systems.
@ 2024-12-06 10:27 David Laight
  2024-12-06 12:19 ` Julian Anastasov
  0 siblings, 1 reply; 6+ messages in thread
From: David Laight @ 2024-12-06 10:27 UTC (permalink / raw)
  To: netdev, 'Naresh Kamboju', 'Dan Carpenter',
	Julian Anastasov, 'pablo@netfilter.org'
  Cc: 'open list', 'lkft-triage@lists.linaro.org',
	'Linux Regressions', 'Linux ARM',
	'netfilter-devel@vger.kernel.org',
	'Arnd Bergmann', 'Anders Roxell',
	'Johannes Berg', 'toke@kernel.org',
	'Al Viro', 'kernel@jfarr.cc',
	'kees@kernel.org'

The intention of the code seems to be that the minimum table
size should be 256 (1 << min).
However the code uses max = clamp(20, 5, max_avail) which implies
the author thought max_avail could be less than 5.
But clamp(val, min, max) is only well defined for max >= min.
If max < min whether is returns min or max depends on the order of
the comparisons.

Change to clamp(max_avail, 5, 20) which has the expected behaviour.

Replace the clamp_val() on the line below with clamp().
clamp_val() is just 'an accident waiting to happen' and not needed here.

Fixes: 4f325e26277b6
(Although I actually doubt the code is used on small memory systems.)

Detected by compile time checks added to clamp(), specifically:
minmax.h: use BUILD_BUG_ON_MSG() for the lo < hi test in clamp()

Signed-off-by: David Laight <david.laight@aculab.com>
---
 net/netfilter/ipvs/ip_vs_conn.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
index 98d7dbe3d787..c0289f83f96d 100644
--- a/net/netfilter/ipvs/ip_vs_conn.c
+++ b/net/netfilter/ipvs/ip_vs_conn.c
@@ -1495,8 +1495,8 @@ int __init ip_vs_conn_init(void)
 	max_avail -= 2;		/* ~4 in hash row */
 	max_avail -= 1;		/* IPVS up to 1/2 of mem */
 	max_avail -= order_base_2(sizeof(struct ip_vs_conn));
-	max = clamp(max, min, max_avail);
-	ip_vs_conn_tab_bits = clamp_val(ip_vs_conn_tab_bits, min, max);
+	max = clamp(max_avail, min, max);
+	ip_vs_conn_tab_bits = clamp(ip_vs_conn_tab_bits, min, max);
 	ip_vs_conn_tab_size = 1 << ip_vs_conn_tab_bits;
 	ip_vs_conn_tab_mask = ip_vs_conn_tab_size - 1;
 
-- 
2.17.1

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)


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

end of thread, other threads:[~2024-12-06 20:58 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-12-06 10:27 [PATCH net] Fix clamp() of ip_vs_conn_tab on small memory systems David Laight
2024-12-06 12:19 ` Julian Anastasov
2024-12-06 13:07   ` David Laight
2024-12-06 16:23     ` Julian Anastasov
2024-12-06 17:53       ` David Laight
2024-12-06 20:58         ` Julian Anastasov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®