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 31E92C433F5 for ; Wed, 23 Feb 2022 08:56:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7EF408D0002; Wed, 23 Feb 2022 03:55:59 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 778168D0001; Wed, 23 Feb 2022 03:55:59 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 63F2B8D0002; Wed, 23 Feb 2022 03:55:59 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.27]) by kanga.kvack.org (Postfix) with ESMTP id 50E318D0001 for ; Wed, 23 Feb 2022 03:55:59 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 2B375231B5 for ; Wed, 23 Feb 2022 08:55:59 +0000 (UTC) X-FDA: 79173437238.07.784DD4D Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf17.hostedemail.com (Postfix) with ESMTP id 86D3440004 for ; Wed, 23 Feb 2022 08:55:58 +0000 (UTC) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 4EF7A21119; Wed, 23 Feb 2022 08:55:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1645606557; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=rSWEIXnuQwpAk+MXHN8ZsAjaODfoEUy8DAhjKKDK/28=; b=lC6VZFYW0mGAsEmT5L6fmOa08ga+ZVyisgDMw3BbvZrTaWThVfRu/4FYG2ktsZB7sQflVe IOkYvhzDSqSYsOMhspba/y3tCILrDymeWXWoNnFFMXEa5p3FUtd9xlFZnP1PvxTQWqqzTG 3gBTDpdfKIwqNgBKvTK1qsYw1jipMbQ= Received: from suse.cz (unknown [10.100.201.86]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 69A7EA3B85; Wed, 23 Feb 2022 08:55:56 +0000 (UTC) Date: Wed, 23 Feb 2022 09:55:54 +0100 From: Michal Hocko To: Suren Baghdasaryan Cc: akpm@linux-foundation.org, ccross@google.com, sumit.semwal@linaro.org, dave.hansen@intel.com, keescook@chromium.org, willy@infradead.org, kirill.shutemov@linux.intel.com, vbabka@suse.cz, hannes@cmpxchg.org, ebiederm@xmission.com, brauner@kernel.org, legion@kernel.org, ran.xiaokai@zte.com.cn, sashal@kernel.org, chris.hyser@oracle.com, dave@stgolabs.net, pcc@google.com, caoxiaofeng@yulong.com, david@redhat.com, gorcunov@gmail.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@android.com, syzbot+aa7b3d4b35f9dc46a366@syzkaller.appspotmail.com Subject: Re: [PATCH v4 3/3] mm: fix use-after-free when anon vma name is used after vma is freed Message-ID: References: <20220222054025.3412898-1-surenb@google.com> <20220222054025.3412898-3-surenb@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Queue-Id: 86D3440004 X-Stat-Signature: yjgkmtroi9tadxkgggscstt4e4eeo433 X-Rspam-User: Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=lC6VZFYW; spf=pass (imf17.hostedemail.com: domain of mhocko@suse.com designates 195.135.220.28 as permitted sender) smtp.mailfrom=mhocko@suse.com; dmarc=pass (policy=quarantine) header.from=suse.com X-Rspamd-Server: rspam05 X-HE-Tag: 1645606558-840095 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 Tue 22-02-22 07:43:40, Suren Baghdasaryan wrote: > On Tue, Feb 22, 2022 at 12:06 AM Michal Hocko wrote: > > > > On Mon 21-02-22 21:40:25, Suren Baghdasaryan wrote: > > > When adjacent vmas are being merged it can result in the vma that was > > > originally passed to madvise_update_vma being destroyed. In the current > > > implementation, the name parameter passed to madvise_update_vma points > > > directly to vma->anon_name->name and it is used after the call to > > > vma_merge. In the cases when vma_merge merges the original vma and > > > destroys it, this will result in use-after-free bug as shown below: > > > > > > madvise_vma_behavior << passes vma->anon_name->name as name param > > > madvise_update_vma(name) > > > vma_merge > > > __vma_adjust > > > vm_area_free <-- frees the vma > > > replace_vma_anon_name(name) <-- UAF > > > > This seems to be stale because bare const char pointer is not passed in > > the call chain. In fact I am not even sure there is any actual UAF here > > after the rework. > > Could you be more specific in describing the scenario? > > Yes, sorry, I need to update the part of the description talking about > passing vma->anon_name->name directly. > I think UAF is still there, it's just harder to reproduce (admittedly > I could not reproduce it with the previous reproducer). The scenario > would be when a vma with vma->anon_name->kref == 1 is being merged > with another one and freed in the process: > > madvise_vma_behavior > anon_name = vma_anon_name(vma) <-- does not increase refcount > madvise_update_vma(anon_name) > *prev = vma_merge <-- returns another vma > __vma_adjust > vm_area_free(vma) > free_vma_anon_name > anon_vma_name_put > vma_anon_name_free <-- frees the vma->anon_name > vma = *prev <-- original vma was freed How come this is not a UAF in the first place? > replace_vma_anon_name(vma, >>anon_name<<) <-- UAF > > Does this make sense or did I miss something? Sorry for being dense but I still do not see it. If *prev has been freed then we already have a different UAF. Admittedly, I am not really fluent at vma_merge code path so I am not really sure your chain above is really possible. I will try to double check later. -- Michal Hocko SUSE Labs