Skip to content

Commit 80b78c3

Browse files
Dan Carpenterummakynes
authored andcommitted
ipvs: prevent integer overflow in do_ip_vs_get_ctl()
The get->num_services variable is an unsigned int which is controlled by the user. The struct_size() function ensures that the size calculation does not overflow an unsigned long, however, we are saving the result to an int so the calculation can overflow. Both "len" and "get->num_services" come from the user. This check is just a sanity check to help the user and ensure they are using the API correctly. An integer overflow here is not a big deal. This has no security impact. Save the result from struct_size() type size_t to fix this integer overflow bug. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org> Acked-by: Julian Anastasov <ja@ssi.bg> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
1 parent c21b02f commit 80b78c3

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

net/netfilter/ipvs/ip_vs_ctl.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3091,12 +3091,12 @@ do_ip_vs_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
30913091
case IP_VS_SO_GET_SERVICES:
30923092
{
30933093
struct ip_vs_get_services *get;
3094-
int size;
3094+
size_t size;
30953095

30963096
get = (struct ip_vs_get_services *)arg;
30973097
size = struct_size(get, entrytable, get->num_services);
30983098
if (*len != size) {
3099-
pr_err("length: %u != %u\n", *len, size);
3099+
pr_err("length: %u != %zu\n", *len, size);
31003100
ret = -EINVAL;
31013101
goto out;
31023102
}
@@ -3132,12 +3132,12 @@ do_ip_vs_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
31323132
case IP_VS_SO_GET_DESTS:
31333133
{
31343134
struct ip_vs_get_dests *get;
3135-
int size;
3135+
size_t size;
31363136

31373137
get = (struct ip_vs_get_dests *)arg;
31383138
size = struct_size(get, entrytable, get->num_dests);
31393139
if (*len != size) {
3140-
pr_err("length: %u != %u\n", *len, size);
3140+
pr_err("length: %u != %zu\n", *len, size);
31413141
ret = -EINVAL;
31423142
goto out;
31433143
}

0 commit comments

Comments
 (0)