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 E0F92C07E9D for ; Sat, 24 Sep 2022 00:08:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233023AbiIXAIM (ORCPT ); Fri, 23 Sep 2022 20:08:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233190AbiIXAHo (ORCPT ); Fri, 23 Sep 2022 20:07:44 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6E23114A7B1 for ; Fri, 23 Sep 2022 17:06:01 -0700 (PDT) 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 D968E616DF for ; 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.