Skip to content

Commit 1ce101e

Browse files
David LaightKernel Patches Daemon
authored andcommitted
net/netlink: Use umin() to avoid min_t(int, ...) discarding high bits
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 <[email protected]>
1 parent f57a33b commit 1ce101e

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

net/netlink/genetlink.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -395,10 +395,11 @@ static unsigned int genl_op_iter_idx(struct genl_op_iter *iter)
395395
return iter->cmd_idx;
396396
}
397397

398-
static int genl_allocate_reserve_groups(int n_groups, int *first_id)
398+
static noinline_for_stack int genl_allocate_reserve_groups(int n_groups, int *first_id)
399399
{
400400
unsigned long *new_groups;
401401
int start = 0;
402+
int limit;
402403
int i;
403404
int id;
404405
bool fits;
@@ -414,10 +415,8 @@ static int genl_allocate_reserve_groups(int n_groups, int *first_id)
414415
start);
415416

416417
fits = true;
417-
for (i = id;
418-
i < min_t(int, id + n_groups,
419-
mc_groups_longs * BITS_PER_LONG);
420-
i++) {
418+
limit = umin(id + n_groups, mc_groups_longs * BITS_PER_LONG);
419+
for (i = id; i < limit; i++) {
421420
if (test_bit(i, mc_groups)) {
422421
start = i;
423422
fits = false;

0 commit comments

Comments
 (0)