Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1634523 > unrolled thread
| Started by | Andrey Konovalov <andreyknvl@google.com> |
|---|---|
| First post | 2017-05-02 18:50 +0200 |
| Last post | 2017-05-08 14:00 +0200 |
| Articles | 4 — 2 participants |
Back to article view | Back to linux.kernel
net/key: slab-out-of-bounds in pfkey_compile_policy Andrey Konovalov <andreyknvl@google.com> - 2017-05-02 18:50 +0200
Re: net/key: slab-out-of-bounds in pfkey_compile_policy Steffen Klassert <steffen.klassert@secunet.com> - 2017-05-05 11:20 +0200
Re: net/key: slab-out-of-bounds in pfkey_compile_policy Andrey Konovalov <andreyknvl@google.com> - 2017-05-05 14:20 +0200
Re: net/key: slab-out-of-bounds in pfkey_compile_policy Steffen Klassert <steffen.klassert@secunet.com> - 2017-05-08 14:00 +0200
| From | Andrey Konovalov <andreyknvl@google.com> |
|---|---|
| Date | 2017-05-02 18:50 +0200 |
| Subject | net/key: slab-out-of-bounds in pfkey_compile_policy |
| Message-ID | <tCJ9T-LW-11@gated-at.bofh.it> |
[Multipart message — attachments visible in raw view] — view raw
Hi,
I've got the following error report while fuzzing the kernel with syzkaller.
On commit d3b5d35290d729a2518af00feca867385a1b08fa (4.11).
A reproducer and .config are attached.
==================================================================
BUG: KASAN: slab-out-of-bounds in pfkey_compile_policy+0x8e6/0xd40 at
addr ffff88006701f798
Read of size 1280 by task a.out/4181
CPU: 0 PID: 4181 Comm: a.out Not tainted 4.11.0+ #306
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs 01/01/2011
Call Trace:
__dump_stack lib/dump_stack.c:16
dump_stack+0x292/0x395 lib/dump_stack.c:52
kasan_object_err+0x1c/0x70 mm/kasan/report.c:164
print_address_description mm/kasan/report.c:202
kasan_report_error mm/kasan/report.c:291
kasan_report+0x252/0x510 mm/kasan/report.c:347
check_memory_region_inline mm/kasan/kasan.c:326
check_memory_region+0x139/0x190 mm/kasan/kasan.c:333
memcpy+0x23/0x50 mm/kasan/kasan.c:368
pfkey_sadb2xfrm_user_sec_ctx net/key/af_key.c:474
pfkey_compile_policy+0x8e6/0xd40 net/key/af_key.c:3294
xfrm_user_policy+0x349/0x560 net/xfrm/xfrm_state.c:1892
do_ip_setsockopt.isra.12+0x1d05/0x38c0 net/ipv4/ip_sockglue.c:1175
ip_setsockopt+0x3a/0xb0 net/ipv4/ip_sockglue.c:1264
tcp_setsockopt+0x82/0xd0 net/ipv4/tcp.c:2732
sock_common_setsockopt+0x95/0xd0 net/core/sock.c:2750
SYSC_setsockopt net/socket.c:1798
SyS_setsockopt+0x270/0x3a0 net/socket.c:1777
entry_SYSCALL_64_fastpath+0x1f/0xbe arch/x86/entry/entry_64.S:204
RIP: 0033:0x7f13a0968b79
RSP: 002b:00007fff131bc3f8 EFLAGS: 00000206 ORIG_RAX: 0000000000000036
RAX: ffffffffffffffda RBX: 00007fff131bc550 RCX: 00007f13a0968b79
RDX: 0000000000000010 RSI: 0000000000000000 RDI: 0000000000000003
RBP: 00000000004004e0 R08: 00000000000000c2 R09: 0000000000000000
R10: 0000000020a2ff3e R11: 0000000000000206 R12: 0000000000000000
R13: 00007fff131bc550 R14: 0000000000000000 R15: 0000000000000000
Object at ffff88006701f780, in cache kmalloc-256 size: 256
Allocated:
PID = 4181
save_stack_trace+0x16/0x20 arch/x86/kernel/stacktrace.c:59
save_stack+0x43/0xd0 mm/kasan/kasan.c:513
set_track mm/kasan/kasan.c:525
kasan_kmalloc+0xad/0xe0 mm/kasan/kasan.c:616
__kmalloc+0xa0/0x2d0 mm/slub.c:3745
kmalloc ./include/linux/slab.h:495
xfrm_user_policy+0xd8/0x560 net/xfrm/xfrm_state.c:1881
do_ip_setsockopt.isra.12+0x1d05/0x38c0 net/ipv4/ip_sockglue.c:1175
ip_setsockopt+0x3a/0xb0 net/ipv4/ip_sockglue.c:1264
tcp_setsockopt+0x82/0xd0 net/ipv4/tcp.c:2732
sock_common_setsockopt+0x95/0xd0 net/core/sock.c:2750
SYSC_setsockopt net/socket.c:1798
SyS_setsockopt+0x270/0x3a0 net/socket.c:1777
entry_SYSCALL_64_fastpath+0x1f/0xbe arch/x86/entry/entry_64.S:204
Freed:
PID = 3951
save_stack_trace+0x16/0x20 arch/x86/kernel/stacktrace.c:59
save_stack+0x43/0xd0 mm/kasan/kasan.c:513
set_track mm/kasan/kasan.c:525
kasan_slab_free+0x73/0xc0 mm/kasan/kasan.c:589
slab_free_hook mm/slub.c:1357
slab_free_freelist_hook mm/slub.c:1379
slab_free mm/slub.c:2961
kfree+0xe8/0x2b0 mm/slub.c:3882
free_bprm+0x19d/0x200 fs/exec.c:1382
do_execveat_common.isra.34+0x19ad/0x2220 fs/exec.c:1778
do_execve fs/exec.c:1813
SYSC_execve fs/exec.c:1894
SyS_execve+0x39/0x50 fs/exec.c:1889
do_syscall_64+0x2c7/0x7a0 arch/x86/entry/common.c:281
return_from_SYSCALL_64+0x0/0x7a arch/x86/entry/entry_64.S:246
Memory state around the buggy address:
ffff88006701f700: fb fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
ffff88006701f780: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
>ffff88006701f800: 00 00 00 00 00 00 00 00 02 fc fc fc fc fc fc fc
^
ffff88006701f880: fc fc fc fc fc fc fc fc fb fb fb fb fb fb fb fb
ffff88006701f900: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================
[toc] | [next] | [standalone]
| From | Steffen Klassert <steffen.klassert@secunet.com> |
|---|---|
| Date | 2017-05-05 11:20 +0200 |
| Message-ID | <tDHz3-8aB-9@gated-at.bofh.it> |
| In reply to | #1634523 |
On Tue, May 02, 2017 at 06:45:03PM +0200, Andrey Konovalov wrote:
> Hi,
>
> I've got the following error report while fuzzing the kernel with syzkaller.
>
> On commit d3b5d35290d729a2518af00feca867385a1b08fa (4.11).
>
> A reproducer and .config are attached.
>
> ==================================================================
> BUG: KASAN: slab-out-of-bounds in pfkey_compile_policy+0x8e6/0xd40 at
> addr ffff88006701f798
> Read of size 1280 by task a.out/4181
This bug was introduced twelve years ago...
This patch is based just on code review, I don't have an option to
function test this. But I see that we now exit with -EINVAL before the
memcpy that causes the slab-out-of-bounds when using your reproducer,
so it should at least fix the bug.
Subject: [PATCH RFC] af_key: Fix slab-out-of-bounds in pfkey_compile_policy.
The sadb_x_sec_len is stored in the unit 'byte divided by eight'.
So we have to multiply this value by eight before we can do
size checks. Otherwise we may get a slab-out-of-bounds when
we memcpy the user sec_ctx.
Fixes: df71837d502 ("[LSM-IPSec]: Security association restriction.")
Reported-by: Andrey Konovalov <andreyknvl@google.com>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
---
net/key/af_key.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/key/af_key.c b/net/key/af_key.c
index c1950bb..512dc43 100644
--- a/net/key/af_key.c
+++ b/net/key/af_key.c
@@ -3285,7 +3285,7 @@ static struct xfrm_policy *pfkey_compile_policy(struct sock *sk, int opt,
p += pol->sadb_x_policy_len*8;
sec_ctx = (struct sadb_x_sec_ctx *)p;
if (len < pol->sadb_x_policy_len*8 +
- sec_ctx->sadb_x_sec_len) {
+ sec_ctx->sadb_x_sec_len*8) {
*dir = -EINVAL;
goto out;
}
--
2.7.4
[toc] | [prev] | [next] | [standalone]
| From | Andrey Konovalov <andreyknvl@google.com> |
|---|---|
| Date | 2017-05-05 14:20 +0200 |
| Message-ID | <tDKnf-1Cl-5@gated-at.bofh.it> |
| In reply to | #1636264 |
On Fri, May 5, 2017 at 11:11 AM, Steffen Klassert
<steffen.klassert@secunet.com> wrote:
> On Tue, May 02, 2017 at 06:45:03PM +0200, Andrey Konovalov wrote:
>> Hi,
>>
>> I've got the following error report while fuzzing the kernel with syzkaller.
>>
>> On commit d3b5d35290d729a2518af00feca867385a1b08fa (4.11).
>>
>> A reproducer and .config are attached.
>>
>> ==================================================================
>> BUG: KASAN: slab-out-of-bounds in pfkey_compile_policy+0x8e6/0xd40 at
>> addr ffff88006701f798
>> Read of size 1280 by task a.out/4181
>
>
> This bug was introduced twelve years ago...
>
> This patch is based just on code review, I don't have an option to
> function test this. But I see that we now exit with -EINVAL before the
> memcpy that causes the slab-out-of-bounds when using your reproducer,
> so it should at least fix the bug.
Hi Steffen,
This patch fixes the issue for me.
Thanks!
Tested-by: Andrey Konovalov <andreyknvl@google.com>
>
> Subject: [PATCH RFC] af_key: Fix slab-out-of-bounds in pfkey_compile_policy.
>
> The sadb_x_sec_len is stored in the unit 'byte divided by eight'.
> So we have to multiply this value by eight before we can do
> size checks. Otherwise we may get a slab-out-of-bounds when
> we memcpy the user sec_ctx.
>
> Fixes: df71837d502 ("[LSM-IPSec]: Security association restriction.")
> Reported-by: Andrey Konovalov <andreyknvl@google.com>
> Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
> ---
> net/key/af_key.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/net/key/af_key.c b/net/key/af_key.c
> index c1950bb..512dc43 100644
> --- a/net/key/af_key.c
> +++ b/net/key/af_key.c
> @@ -3285,7 +3285,7 @@ static struct xfrm_policy *pfkey_compile_policy(struct sock *sk, int opt,
> p += pol->sadb_x_policy_len*8;
> sec_ctx = (struct sadb_x_sec_ctx *)p;
> if (len < pol->sadb_x_policy_len*8 +
> - sec_ctx->sadb_x_sec_len) {
> + sec_ctx->sadb_x_sec_len*8) {
> *dir = -EINVAL;
> goto out;
> }
> --
> 2.7.4
>
>
[toc] | [prev] | [next] | [standalone]
| From | Steffen Klassert <steffen.klassert@secunet.com> |
|---|---|
| Date | 2017-05-08 14:00 +0200 |
| Message-ID | <tEPux-3tj-5@gated-at.bofh.it> |
| In reply to | #1636341 |
On Fri, May 05, 2017 at 02:18:01PM +0200, Andrey Konovalov wrote: > On Fri, May 5, 2017 at 11:11 AM, Steffen Klassert > <steffen.klassert@secunet.com> wrote: > > On Tue, May 02, 2017 at 06:45:03PM +0200, Andrey Konovalov wrote: > >> Hi, > >> > >> I've got the following error report while fuzzing the kernel with syzkaller. > >> > >> On commit d3b5d35290d729a2518af00feca867385a1b08fa (4.11). > >> > >> A reproducer and .config are attached. > >> > >> ================================================================== > >> BUG: KASAN: slab-out-of-bounds in pfkey_compile_policy+0x8e6/0xd40 at > >> addr ffff88006701f798 > >> Read of size 1280 by task a.out/4181 > > > > > > This bug was introduced twelve years ago... > > > > This patch is based just on code review, I don't have an option to > > function test this. But I see that we now exit with -EINVAL before the > > memcpy that causes the slab-out-of-bounds when using your reproducer, > > so it should at least fix the bug. > > Hi Steffen, > > This patch fixes the issue for me. > > Thanks! > > Tested-by: Andrey Konovalov <andreyknvl@google.com> Patch is now applied to the ipsec tree. Thanks for reporting and testing!
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web