From: 刘通 <lyutoon@gmail.com>
To: leah.rumancik@gmail.com, djwong@kernel.org,
linux-xfs@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: A bug was found in Linux Kernel 5.15.148 and 5.15.150: KASAN: use-after-free in xfs_allocbt_init_key_from_rec (with POC)
Date: Thu, 7 Mar 2024 15:23:46 +0800 [thread overview]
Message-ID: <CAEJPjCvT3Uag-pMTYuigEjWZHn1sGMZ0GCjVVCv29tNHK76Cgg@mail.gmail.com> (raw)
Hi upstream community,
I was fuzzing a LTS version of Linux kernel 5.15.148 with my modified
syzkaller and I found a bug named "KASAN: use-after-free in
xfs_allocbt_init_key_from_rec".
I tested the PoC on 5.15.148, 5.15.149 and 5.15.150 with sanitizer on
and found sanitizer through a panic as "KASAN: use-after-free in
xfs_allocbt_init_key_from_rec" on 5.15.148 and 5.15.150, but there was
no panic and sanitizer error in 5.15.149.
The syzkaller log, report, kernel config, PoC can be found here:
https://drive.google.com/file/d/1w6VKKewt4VQzb9FzcGtkELJUOwd1wMcC/view?usp=sharing
# Analysis (rough):
Because that I cannot understand the report0 clearly in the zip file
above, so I rerun the PoC on my vm (5.15.148) and I get another report
named as the same but it looks much clearer than the report0. The new
report can be found in:
https://drive.google.com/file/d/1Vg_4Qwueow6VgjLrijnUB8QbZVx902sv/view?usp=sharing
In this report, we can easily see that the memory allocation and free:
Allocation:
```
[ 62.995194][ T6349] Allocated by task 6343:
[ 62.995610][ T6349] kasan_save_stack+0x1b/0x40
[ 62.996044][ T6349] __kasan_slab_alloc+0x61/0x80
[ 62.996475][ T6349] kmem_cache_alloc+0x18e/0x6b0
[ 62.996918][ T6349] getname_flags+0xd2/0x5b0
[ 62.997335][ T6349] user_path_at_empty+0x2b/0x60
[ 62.997782][ T6349] vfs_statx+0x13c/0x370
[ 62.998193][ T6349] __do_sys_newlstat+0x91/0x110
[ 62.998634][ T6349] do_syscall_64+0x35/0xb0
[ 62.999033][ T6349] entry_SYSCALL_64_after_hwframe+0x61/0xcb
```
Free:
```
[ 62.999776][ T6349] Freed by task 6343:
[ 63.000135][ T6349] kasan_save_stack+0x1b/0x40
[ 63.000555][ T6349] kasan_set_track+0x1c/0x30
[ 63.001053][ T6349] kasan_set_free_info+0x20/0x30
[ 63.001638][ T6349] __kasan_slab_free+0xe1/0x110
[ 63.002206][ T6349] kmem_cache_free+0x82/0x5b0
[ 63.002742][ T6349] putname+0xfe/0x140
[ 63.003103][ T6349] user_path_at_empty+0x4d/0x60
[ 63.003551][ T6349] vfs_statx+0x13c/0x370
[ 63.003943][ T6349] __do_sys_newlstat+0x91/0x110
[ 63.004378][ T6349] do_syscall_64+0x35/0xb0
[ 63.004841][ T6349] entry_SYSCALL_64_after_hwframe+0x61/0xcb
```
So this is a use-after-free bug: allocated by `kmem_cache_alloc` and
freed by `kmem_cache_free`.
And according to the report, the UAF occurs in
`xfs_allocbt_init_key_from_rec`, `key->alloc.ar_startblock =
rec->alloc.ar_startblock;` which indicates that maybe
`rec->alloc.ar_startblock` was freed before.
# Step to reproduce:
1. download the zip file
2. unzip it
3. compile the kernel (5.15.148, 5.15.150) with kernel_config
4. start the kernel with qemu vm
5. scp repro.c to the vm
6. compile the repro.c and run it: gcc repro.c -o exp && ./exp
7. you will see the KASAN error
# Note:
I didn't find any related reports on the internet, which indicates
that it may be a 0day. Hope the upstream can help check and fix it.
And I'll be happy to provide more information if needed.
Best,
Tong
next reply other threads:[~2024-03-07 7:23 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-07 7:23 刘通 [this message]
2024-04-02 5:54 ` A bug was found in Linux Kernel 5.15.148 and 5.15.150: KASAN: use-after-free in xfs_allocbt_init_key_from_rec (with POC) Eric Sandeen
[not found] ` <CAEJPjCvK-LATJ5B9-=KXa3oMZwT-zQyFqMNU9EgcfsRD12AWWA@mail.gmail.com>
2024-04-02 15:09 ` Eric Sandeen
[not found] ` <CAEJPjCsXGHWzek7AQ1g3byUZe1Uq7KuUxJ0GY2fac3J8y+LFZQ@mail.gmail.com>
2024-04-02 17:55 ` Eric Sandeen
2024-04-11 20:34 ` Eric Sandeen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAEJPjCvT3Uag-pMTYuigEjWZHn1sGMZ0GCjVVCv29tNHK76Cgg@mail.gmail.com \
--to=lyutoon@gmail.com \
--cc=djwong@kernel.org \
--cc=leah.rumancik@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-xfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).