diff options
| author | Eric Dumazet <eric.dumazet@gmail.com> | 2011-06-17 16:25:39 -0400 |
|---|---|---|
| committer | David S. Miller <davem@davemloft.net> | 2011-06-17 16:25:39 -0400 |
| commit | eeb1497277d6b1a0a34ed36b97e18f2bd7d6de0d (patch) | |
| tree | 6bf39e1931999e49ef29b2bdcacc530044dcb1df | |
| parent | 2f9381e98471837b631743270de988e78aad1f96 (diff) | |
inet_diag: fix inet_diag_bc_audit()
A malicious user or buggy application can inject code and trigger an
infinite loop in inet_diag_bc_audit()
Also make sure each instruction is aligned on 4 bytes boundary, to avoid
unaligned accesses.
Reported-by: Dan Rosenberg <drosenberg@vsecurity.com>
Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
| -rw-r--r-- | net/ipv4/inet_diag.c | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/net/ipv4/inet_diag.c b/net/ipv4/inet_diag.c index 6ffe94ca5bc9..3267d3898437 100644 --- a/net/ipv4/inet_diag.c +++ b/net/ipv4/inet_diag.c | |||
| @@ -437,7 +437,7 @@ static int valid_cc(const void *bc, int len, int cc) | |||
| 437 | return 0; | 437 | return 0; |
| 438 | if (cc == len) | 438 | if (cc == len) |
| 439 | return 1; | 439 | return 1; |
| 440 | if (op->yes < 4) | 440 | if (op->yes < 4 || op->yes & 3) |
| 441 | return 0; | 441 | return 0; |
| 442 | len -= op->yes; | 442 | len -= op->yes; |
| 443 | bc += op->yes; | 443 | bc += op->yes; |
| @@ -447,11 +447,11 @@ static int valid_cc(const void *bc, int len, int cc) | |||
| 447 | 447 | ||
| 448 | static int inet_diag_bc_audit(const void *bytecode, int bytecode_len) | 448 | static int inet_diag_bc_audit(const void *bytecode, int bytecode_len) |
| 449 | { | 449 | { |
| 450 | const unsigned char *bc = bytecode; | 450 | const void *bc = bytecode; |
| 451 | int len = bytecode_len; | 451 | int len = bytecode_len; |
| 452 | 452 | ||
| 453 | while (len > 0) { | 453 | while (len > 0) { |
| 454 | struct inet_diag_bc_op *op = (struct inet_diag_bc_op *)bc; | 454 | const struct inet_diag_bc_op *op = bc; |
| 455 | 455 | ||
| 456 | //printk("BC: %d %d %d {%d} / %d\n", op->code, op->yes, op->no, op[1].no, len); | 456 | //printk("BC: %d %d %d {%d} / %d\n", op->code, op->yes, op->no, op[1].no, len); |
| 457 | switch (op->code) { | 457 | switch (op->code) { |
| @@ -462,22 +462,20 @@ static int inet_diag_bc_audit(const void *bytecode, int bytecode_len) | |||
| 462 | case INET_DIAG_BC_S_LE: | 462 | case INET_DIAG_BC_S_LE: |
| 463 | case INET_DIAG_BC_D_GE: | 463 | case INET_DIAG_BC_D_GE: |
| 464 | case INET_DIAG_BC_D_LE: | 464 | case INET_DIAG_BC_D_LE: |
| 465 | if (op->yes < 4 || op->yes > len + 4) | ||
| 466 | return -EINVAL; | ||
| 467 | case INET_DIAG_BC_JMP: | 465 | case INET_DIAG_BC_JMP: |
| 468 | if (op->no < 4 || op->no > len + 4) | 466 | if (op->no < 4 || op->no > len + 4 || op->no & 3) |
| 469 | return -EINVAL; | 467 | return -EINVAL; |
| 470 | if (op->no < len && | 468 | if (op->no < len && |
| 471 | !valid_cc(bytecode, bytecode_len, len - op->no)) | 469 | !valid_cc(bytecode, bytecode_len, len - op->no)) |
| 472 | return -EINVAL; | 470 | return -EINVAL; |
| 473 | break; | 471 | break; |
| 474 | case INET_DIAG_BC_NOP: | 472 | case INET_DIAG_BC_NOP: |
| 475 | if (op->yes < 4 || op->yes > len + 4) | ||
| 476 | return -EINVAL; | ||
| 477 | break; | 473 | break; |
| 478 | default: | 474 | default: |
| 479 | return -EINVAL; | 475 | return -EINVAL; |
| 480 | } | 476 | } |
| 477 | if (op->yes < 4 || op->yes > len + 4 || op->yes & 3) | ||
| 478 | return -EINVAL; | ||
| 481 | bc += op->yes; | 479 | bc += op->yes; |
| 482 | len -= op->yes; | 480 | len -= op->yes; |
| 483 | } | 481 | } |
