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 D99F4C433F5 for ; Fri, 25 Feb 2022 05:51:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 36BC68D0002; Fri, 25 Feb 2022 00:51:08 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 31B298D0001; Fri, 25 Feb 2022 00:51:08 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 20A748D0002; Fri, 25 Feb 2022 00:51:08 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.a.hostedemail.com [64.99.140.24]) by kanga.kvack.org (Postfix) with ESMTP id 10B658D0001 for ; Fri, 25 Feb 2022 00:51:08 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id C897423D9F for ; Fri, 25 Feb 2022 05:51:07 +0000 (UTC) X-FDA: 79180228974.02.BEB3522 Received: from mail-yb1-f176.google.com (mail-yb1-f176.google.com [209.85.219.176]) by imf21.hostedemail.com (Postfix) with ESMTP id 4C7301C000E for ; Fri, 25 Feb 2022 05:51:07 +0000 (UTC) Received: by mail-yb1-f176.google.com with SMTP id v186so3885436ybg.1 for ; Thu, 24 Feb 2022 21:51:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=9Girgga9Ci+5xd+8kHR+4MAPMnZRC/qWzFHzhTjkouU=; b=APbEdw9DCoq4YO9CPnVxJaCcGKIrX5WNvB8CrAqLgW+g9afQj3tz1pMqKsE7u7rh7h 0UDFDhDrmI5J7WRYMtG6H+2tUzTSpk8XSYa5DMqtnvxRNb6qLNLxct/uP31Kfc7VPOCY c/wAxEXw0nNmvElPJL52UhKlpywF0hxptGEbE8YjqhZjJd89+enNUTK63m7plns1Bk5R EE252+R7LSROnt1LAG7IJwOK5ysyLmIhQHZgBE1nYxkJvrlHhH6ERS7u0FQjak2Gkfe+ +DpeMk9dZ+9Xzileze/aRznlewvT/WmgWaaGEg0yGybKNuX60TmW0AL7lmBwkTYDPqSy AOaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=9Girgga9Ci+5xd+8kHR+4MAPMnZRC/qWzFHzhTjkouU=; b=x0YPNXNmItEPb3QcrmaIveNv0aNzNIAOTM/quY+AorpHGgd7z+8XONfNzngprCYIKY v2/c0BGVbph+utlCDG7i0naXqJCy58nRY6O9bD/GFnNdvGZWsn1beoA0O09y0lGjwHC2 HOKDNFiTnvJRQGkE/ZR9WGn19931M+u5zrdivVBuwZIS+N2d8M+YChRbvDCA1InrjnXn EGJEHMSSgA2djJ3lEM57rUn+Mo3KJon6wwV9kJgkEwVDzWXHPwfdcWa8zRm4YYCCtukA OQfNRiSnruUEccpo5a5gVEuE4Fse98gM3idcR6CwkmsTPL2w2T7b9VfHF5YB7g/ECn1/ 2Wgw== X-Gm-Message-State: AOAM5316VP8q1/2wVZcvoWcBu65jXcylipaf83QSrXUJqwLk2RbchG7j ptj3am7vEfnPWGiMG6OdrUD2STgVZnRDo3bl/nkr6g== X-Google-Smtp-Source: ABdhPJyg1MamSYunzsREevAh9ocOCGsMKrLpiB38putz2JxBhuE88oIZqQN7LkJKrDAj1wsPekXhQPxtDa0vVMN/crY= X-Received: by 2002:a25:da47:0:b0:61d:9af4:c834 with SMTP id n68-20020a25da47000000b0061d9af4c834mr5853645ybf.441.1645768266299; Thu, 24 Feb 2022 21:51:06 -0800 (PST) MIME-Version: 1.0 References: <20220215201922.1908156-1-surenb@google.com> <20220224201859.a38299b6c9d52cb51e6738ea@linux-foundation.org> In-Reply-To: From: Suren Baghdasaryan Date: Thu, 24 Feb 2022 21:50:54 -0800 Message-ID: Subject: Re: [PATCH 1/1] mm: fix use-after-free bug when mm->mmap is reused after being freed To: Matthew Wilcox Cc: Andrew Morton , mhocko@kernel.org, mhocko@suse.com, shy828301@gmail.com, rientjes@google.com, hannes@cmpxchg.org, guro@fb.com, riel@surriel.com, minchan@kernel.org, kirill@shutemov.name, aarcange@redhat.com, brauner@kernel.org, christian@brauner.io, hch@infradead.org, oleg@redhat.com, david@redhat.com, jannh@google.com, shakeelb@google.com, luto@kernel.org, christian.brauner@ubuntu.com, fweimer@redhat.com, jengelh@inai.de, timmurray@google.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@android.com, syzbot+2ccf63a4bd07cf39cab0@syzkaller.appspotmail.com, Liam Howlett Content-Type: text/plain; charset="UTF-8" X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 4C7301C000E X-Rspam-User: Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=APbEdw9D; spf=pass (imf21.hostedemail.com: domain of surenb@google.com designates 209.85.219.176 as permitted sender) smtp.mailfrom=surenb@google.com; dmarc=pass (policy=reject) header.from=google.com X-Stat-Signature: ruq8i9pnhacqagbq1kzp4tus14yobq49 X-HE-Tag: 1645768267-972253 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 Thu, Feb 24, 2022 at 8:23 PM Matthew Wilcox wrote: > > On Thu, Feb 24, 2022 at 08:18:59PM -0800, Andrew Morton wrote: > > On Tue, 15 Feb 2022 12:19:22 -0800 Suren Baghdasaryan wrote: > > > > > After exit_mmap frees all vmas in the mm, mm->mmap needs to be reset, > > > otherwise it points to a vma that was freed and when reused leads to > > > a use-after-free bug. > > > > > > ... > > > > > > --- a/mm/mmap.c > > > +++ b/mm/mmap.c > > > @@ -3186,6 +3186,7 @@ void exit_mmap(struct mm_struct *mm) > > > vma = remove_vma(vma); > > > cond_resched(); > > > } > > > + mm->mmap = NULL; > > > mmap_write_unlock(mm); > > > vm_unacct_memory(nr_accounted); > > > } > > > > After the Maple tree patches, mm_struct.mmap doesn't exist. So I'll > > revert this fix as part of merging the maple-tree parts of linux-next. > > I'll be sending this fix to Linus this week. > > > > All of which means that the thusly-resolved Maple tree patches might > > reintroduce this use-after-free bug. > > I don't think so? The problem is that VMAs are (currently) part of > two data structures -- the rbtree and the linked list. remove_vma() > only removes VMAs from the rbtree; it doesn't set mm->mmap to NULL. > > With maple tree, the linked list goes away. remove_vma() removes VMAs > from the maple tree. So anyone looking to iterate over all VMAs has to > go and look in the maple tree for them ... and there's nothing there. Yes, I think you are right. With maple trees we don't need this fix. > > But maybe I misunderstood the bug that's being solved here.