Skip to content

Commit

Permalink
netfilter: ipset: Fix warn: integer overflows 'sizeof(*map) + size * …
Browse files Browse the repository at this point in the history
…set->dsize'

Dan Carpenter reported that the static checker emits the warning

        net/netfilter/ipset/ip_set_list_set.c:600 init_list_set()
        warn: integer overflows 'sizeof(*map) + size * set->dsize'

Limit the maximal number of elements in list type of sets.

Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
  • Loading branch information
Jozsef Kadlecsik committed Aug 24, 2014
1 parent 94729f8 commit 1b05756
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions include/linux/netfilter/ipset/ip_set_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@

#define IP_SET_LIST_DEFAULT_SIZE 8
#define IP_SET_LIST_MIN_SIZE 4
#define IP_SET_LIST_MAX_SIZE 65536

#endif /* __IP_SET_LIST_H */
4 changes: 3 additions & 1 deletion net/netfilter/ipset/ip_set_list_set.c
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,9 @@ init_list_set(struct net *net, struct ip_set *set, u32 size)
struct set_elem *e;
u32 i;

map = kzalloc(sizeof(*map) + size * set->dsize, GFP_KERNEL);
map = kzalloc(sizeof(*map) +
min_t(u32, size, IP_SET_LIST_MAX_SIZE) * set->dsize,
GFP_KERNEL);
if (!map)
return false;

Expand Down

0 comments on commit 1b05756

Please sign in to comment.