Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp624280lqp; Thu, 21 Mar 2024 10:30:30 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVb2H+9h3RfWVeHZ9O0hpLJLq4L8tg60p1Zey1zZ1m28w5dnKJKYbyw1lsjEPOT/7j2GSXkyM6D3aJiUVyHJhbXtYGQBvtVvrobgpHpaA== X-Google-Smtp-Source: AGHT+IFhApRr9LF8AfQoJh9T37OeDcb/2APjikAGpoL/uRYEvyTDaUNPiUY54YdikyxY3nookfks X-Received: by 2002:a05:622a:58c:b0:42e:d04a:4c85 with SMTP id c12-20020a05622a058c00b0042ed04a4c85mr2614993qtb.66.1711042230202; Thu, 21 Mar 2024 10:30:30 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711042230; cv=pass; d=google.com; s=arc-20160816; b=rVS/qpNfi52jdPePStn/7VAUVm/v7yyJPvRMXrEjP25NVzqVY51s8uiE0KalRXECs5 010XoCu3fCsYFTCS2Yeuq8fJk67WSXSQfRkL4RCpYC+lImUqO7sGSw2NpdHhJ1/SsZ17 qH09IfO3DyVau8tkac6z7RQYOe1OX5mNQi+tosRbp5jApS3ERh/rK86pQaPZqWtk63EW FtH6d033SoY5GnsFQi76xD8C3XLH66NA78i/hYkmohgZLiArHAX7bvaO9nL5xrxhrajv wbTViJs1Ori+SKlwbeSuYUj2ZOrQqLx21NjjTk9e2kNJLcUDTz4fx0hF+dLMhVOKUTtV Vj+A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id; bh=lGa0gIWLoWrjdnFA26nph0dMAg/4xGjL+x8igH5HbPs=; fh=dTcrqJn+d8RH3F5WTpGmlSJW7F3l/kChu5xZUOYsoIY=; b=oJLhuM1qkIACUmYxVkeCVEo6OCZQ3+1UlM1uS3kOAA+XbelSomMwSri74y0f6d9WIZ Z9zIaOGI6/B5jo4RRaOKLjKUmvrN5vwuSiENaF7I9djUIjF0Gz9+sLE0h8jv6nOP9FVf arBeGCOKa/tY3BvHRP4XgdFc0HGnXNE19LOD9XuzJHtpTPV9BgnuYeqa3K3QTrX1JANw Lv1CaOCHy9xpIl3OdAiVn8KibWHwvt5Vdd9HthEhD2Qqa71cvumJ8Sq5SfncPKA0RUD+ rfj+QkTzVsW+lqu46XbGPhmxmvmPXZRjbdvhTZ4j8Z3jT1SKJpGHqMLkA+VqYxT2Vgzt YXHg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei-partners.com dmarc=pass fromdomain=huawei-partners.com); spf=pass (google.com: domain of linux-kernel+bounces-110497-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-110497-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei-partners.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id e8-20020ac85dc8000000b00430d6e93300si174660qtx.199.2024.03.21.10.30.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Mar 2024 10:30:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-110497-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei-partners.com dmarc=pass fromdomain=huawei-partners.com); spf=pass (google.com: domain of linux-kernel+bounces-110497-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-110497-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei-partners.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id E34251C2196A for ; Thu, 21 Mar 2024 17:30:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3CBB083CBE; Thu, 21 Mar 2024 17:30:24 +0000 (UTC) Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) (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 1F549C2E9 for ; Thu, 21 Mar 2024 17:30:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.176.79.56 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711042223; cv=none; b=D+ksezhFbu5cy0y5WajXTFbfC7mcepj0vlTE5g9D1BiijeGte/e0yygrzrtbbdk15+edsS1YzQUcw+W6B21G9t8tP4aMEt49429TO24pcPiNrL2mjMsDtp7R/w2Gr6OJJ48l64HB1je9NyqfN8nBcTwolK+RScCBVtaieQ2Gv0M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711042223; c=relaxed/simple; bh=aCeT919OkCma1l6oDXXOSV7I7yWmK6bpOsYwA40kB1Y=; h=Message-ID:Date:MIME-Version:Subject:To:CC:References:From: In-Reply-To:Content-Type; b=T8kyeLVeKrLvnHFJiz9MjvINAzL6Q356KgcJudKT0Pi09qFaVpWmsme7k1rSQcCPtXGaI5dGaH5PbuaQjdxn7W7V2NT5qUK8NAF/rdXv0DDD7LZbpBdXZFZt95TkPRi4b+Adx60fTYrQerEl1t06vChvv8OhW9EnNPupKRH55/U= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei-partners.com; spf=pass smtp.mailfrom=huawei-partners.com; arc=none smtp.client-ip=185.176.79.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei-partners.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei-partners.com Received: from mail.maildlp.com (unknown [172.18.186.231]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4V0smv46GNz6K9C6; Fri, 22 Mar 2024 01:25:51 +0800 (CST) Received: from frapeml500002.china.huawei.com (unknown [7.182.85.205]) by mail.maildlp.com (Postfix) with ESMTPS id 120DC140A9C; Fri, 22 Mar 2024 01:30:11 +0800 (CST) Received: from [10.81.213.73] (10.81.213.73) by frapeml500002.china.huawei.com (7.182.85.205) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Thu, 21 Mar 2024 18:30:10 +0100 Message-ID: <9cfb4aa7-d927-4015-8ef8-1cd081250cdc@huawei-partners.com> Date: Thu, 21 Mar 2024 18:30:09 +0100 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 RESEND 1/1] um: oops on accessing a non-present page in the vmalloc area To: David Gow , Petr Tesarik CC: Richard Weinberger , Anton Ivanov , Johannes Berg , "open list:USER-MODE LINUX (UML)" , open list , Roberto Sassu References: <20240223140435.1240-1-petrtesarik@huaweicloud.com> Content-Language: en-US From: Petr Tesarik In-Reply-To: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-ClientProxiedBy: frapeml500001.china.huawei.com (7.182.85.94) To frapeml500002.china.huawei.com (7.182.85.205) On 3/21/2024 5:44 AM, David Gow wrote: > On Fri, 23 Feb 2024 at 22:07, Petr Tesarik wrote: >> >> From: Petr Tesarik >> >> If a segmentation fault is caused by accessing an address in the vmalloc >> area, check that the target page is present. >> >> Currently, if the kernel hits a guard page in the vmalloc area, UML blindly >> assumes that the fault is caused by a stale mapping and will be fixed by >> flush_tlb_kernel_vm(). Unsurprisingly, if the fault is caused by accessing >> a guard page, no mapping is created, and when the faulting instruction is >> restarted, it will cause exactly the same fault again, effectively creating >> an infinite loop. >> >> Signed-off-by: Petr Tesarik >> --- >> arch/um/kernel/trap.c | 4 ++++ >> 1 file changed, 4 insertions(+) >> >> diff --git a/arch/um/kernel/trap.c b/arch/um/kernel/trap.c >> index 6d8ae86ae978..d5b85f1bfe33 100644 >> --- a/arch/um/kernel/trap.c >> +++ b/arch/um/kernel/trap.c >> @@ -206,11 +206,15 @@ unsigned long segv(struct faultinfo fi, unsigned long ip, int is_user, >> int err; >> int is_write = FAULT_WRITE(fi); >> unsigned long address = FAULT_ADDRESS(fi); >> + pte_t *pte; >> >> if (!is_user && regs) >> current->thread.segv_regs = container_of(regs, struct pt_regs, regs); >> >> if (!is_user && (address >= start_vm) && (address < end_vm)) { >> + pte = virt_to_pte(&init_mm, address); >> + if (!pte_present(*pte)) >> + page_fault_oops(regs, address, ip); > > page_fault_oops() appears to be private to arch/x86/mm/fault.c, so > can't be used here? > Also, it accepts struct pt_regs*, not struct uml_pt_regs*, so would > need to at least handle the type difference here. Argh, you're right. This was originally a two-patch series, but Richard wanted improvements in the implementation which would require more effort, see here: http://lists.infradead.org/pipermail/linux-um/2024-January/006406.html So I wanted to fix only the infinite loop, but in the mean time I forgot about the dependency on the first patch: http://lists.infradead.org/pipermail/linux-um/2023-December/006380.html That's because a quick git grep page_fault_oops found the function. It was my mistake that I did not notice the other page_fault_oops() earlier. OK, please forget about this patch for now; I must rework it. > Could we equally avoid the infinite loop here by putting the > 'flush_tlb_kernel_vm();goto out;' behind a if (pte_present(...)) > check, and let the rest of the UML checks panic or oops if required. > (Actually OOPSing where we can under UML would be nice to do at some > point anyway, but is a bigger issue than just fixing a bug, IMO.) Yes, that would be the best quick fix until I get to implementing all the blows and whistles (oops_* helpers, notification chains, tainting, etc.). Petr T > Or am I lacking a prerequisite patch or applying this to the wrong > version (or otherwise missing something), as it definitely doesn't > build here. > > Cheers, > -- David