From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751519AbdK0GPX (ORCPT ); Mon, 27 Nov 2017 01:15:23 -0500 Received: from mail-pl0-f67.google.com ([209.85.160.67]:46879 "EHLO mail-pl0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751096AbdK0GPV (ORCPT ); Mon, 27 Nov 2017 01:15:21 -0500 X-Google-Smtp-Source: AGs4zMaW0NuF2yOqYYOkto0hslOok75SsF5y74GZkF/3ONms8DELXls6NTFM13mV/qBFLI/p0BqQ1w== Date: Sun, 26 Nov 2017 22:15:17 -0800 From: Eric Biggers To: Dmitry Vyukov Cc: syzbot , linux-fsdevel@vger.kernel.org, LKML , syzkaller-bugs@googlegroups.com, Al Viro , Andrea Arcangeli , Pavel Emelyanov , linux-mm@kvack.org Subject: Re: KASAN: use-after-free Read in handle_userfault Message-ID: <20171127061517.GA26341@zzz.localdomain> References: <001a114c9224e34a49055c842032@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.1 (2017-09-22) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org +Cc aarcange@redhat.com, xemul@parallels.com, linux-mm@kvack.org On Fri, Oct 27, 2017 at 11:46:13AM +0200, Dmitry Vyukov wrote: > On Fri, Oct 27, 2017 at 11:44 AM, syzbot > > wrote: > > Hello, > > > > syzkaller hit the following crash on > > a31cc455c512f3f1dd5f79cac8e29a7c8a617af8 > > git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/master > > compiler: gcc (GCC) 7.1.1 20170620 > > .config is attached > > Raw console output is attached. > > C reproducer is attached > > syzkaller reproducer is attached. See https://goo.gl/kgGztJ > > for information about syzkaller reproducers > Andrea or Pavel, can one of you please fix this? It's another use-after-free related to userfaultfd "fork events", and it can easily be triggered by an unprivileged user. It was reported a month ago already; the original report is here: https://groups.google.com/forum/#!topic/syzkaller-bugs/sS99S-Z-9No. (Please consider adding yourself and/or linux-mm to the MAINTAINERS file for fs/userfaultfd.c, so that you are Cc'ed on userfaultfd bug reports.) In userfaultfd_event_wait_completion(), called from dup_fctx(), the kernel is freeing the the new userfaultfd_ctx because the old one had all its fd's closed, but actually the new one is still in use by the new mm_struct. Also, I've simplified the C reproducer: #include #include #include #include #include #include #include #include static int userfaultfd; static void *page; static void *close_fd_proc(void *arg) { usleep(1000); close(userfaultfd); return NULL; } int main() { pthread_t t; struct uffdio_api api = { 0 }; struct uffdio_register reg = { 0 }; page = mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); userfaultfd = syscall(__NR_userfaultfd, 0); api.api = UFFDIO; api.features = UFFD_FEATURE_EVENT_FORK; ioctl(userfaultfd, UFFDIO_API, &api); reg.range.start = (__u64)page; reg.range.len = 4096; reg.mode = UFFDIO_REGISTER_MODE_MISSING; ioctl(userfaultfd, UFFDIO_REGISTER, ®); pthread_create(&t, NULL, close_fd_proc, NULL); syscall(__NR_clone, CLONE_FILES, page, NULL, NULL, NULL); return 0; }