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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A016AC433FE for ; Wed, 25 May 2022 18:33:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1F4C18D0006; Wed, 25 May 2022 14:33:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1A4B48D0001; Wed, 25 May 2022 14:33:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 08EF68D0006; Wed, 25 May 2022 14:33:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id F00CC8D0001 for ; Wed, 25 May 2022 14:33:47 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id CFEF634BA0 for ; Wed, 25 May 2022 18:33:47 +0000 (UTC) X-FDA: 79505114094.12.1949702 Received: from mail-il1-f197.google.com (mail-il1-f197.google.com [209.85.166.197]) by imf12.hostedemail.com (Postfix) with ESMTP id A767840034 for ; Wed, 25 May 2022 18:33:11 +0000 (UTC) Received: by mail-il1-f197.google.com with SMTP id q6-20020a056e0215c600b002c2c4091914so13164213ilu.14 for ; Wed, 25 May 2022 11:33:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:date:in-reply-to:message-id:subject :from:to:cc; bh=jBh+sSzl4wfXD/kPQJA89QqmrKGas63PcudsVVN500M=; b=G83bUFhXuym1QQCVtM1bimkvoX48/pXwdjL+AqnaHiGpOk7GyNfzyjguWrzbsaPXea mgHCNUW+89zHEL6/TGxzh7zbnhShvkd6xtcSA4uAHgiS1L+w3bEDTvIw1m/K2j0NVm+f wSc/mIHLdbe3lm/2z0wwKM9V7j8fKHotBCnshqJQmpVYe9ohETQW2QGM7awed97tILDn 9cwTbr/edBNbc+yWZJfKeK14A8YAG2hnyvgeLaOS6rNDkK5hR08U2i1td7ybuDH1lqia ZBamhP7KLKg8rcTOOK9si1yd4IX/2pq8IRJBZq1Z6ypfjGPyZY77CCJUoEZg7aTd6PTL 70iQ== X-Gm-Message-State: AOAM532LKSBbJ30EHs8Wzxr7oMGv5kyYM8kFCS6Z6uzq2Rh25GXaoujh 6w8syNy0dA9fr+AsKuoKfhm7EM+hWuJzOnl3I2IPVSBKv98K X-Google-Smtp-Source: ABdhPJyAHVM+GHbGuvRjp+RpiuOF4QyRyVcQFg7NsXY8j80zDGnjoXHBvqgzEfTImjNZ9asqN8GB4m/9gi1NXkTy9w/J7uW8/aCC MIME-Version: 1.0 X-Received: by 2002:a05:6638:1481:b0:330:4470:b7a4 with SMTP id j1-20020a056638148100b003304470b7a4mr3502656jak.61.1653503626838; Wed, 25 May 2022 11:33:46 -0700 (PDT) Date: Wed, 25 May 2022 11:33:46 -0700 In-Reply-To: X-Google-Appengine-App-Id: s~syzkaller X-Google-Appengine-App-Id-Alias: syzkaller Message-ID: <000000000000500bbb05dfda50af@google.com> Subject: Re: [syzbot] KASAN: use-after-free Read in do_sync_mmap_readahead From: syzbot To: Matthew Wilcox Cc: akpm@linux-foundation.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, syzkaller-bugs@googlegroups.com, willy@infradead.org Content-Type: text/plain; charset="UTF-8" X-Rspam-User: X-Rspamd-Queue-Id: A767840034 X-Stat-Signature: i1m8pu96rx3r1bnnohdt39bi7j9fdymd Authentication-Results: imf12.hostedemail.com; dkim=none; spf=pass (imf12.hostedemail.com: domain of 3inaOYgkbAMs9FG1r22v8r66zu.x55x2vB9v8t54Av4A.t53@M3KW2WVRGUFZ5GODRSRYTGD7.apphosting.bounces.google.com designates 209.85.166.197 as permitted sender) smtp.mailfrom=3inaOYgkbAMs9FG1r22v8r66zu.x55x2vB9v8t54Av4A.t53@M3KW2WVRGUFZ5GODRSRYTGD7.apphosting.bounces.google.com; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=appspotmail.com (policy=none) X-Rspamd-Server: rspam04 X-HE-Tag: 1653503591-159710 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: > On Wed, May 25, 2022 at 06:57:55PM +0100, Matthew Wilcox wrote: >> >> Ohh, that makes sense. We unlocked the mmap_sem, so the file is >> pinned, but the VMA isn't. I'll whip up a patch. > > #syz test want 2 args (repo, branch), got 7 > > From 01a4917c4cfe400eb310eba4f2fa466d381623c1 Mon Sep 17 00:00:00 2001 > From: "Matthew Wilcox (Oracle)" > Date: Wed, 25 May 2022 14:23:45 -0400 > Subject: [PATCH] mm/filemap: Cache the value of vm_flags > > After we have unlocked the mmap_lock for I/O, the file is pinned, but > the VMA is not. Checking this flag after that can be a use-after-free. > It's not a terribly interesting use-after-free as it can only read one > bit, and it's used to decide whether to read 2MB or 4MB. But it > upsets the automated tools and it's generally bad practice anyway, > so let's fix it. > > Reported-by: syzbot+5b96d55e5b54924c77ad@syzkaller.appspotmail.com > Fixes: 4687fdbb805a ("mm/filemap: Support VM_HUGEPAGE for file mappings") > Signed-off-by: Matthew Wilcox (Oracle) > --- > mm/filemap.c | 9 +++++---- > 1 file changed, 5 insertions(+), 4 deletions(-) > > diff --git a/mm/filemap.c b/mm/filemap.c > index 9a1eef6c5d35..61dd39990fda 100644 > --- a/mm/filemap.c > +++ b/mm/filemap.c > @@ -2991,11 +2991,12 @@ static struct file *do_sync_mmap_readahead(struct vm_fault *vmf) > struct address_space *mapping = file->f_mapping; > DEFINE_READAHEAD(ractl, file, ra, mapping, vmf->pgoff); > struct file *fpin = NULL; > + unsigned long vm_flags = vmf->vma->vm_flags; > unsigned int mmap_miss; > > #ifdef CONFIG_TRANSPARENT_HUGEPAGE > /* Use the readahead code, even if readahead is disabled */ > - if (vmf->vma->vm_flags & VM_HUGEPAGE) { > + if (vm_flags & VM_HUGEPAGE) { > fpin = maybe_unlock_mmap_for_io(vmf, fpin); > ractl._index &= ~((unsigned long)HPAGE_PMD_NR - 1); > ra->size = HPAGE_PMD_NR; > @@ -3003,7 +3004,7 @@ static struct file *do_sync_mmap_readahead(struct vm_fault *vmf) > * Fetch two PMD folios, so we get the chance to actually > * readahead, unless we've been told not to. > */ > - if (!(vmf->vma->vm_flags & VM_RAND_READ)) > + if (!(vm_flags & VM_RAND_READ)) > ra->size *= 2; > ra->async_size = HPAGE_PMD_NR; > page_cache_ra_order(&ractl, ra, HPAGE_PMD_ORDER); > @@ -3012,12 +3013,12 @@ static struct file *do_sync_mmap_readahead(struct vm_fault *vmf) > #endif > > /* If we don't want any read-ahead, don't bother */ > - if (vmf->vma->vm_flags & VM_RAND_READ) > + if (vm_flags & VM_RAND_READ) > return fpin; > if (!ra->ra_pages) > return fpin; > > - if (vmf->vma->vm_flags & VM_SEQ_READ) { > + if (vm_flags & VM_SEQ_READ) { > fpin = maybe_unlock_mmap_for_io(vmf, fpin); > page_cache_sync_ra(&ractl, ra->ra_pages); > return fpin; > -- > 2.34.1 > > -- > You received this message because you are subscribed to the Google Groups "syzkaller-bugs" group. > To unsubscribe from this group and stop receiving emails from it, send an email to syzkaller-bugs+unsubscribe@googlegroups.com. > To view this discussion on the web visit https://groups.google.com/d/msgid/syzkaller-bugs/Yo52gzYYOpU0NwDo%40casper.infradead.org.