Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp1702192rwb; Fri, 23 Sep 2022 17:33:05 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6nXFzIAwHVRK6APz3fU+AP+JGCUlAlqr4F80wxcNFkVXaO4hF/OzMFAp6nfYqDqmcM2LX0 X-Received: by 2002:a17:907:760d:b0:77b:1d8d:7700 with SMTP id jx13-20020a170907760d00b0077b1d8d7700mr9209840ejc.195.1663979585001; Fri, 23 Sep 2022 17:33:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663979584; cv=none; d=google.com; s=arc-20160816; b=e9bBrqGfSGbom1NVf2cEdBxtNt2G9uEviI2u8t72pXnD1cGbXFGSGxNVxrnx/fw0+A W4gfR58aUNiJy/LMfZubATSF6kVBDDifrG4JbIcOL2sLfFKacpzn+TfrQbrKK2duWx7M CtUEPy9LK5FM2GEbYaPdGqAo9Bq8qIjyL3kAwW7Y1/WnHzAbdzItn+gqzTgZFaYr7rJD 7BRohovr9kF5AHCrCtv2lU/jMolct+uC/wfxtavR3DOLVUDf+KOOWV1IqSI5VXmxCqAU SBuP2nU1xvgohHTPRqwmXXgePo6XQYivhiGBKT2wfao7D/+/GvemktxJX1PA/JO4ykLX a0Ww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=JZkrI3y54lEUvAWGt8BG1unM7WxI6qxTPlTNOOtQKAg=; b=J+bQ0zTAB9Gau1R8yw0zZL3udrPxo5Qjvxw8YdfjW9PLpMP3qbuY8uDSjXPMpxjp38 rBqGdjbsrhf+g+A07yKRRO/ygAB7EOfLbDWVaczuWbXZ5aNIAY2mIV5dXR20mQJe30y6 JciR+9ICkdaesAsm+++OKXiMZsB52aislD2p4it0aSsHWZPFxTZywmSOM+DT3WqXRf74 vU+utkz4WAFBgRmE9DxP3vbWkepLfQNCX+T4xj9YXAfgZi627IyAUx1YPP9PYiLVhD7t n4Uz3CzBvfE7fq+smN2H+wScbOB40tb+DH+fnViFVNlTTLiE0+vylzm/OVT55Ik6muP3 2VOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=NNQb1trd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id he17-20020a1709073d9100b007808f3f4cbcsi9931127ejc.239.2022.09.23.17.32.36; Fri, 23 Sep 2022 17:33:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=NNQb1trd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233011AbiIXAIL (ORCPT + 99 others); Fri, 23 Sep 2022 20:08:11 -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 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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.