Commit 1b93ae64cabe5e28dd5a1f35f96f938ca4f6ae20

Authored by David S. Miller
1 parent 6732badee0

[NET]: Validate socket filters against BPF_MAXINSNS in one spot.

Currently the checks are scattered all over and this leads
to inconsistencies and even cases where the check is not made.

Based upon a patch from Kris Katterjohn.

Signed-off-by: David S. Miller <davem@davemloft.net>

Showing 2 changed files with 2 additions and 5 deletions Side-by-side Diff

drivers/net/ppp_generic.c
... ... @@ -524,9 +524,6 @@
524 524 if (copy_from_user(&uprog, arg, sizeof(uprog)))
525 525 return -EFAULT;
526 526  
527   - if (uprog.len > BPF_MAXINSNS)
528   - return -EINVAL;
529   -
530 527 if (!uprog.len) {
531 528 *p = NULL;
532 529 return 0;
... ... @@ -293,7 +293,7 @@
293 293 struct sock_filter *ftest;
294 294 int pc;
295 295  
296   - if (((unsigned int)flen >= (~0U / sizeof(struct sock_filter))) || flen == 0)
  296 + if (flen == 0 || flen > BPF_MAXINSNS)
297 297 return -EINVAL;
298 298  
299 299 /* check the filter code now */
... ... @@ -360,7 +360,7 @@
360 360 int err;
361 361  
362 362 /* Make sure new filter is there and in the right amounts. */
363   - if (fprog->filter == NULL || fprog->len > BPF_MAXINSNS)
  363 + if (fprog->filter == NULL)
364 364 return -EINVAL;
365 365  
366 366 fp = sock_kmalloc(sk, fsize+sizeof(*fp), GFP_KERNEL);