grsecurity: 3.0-3.2.57-vs2.3.2.16-201404131253

commit 27573d9ea921caaed36a74fc2a409f460eef48f9
Merge: bb184b9 1c930d3
Author: Brad Spengler
Date: Sun Apr 13 12:50:18 2014 -0400

Merge branch 'grsec-stable2' into grsec-vserver-stable2

commit 1c930d360ce624a56b857812faa6d577209fdc9c
Author: Brad Spengler
Date: Sun Apr 13 12:47:57 2014 -0400

From: Mathias Krause
[PATCH net] filter: prevent nla extensions to peek beyond the end of
the message

The BPF_S_ANC_NLATTR and BPF_S_ANC_NLATTR_NEST extensions fail to check
for a minimal message length before testing the supplied offset to be
within the bounds of the message. This allows the subtraction of the nla
header to underflow and therefore -- as the data type is unsigned --
allowing far to big offset and length values for the search of the
netlink attribute.

The remainder calculation for the BPF_S_ANC_NLATTR_NEST extension is
also wrong. It has the minuend und subtrahend mixed up, therefore
calculates a huge length value, allowing to overrun the end of the
message while looking for the netlink attribute.

The following three BPF snippets will trigger the bugs when attached to
a UNIX datagram socket and parsing a message with length 1, 2 or 3.

,-[ PoC for missing size check in BPF_S_ANC_NLATTR ]--
| ld #0x87654321
| ldx #42
| ld #nla
| ret a
`---

,-[ PoC for the same bug in BPF_S_ANC_NLATTR_NEST ]--
| ld #0x87654321
| ldx #42
| ld #nlan
| ret a
`---

,-[ PoC for wrong remainder calculation in BPF_S_ANC_NLATTR_NEST ]--
| ; (needs a fake netlink header at offset 0)
| ld #0
| ldx #42
| ld #nlan
| ret a
`---

Fix the first issue by ensuring the message length fulfills the minimal
size constrains of a nla header. Fix the second bug by getting the math
for the remainder calculation right.

Fixes: 4738c1db15 ("[SKFILTER]: Add SKF_ADF_NLATTR instruction")
Fixes: d214c7537b ("filter: add SKF_AD_NLATTR_NEST to look for nested..")
Cc: Patrick McHardy
Cc: Pablo Neira Ayuso
Signed-off-by: Mathias Krause

net/core/filter.c | 10 +++++++++-
1 files changed, 9 insertions(+), 1 deletions(-)