Re: [syzbot] BUG: unable to handle kernel access to user memory in sock_ioctl

From: Ben Dooks
Date: Thu Mar 18 2021 - 11:35:57 EST

On 18/03/2021 15:18, Dmitry Vyukov wrote:
On Mon, Mar 15, 2021 at 3:41 PM Ben Dooks <ben.dooks@xxxxxxxxxxxxxxx> wrote:

On 15/03/2021 11:52, Dmitry Vyukov wrote:
On Mon, Mar 15, 2021 at 12:30 PM Ben Dooks <ben.dooks@xxxxxxxxxxxxxxx> wrote:

On 14/03/2021 11:03, Dmitry Vyukov wrote:
On Sun, Mar 14, 2021 at 11:01 AM Dmitry Vyukov <dvyukov@xxxxxxxxxx> wrote:
On Wed, Mar 10, 2021 at 7:28 PM syzbot
<syzbot+c23c5421600e9b454849@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:


syzbot found the following issue on:

HEAD commit: 0d7588ab riscv: process: Fix no prototype for arch_dup_tas..
git tree: git:// fixes
console output:
kernel config:
dashboard link:
userspace arch: riscv64

Unfortunately, I don't have any reproducer for this issue yet.

IMPORTANT: if you fix the issue, please add the following tag to the commit:
Reported-by: syzbot+c23c5421600e9b454849@xxxxxxxxxxxxxxxxxxxxxxxxx

+riscv maintainers

Another case of put_user crashing.

There are 58 crashes in sock_ioctl already. Somehow there is a very
significant skew towards crashing with this "user memory without
uaccess routines" in schedule_tail and sock_ioctl of all places in the
kernel that use put_user... This looks very strange... Any ideas
what's special about these 2 locations?

I could imagine if such a crash happens after a previous stack
overflow and now task data structures are corrupted. But f_getown does
not look like a function that consumes way more than other kernel

The last crash I looked at suggested somehow put_user got re-entered
with the user protection turned back on. Either there is a path through
one of the kernel handlers where this happens or there's something
weird going on with qemu.

Is there any kind of tracking/reporting that would help to localize
it? I could re-reproduce with that code.

I'm not sure. I will have a go at debugging on qemu today just to make
sure I can reproduce here before I have to go into the office and fix
my Icicle board for real hardware tests.

I think my first plan post reproduction is to stuff some trace points
into the fault handlers to see if we can get a idea of faults being
processed, etc.

Maybe also add a check in the fault handler to see if the fault was
in a fixable region and post an error if that happens / maybe retry
the instruction with the relevant SR_SUM flag set.

Hopefully tomorrow I can get a run on real hardware to confirm.
Would have been better if the Unmatched board I ordered last year
would turn up.

In retrospect it's obvious what's common between these 2 locations:
they both call a function inside of put_user.

#syz dup:
BUG: unable to handle kernel access to user memory in schedule_tail

I think so. I've posted a patch that you can test, which should force
the flags to be saved over switch_to(). I think the sanitisers are just
making it easier to see.

There is a seperate issue of passing complicated things to put_user()
as for security, the function may be executed with the user-space
protections turned off. I plan to raise this on the kernel list later
once I've done some more testing.

Ben Dooks
Senior Engineer Codethink - Providing Genius