From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from canpmsgout03.his.huawei.com (canpmsgout03.his.huawei.com [113.46.200.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 BA7F82FB969 for ; Tue, 7 Jul 2026 11:48:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.218 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783424905; cv=none; b=WreuKeaedUfkLxBXL2pSaCt+K6k9lrzJ3ecDKMR4GisUuOElKw9fiVRgyPb8cY78aGSv7A+wInoYxDx/2m0/h1IE6Dzd8ajUjWJHtPbhI72MlcyFtASHuoFfEyIC+uJpY8ehX8y4lXzH40fLpDgcqvVJ30qNKc4FqzOVzLkDYsQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783424905; c=relaxed/simple; bh=F87vvyew+s6Gkw0BF1GWNWjtBks+KrvzrxQfydIJsGw=; h=Message-ID:Date:MIME-Version:Subject:To:CC:References:From: In-Reply-To:Content-Type; b=kTXhAqnTUE40hXvncifaYT3wngDf7M9zW28BDgJmEIm8zg/AyKDXu9+pHPLrPv/B/g/ZDOFBcdfRjSP5KPN6hwahmBTr6JlUUyJKnCQvI5e4fXvaW7gBqLejkIf8ZkD4yju0vgPJIbap/+fYnOhoYhPHMJjpaFkJ1P1oa5h38O8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b=Lp9/IJDW; arc=none smtp.client-ip=113.46.200.218 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b="Lp9/IJDW" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=GQ0mvywMk1VYYOPBF5PvfJak/QAKIBpitC3KAeG7XY0=; b=Lp9/IJDW0+fMhUe2D2c7Pxs+psR2xzhuJBRSozphimRGSOx/peqUwYuBnRGHBZfVoaMu6L4iC UkKTve2BKsVhZCC8/8/OQMn1T4wsjMlaJjcR8BQtbUdmD72ShTagpcLqBR53ClUDZZDnYgZAG9k 6LYz4Th35zqYGoyXSpwTTqc= Received: from mail.maildlp.com (unknown [172.19.162.223]) by canpmsgout03.his.huawei.com (SkyGuard) with ESMTPS id 4gvfQb0MvzzpStg; Tue, 7 Jul 2026 19:39:35 +0800 (CST) Received: from kwepemo200010.china.huawei.com (unknown [7.202.195.178]) by mail.maildlp.com (Postfix) with ESMTPS id A17B440575; Tue, 7 Jul 2026 19:48:13 +0800 (CST) Received: from [10.174.178.56] (10.174.178.56) by kwepemo200010.china.huawei.com (7.202.195.178) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.36; Tue, 7 Jul 2026 19:48:12 +0800 Message-ID: Date: Tue, 7 Jul 2026 19:48:12 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 1/2] ARM: mm: fix use-after-free in __do_user_fault() under CONFIG_DEBUG_USER To: Xie Yuanbin , , , , , , , , , , CC: , , , , , References: <20260626073048.3595106-2-xiqi2@huawei.com> <20260706133247.145485-1-xieyuanbin1@huawei.com> Content-Language: en-GB From: Qi Xi In-Reply-To: <20260706133247.145485-1-xieyuanbin1@huawei.com> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: kwepems500002.china.huawei.com (7.221.188.17) To kwepemo200010.china.huawei.com (7.202.195.178) On 06/07/2026 21:32, Xie Yuanbin wrote: > On Fri, 26 Jun 2026 15:30:47 +0800, Qi Xi wrote: >> @@ -181,7 +181,9 @@ __do_user_fault(unsigned long addr, unsigned int fsr, unsigned int sig, >> pr_err("8<--- cut here ---\n"); >> pr_err("%s: unhandled page fault (%d) at 0x%08lx, code 0x%03x\n", >> tsk->comm, sig, addr, fsr); >> + mmap_read_lock(tsk->mm); >> show_pte(KERN_ERR, tsk->mm, addr); >> + mmap_read_unlock(tsk->mm); >> show_regs(regs); >> } >> #endif > I found that this fix does not completely solve the problem. For a user > fault, the addr could also be a kernel address. For arm32/x86, the kernel > address space and user address space share the same pgd page table, > but the kernel address space's page table is not protected by > current->mm->mmap_lock. > > I have written a use case to construct and verify this point. When A user > program accesses a kernel address and triggers __do_user_fault(), > show_pte() will directly print the kernel page table. > > So, I suggest that: > ```c > if (user_mode(regs)) { > struct mm_struct *const pt_mm = addr >= TASK_SIZE ? > &init_mm : current->mm; > > mmap_read_lock(pt_mm); > show_pte(KERN_ALERT, pt_mm, addr); > mmap_read_unlock(pt_mm); > } else { > // .. keep nothing change > show_pte(KERN_ALERT, current->mm, addr); > } > ``` > > I have read this article: > Link: https://docs.kernel.org/mm/process_addrs.html > `mmap_read_lock(&init_mm)` should be able to ensure that the kernel > address's page tables can be traversed. But I'm not quite sure if > `mmap_read_lock(¤t->mm)` provides protection for user-space non-VMA > addresses? You're right. And I think the fix is to simply skip show_pte() for kernel addresses. For do_DataAbort() fallback: if (user_mode(regs)) { if (addr < TASK_SIZE) { mmap_read_lock(current->mm); show_pte(KERN_ALERT, current->mm, addr); mmap_read_unlock(current->mm); } } else { show_pte(KERN_ALERT, current->mm, addr); } For a user-mode fault on a kernel address, printing kernel page tables via show_pte() does not help. And The fault address is already printed above. So it's safe and reasonable to skip it. Same pattern applies to __do_user_fault(). > Also cc to mm maintainers: > Cc: David Hildenbrand > Cc: Lorenzo Stoakes > Cc: Liam R. Howlett > Cc: Vlastimil Babka > Cc: Mike Rapoport > Cc: Suren Baghdasaryan > Cc: Michal Hocko > Cc: Linus Walleij