[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20251119224140.8616-44-david.laight.linux@gmail.com>
Date: Wed, 19 Nov 2025 22:41:39 +0000
From: david.laight.linux@...il.com
To: linux-kernel@...r.kernel.org,
netdev@...r.kernel.org
Cc: "David S. Miller" <davem@...emloft.net>,
Eric Dumazet <edumazet@...gle.com>,
Jakub Kicinski <kuba@...nel.org>,
Paolo Abeni <pabeni@...hat.com>,
David Laight <david.laight.linux@...il.com>
Subject: [PATCH 43/44] net/netlink: Use umin() to avoid min_t(int, ...) discarding high bits
From: David Laight <david.laight.linux@...il.com>
The scan limit in genl_allocate_reserve_groups() is:
min_t(int, id + n_groups, mc_groups_longs * BITS_PER_LONG);
While 'id' and 'n_groups' are both 'int', 'mc_groups_longs' is
'unsigned long' (BITS_PER_LONG is 'int').
These inconsistent types (all the values are small and non-negative)
means that a simple min() fails.
When checks for masking high bits are added to min_t() that also fails.
Instead use umin() so safely convert all the values to unsigned.
Move the limit calculation outside the loop for efficiency and
readability.
Signed-off-by: David Laight <david.laight.linux@...il.com>
---
net/netlink/genetlink.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/net/netlink/genetlink.c b/net/netlink/genetlink.c
index 978c129c6095..a802dd8ead2d 100644
--- a/net/netlink/genetlink.c
+++ b/net/netlink/genetlink.c
@@ -395,10 +395,11 @@ static unsigned int genl_op_iter_idx(struct genl_op_iter *iter)
return iter->cmd_idx;
}
-static int genl_allocate_reserve_groups(int n_groups, int *first_id)
+static noinline_for_stack int genl_allocate_reserve_groups(int n_groups, int *first_id)
{
unsigned long *new_groups;
int start = 0;
+ int limit;
int i;
int id;
bool fits;
@@ -414,10 +415,8 @@ static int genl_allocate_reserve_groups(int n_groups, int *first_id)
start);
fits = true;
- for (i = id;
- i < min_t(int, id + n_groups,
- mc_groups_longs * BITS_PER_LONG);
- i++) {
+ limit = umin(id + n_groups, mc_groups_longs * BITS_PER_LONG);
+ for (i = id; i < limit; i++) {
if (test_bit(i, mc_groups)) {
start = i;
fits = false;
--
2.39.5
Powered by blists - more mailing lists