From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pandora.armlinux.org.uk (pandora.armlinux.org.uk [78.32.30.218]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2706F3E8C59 for ; Fri, 26 Jun 2026 09:44:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=78.32.30.218 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782467097; cv=none; b=VUC03Kz7DUVf67LgIY+qFZaix3yZ4A+2OK3L0ZPftc5Yg9tj1YRlfM5q6rg7AFcH1fJF9YYj155/9pQIaM0d+JxRLcyGZ7NEDq5equrhsvHYq0armaysCVTM7/sx7vcppmUReWaPi9rkn/8Badrxz60WcFDCGkMfHqvic222IpY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782467097; c=relaxed/simple; bh=u5MV01UNnLnFWtlqAcbMz6g7h8+dGTis5YKubznYYQ8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=QYNFoMY8YMmFDmBQPVo31eJI1f0RzxMBtHXCyWrQ587MfTMgQEtjxJl2gFZo2KTLymlhBSSmA2N/pkabaAJ/MptTxYKFxka5gigk77RGcgfohSq2J8ArPEeBiL7kbkayf9fp4ZIsILfWlgQex0oYcWbBT/qFrgKNSulMhD+U7oI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=armlinux.org.uk; spf=none smtp.mailfrom=armlinux.org.uk; dkim=pass (2048-bit key) header.d=armlinux.org.uk header.i=@armlinux.org.uk header.b=bFINEHwW; arc=none smtp.client-ip=78.32.30.218 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=armlinux.org.uk Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=armlinux.org.uk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=armlinux.org.uk header.i=@armlinux.org.uk header.b="bFINEHwW" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=armlinux.org.uk; s=pandora-2019; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=zO17xD6fVEncCUQRFi4FEtuaNS1prWDROZS9ASYU5to=; b=bFINEHwWCcOm/GC2KPSl4Sto2l 89WifYVCpx0fYRkgalv1HFMY/DqG12zLyATQG2o0iTJlSYZ4KDUxyyh1WRLlX69Bh+tpCjkVVSSfy PbJ1ID4RmvaKBUR8JNc7mMESwc0lPxAUQi9oaC6S7+896F90Y2yZbTGZMVebsLe5TtIvexuhP8Sv9 DXKOQ+McLu+eKD7t+hfzEIAmlAk79JAbyuTJxhYoi5MvJV58Yherw+J65BaW1XK1S5r70xkTmo2i7 gH9QJPa1oxSEf50MNsanAyjYDjNj1dYxqmvSbsHmzmMR4Vgy6oO3Vdj+oFpCkE9NHm2K1gr1FHcQV I66q4E8w==; Received: from shell.armlinux.org.uk ([fd8f:7570:feb6:1:5054:ff:fe00:4ec]:38334) by pandora.armlinux.org.uk with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wd376-0000000024R-3rzm; Fri, 26 Jun 2026 10:44:44 +0100 Received: from linux by shell.armlinux.org.uk with local (Exim 4.98.2) (envelope-from ) id 1wd374-000000002wP-1kdy; Fri, 26 Jun 2026 10:44:42 +0100 Date: Fri, 26 Jun 2026 10:44:42 +0100 From: Russell King To: Qi Xi Cc: Andrew Morton , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Yuanbin Xie , Nanyong Sun Subject: Re: [PATCH v3 1/2] ARM: mm: fix use-after-free in __do_user_fault() under CONFIG_DEBUG_USER Message-ID: References: <20260626073048.3595106-1-xiqi2@huawei.com> <20260626073048.3595106-2-xiqi2@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260626073048.3595106-2-xiqi2@huawei.com> Sender: "Russell King,,," On Fri, Jun 26, 2026 at 03:30:47PM +0800, Qi Xi wrote: > When CONFIG_DEBUG_USER is enabled with user_debug=31 on 32-bit ARM, > a user page fault triggers show_pte() via __do_user_fault() after > do_page_fault() has already released mmap_read_lock. If another > thread concurrently calls munmap(), the page table pages can be > freed while show_pte() is still reading them, causing a > use-after-free in show_pte(). > > The race can be reproduced on multi_v7_defconfig with: > CONFIG_DEBUG_USER=y > CONFIG_ARM_LPAE=y > kernel command line: user_debug=31 > > A delay inserted in show_pte() for testing widens the race window and > makes the UAF reliably reproducible. On LPAE, the race works as > follows: > > CPU 0 (fault path) CPU 1 (munmap) > munmap(page 0) -> clears PTE[0] > PTE/PMD pages remain > > read page 0 -> page fault > -> do_DataAbort() > -> do_page_fault() > -> lock_mm_and_find_vma() -> no VMA > (mmap_read_lock released) > -> __do_user_fault() > -> show_pte(tsk->mm, addr) > -> *pgd (valid) > -> p4d/pud checks pass > > -> [delay] munmap(page 1) > -> clears PTE[1] > -> PTE/PMD pages freed > -> PGD cleared > > -> pmd_offset(pud, addr) > -> *pud=0 -> __va(0) > -> dereference > -> secondary data abort (kernel) > > Fix by taking mmap_read_lock() around show_pte() in __do_user_fault(). > __do_user_fault() is called from process context with interrupts > enabled, so the context can sleep and mmap_read_lock() is safe here. This is a fault path which should only be called when something is already wrong, the mm lock may already be held (e.g. a kernel fault while already holding the mmap lock.) We can't take any locks here. -- RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!