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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3A350C433EF for ; Fri, 25 Feb 2022 05:51:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237643AbiBYFvn (ORCPT ); Fri, 25 Feb 2022 00:51:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237644AbiBYFvj (ORCPT ); Fri, 25 Feb 2022 00:51:39 -0500 Received: from mail-yb1-xb2d.google.com (mail-yb1-xb2d.google.com [IPv6:2607:f8b0:4864:20::b2d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D8861F03B4 for ; Thu, 24 Feb 2022 21:51:07 -0800 (PST) Received: by mail-yb1-xb2d.google.com with SMTP id v186so3885438ybg.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=HX3K8/M38GOxz7MBaV8SQMK2kX30ZW3LfyRq0IGJqoWQxiTrdOyI4vVpFIvoGnVDYl Sita8epPuiWOSj+PtXY9DXEjhyUdtgBfyhXXWr9IeuzCYXzWFIjb9RcL3TdUBbh9N01m zczEttR130Rcv7gub4X10AwpiBB9f+p8Tn+Wex/a2/XrekNU4yzRxIiNhxA49Yb+fhnp RD08pYc1vCNJekdpczSIfvVOTdLe7pRM//V/HQRLjJX6rwnJ0QKC7f51WFjSb2lN1Py+ hBtUbH6RU4pjUWibbKu9Uf9CiOaE19QQ9rUFsZJmz+mHAiWvn+LWQGzgOBLFhowOthLp VzHg== X-Gm-Message-State: AOAM532uF5OhT1yKWgoL+2BM2LGx1lcWrIB/EUyWRP/UIrgzlLjCOo6m aw4j98S2/sAv6la6/3ZkUl1vUFuFXDCZKQlzgFd1nQ== 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" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.