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 17D0EC07E9D for ; Sat, 24 Sep 2022 00:06:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 88E2180033; Fri, 23 Sep 2022 20:06:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 83CF280016; Fri, 23 Sep 2022 20:06:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 704ED80033; Fri, 23 Sep 2022 20:06:00 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 5D92380016 for ; Fri, 23 Sep 2022 20:06:00 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 2D1D51A092B for ; Sat, 24 Sep 2022 00:06:00 +0000 (UTC) X-FDA: 79945036080.08.4DC4CF8 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf23.hostedemail.com (Postfix) with ESMTP id C80DA140021 for ; Sat, 24 Sep 2022 00:05:58 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id CF3BF60B2C; Sat, 24 Sep 2022 00:05:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0E05EC433D6; Sat, 24 Sep 2022 00:05:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1663977957; bh=mWdycZrVbYlYerQP3VWTZuUZAv52rEKHRKG7opsxIoQ=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=NNQb1trdB5wAEa0rLSi7MfG1r3yx6medNJchwv/GWiAbeVAngL2qIBHEmeDJsyYyW 6xv59nob/pbHQWYWcsDBGkGRC7hUPZTlTuh8TlrlFo3hd10yJRP1Tm7mf8hAaC7etY rfp6I2AI1MNOpQt4eLkK1OK1LI4Er+Xib8koMOdE= Date: Fri, 23 Sep 2022 17:05:54 -0700 From: Andrew Morton To: Liu Shixin Cc: Liu Zixian , Mike Kravetz , Muchun Song , Sidhartha Kumar , John Hubbard , "David Hildenbrand" , Kefeng Wang , , Subject: Re: [PATCH v3] mm: hugetlb: fix UAF in hugetlb_handle_userfault Message-Id: <20220923170554.7046bb023f8cf582b5909b77@linux-foundation.org> In-Reply-To: <20220923042113.137273-1-liushixin2@huawei.com> References: <20220923042113.137273-1-liushixin2@huawei.com> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=NNQb1trd; spf=pass (imf23.hostedemail.com: domain of akpm@linux-foundation.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1663977958; a=rsa-sha256; cv=none; b=0Tq0cmksNg8qHZiqWqu+HL0TbumKwFjWUDhzPzGjGMEJ3q9mtFDM7aDaDa6t8a+nbStnRG 6QeCFwjJBYdCEhTGmFzkXy6dmmQZL505yUckRS7/X2CFeNB1T1TKJ5NRi32cJt5XoIRw+/ XYwPAZN3iSlqpMc0eYnx8rLCoRYgW/s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1663977958; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=JZkrI3y54lEUvAWGt8BG1unM7WxI6qxTPlTNOOtQKAg=; b=HAh+2a7fzkxEVIu9Niedx50lGooUmm701i1pZYNBTsJwFzBNj/C2LMzmdnthAx+7rq/TCH MJXc0F1CJAbWM7dPaPQ/9x+ecPANSiU1NgrQgBTPMOTBAczcU7vIG8SCQVE+f8YATkzQhH tiDVDS0ohKOy1r6t3QK7KbmDwq/ATLw= X-Stat-Signature: 7e4wricf7mj3rdy6wifyj886cwgrdy3z X-Rspamd-Queue-Id: C80DA140021 Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=NNQb1trd; spf=pass (imf23.hostedemail.com: domain of akpm@linux-foundation.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org; dmarc=none X-Rspam-User: X-Rspamd-Server: rspam03 X-HE-Tag: 1663977958-879922 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 Fri, 23 Sep 2022 12:21:13 +0800 Liu Shixin wrote: > The vma_lock and hugetlb_fault_mutex are dropped before handling > userfault and reacquire them again after handle_userfault(), but > reacquire the vma_lock could lead to UAF[1,2] due to the following > race, > > hugetlb_fault > hugetlb_no_page > /*unlock vma_lock */ > hugetlb_handle_userfault > handle_userfault > /* unlock mm->mmap_lock*/ > vm_mmap_pgoff > do_mmap > mmap_region > munmap_vma_range > /* clean old vma */ > /* lock vma_lock again <--- UAF */ > /* unlock vma_lock */ > > Since the vma_lock will unlock immediately after hugetlb_handle_userfault(), > let's drop the unneeded lock and unlock in hugetlb_handle_userfault() to fix > the issue. > > [1] https://lore.kernel.org/linux-mm/000000000000d5e00a05e834962e@google.com/ > [2] https://lore.kernel.org/linux-mm/20220921014457.1668-1-liuzixian4@huawei.com/ > Reported-by: syzbot+193f9cee8638750b23cf@syzkaller.appspotmail.com > Reported-by: Liu Zixian > Fixes: 1a1aad8a9b7b ("userfaultfd: hugetlbfs: add userfaultfd hugetlb hook") > CC: stable@vger.kernel.org # 4.14+ Patch is against mm-unstable, which isn't appropriate for a backport. Could you please something against current -linus (which will be more backportable), then I'll figure out the fallout on mm-unstable. Thanks.