From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 85413C433E6 for ; Thu, 18 Mar 2021 15:55:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 50DDC64F57 for ; Thu, 18 Mar 2021 15:55:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232038AbhCRPy3 (ORCPT ); Thu, 18 Mar 2021 11:54:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44692 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232029AbhCRPyU (ORCPT ); Thu, 18 Mar 2021 11:54:20 -0400 Received: from mail-qk1-x735.google.com (mail-qk1-x735.google.com [IPv6:2607:f8b0:4864:20::735]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B756C061760 for ; Thu, 18 Mar 2021 08:54:20 -0700 (PDT) Received: by mail-qk1-x735.google.com with SMTP id l132so2449434qke.7 for ; Thu, 18 Mar 2021 08:54:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=J+EfAqBWMuldZhFLKTK7DYwRmCCO76h3wFXCCWaZSMc=; b=JAuMzMkBbITRNY13aACDLIk/k+iuZNwnY+TuVS/VkWrpwiwiZnjIqAqXg+sgD6k0rD 2683zQhrba+zznwFVhN9TrfJ2tXM27aBcej6YTISwW5enO4MpUM/7/vUSZLCc/eilbKY de8krjIAoXdrlFD7hjXponAFXD9uzSZQ848crh8XQfUyaA7GE/p44upKGkaYGQID7gjQ TGu3nqOZmibsYwtW4nkpKaMz1xaGTssKbFmUcf+q/G9q1Acnpjk726Z+krAWQQ7qI1tE /FFn9w3c8gJi84/60Z/hO18B5j9iNY799t13VZZHHC7ydIZvKIyuqgIX3IRpPo6ahMIi Auyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=J+EfAqBWMuldZhFLKTK7DYwRmCCO76h3wFXCCWaZSMc=; b=YOXZov5phnCHDcbzA75jn3AbQqJEkvVZnE2pxN+Pa6WaljhBBaqxGyITBiWhwvGx5/ A700FdOfGKuXdtwMwX2Ev9dHUERufdm4GhjisMBDTUVWsrw08YZdhVHjSOR1s3yuz9iC Kjykw5PTkEyed+QV+hi1ME33TZzLSwAqe7YS2M4liCCRusOHr5olAw9wsA1k4dDnQsXj BQvlNii//DQDrsVRICtA43ZHh0cERJzY38xn1x1t/9OH1SEbIURcMtLeqhsD6PYyduQJ dDnVXAyqyMtAhUUOctjZAASbKEZp726Ghb1b8x3SnKyRECT52zXqRX57xU7gEQ8ZkqqC rLNw== X-Gm-Message-State: AOAM530bfNB/Z+aTtl0i0PVHsCIZ5U+dg0Wu+nEaKKaU+8rT1UyoZ/hC meFWUR9bMtP65DLGh27mHjPqD3/Qq71zUcQUVspGow== X-Google-Smtp-Source: ABdhPJxFh76WWb8+3I2ntXhBqRjTSAc+1WcZgiaZ7ifnOH2xeqOLOi44Fqrc0Z0eZNzc0q7qHi5UZ42ezkHaQtthL9A= X-Received: by 2002:a05:620a:410f:: with SMTP id j15mr5028891qko.424.1616082859168; Thu, 18 Mar 2021 08:54:19 -0700 (PDT) MIME-Version: 1.0 References: <00000000000096cdaa05bd32d46f@google.com> <8372d8e5-af6e-c851-a0ac-733e269102ce@codethink.co.uk> In-Reply-To: <8372d8e5-af6e-c851-a0ac-733e269102ce@codethink.co.uk> From: Dmitry Vyukov Date: Thu, 18 Mar 2021 16:54:07 +0100 Message-ID: Subject: Re: [syzbot] BUG: unable to handle kernel access to user memory in sock_ioctl To: Ben Dooks Cc: syzbot , Paul Walmsley , Palmer Dabbelt , Albert Ou , linux-riscv , andrii@kernel.org, Alexei Starovoitov , bpf , Daniel Borkmann , David Miller , John Fastabend , Martin KaFai Lau , kpsingh@kernel.org, Jakub Kicinski , LKML , netdev , Song Liu , syzkaller-bugs , Yonghong Song Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org On Thu, Mar 18, 2021 at 4:35 PM Ben Dooks wrote: > > On 18/03/2021 15:18, Dmitry Vyukov wrote: > > On Mon, Mar 15, 2021 at 3:41 PM Ben Dooks wrote: > >> > >> On 15/03/2021 11:52, Dmitry Vyukov wrote: > >>> On Mon, Mar 15, 2021 at 12:30 PM Ben Dooks wrote: > >>>> > >>>> On 14/03/2021 11:03, Dmitry Vyukov wrote: > >>>>> On Sun, Mar 14, 2021 at 11:01 AM Dmitry Vyukov wrote: > >>>>>>> On Wed, Mar 10, 2021 at 7:28 PM syzbot > >>>>>>> wrote: > >>>>>>>> > >>>>>>>> Hello, > >>>>>>>> > >>>>>>>> syzbot found the following issue on: > >>>>>>>> > >>>>>>>> HEAD commit: 0d7588ab riscv: process: Fix no prototype for arch_dup_tas.. > >>>>>>>> git tree: git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux.git fixes > >>>>>>>> console output: https://syzkaller.appspot.com/x/log.txt?x=122c343ad00000 > >>>>>>>> kernel config: https://syzkaller.appspot.com/x/.config?x=e3c595255fb2d136 > >>>>>>>> dashboard link: https://syzkaller.appspot.com/bug?extid=c23c5421600e9b454849 > >>>>>>>> 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@syzkaller.appspotmail.com > >>>>>>> > >>>>>>> +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 > >>>>> syscalls... > >>>> > >>>> 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. Thanks for quick debugging and the fix. This is the top crasher on the syzbot instance, so this will unblock real testing. I think I will trust your testing. syzbot instance is now on riscv/fixes branch, so it will pick it up as soon as it's in that tree (hopefully soon) and will do as exhaustive testing as possible :)