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 X-Spam-Level: X-Spam-Status: No, score=-15.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 08650C433B4 for ; Tue, 13 Apr 2021 18:02:32 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6C5AE613B1 for ; Tue, 13 Apr 2021 18:02:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6C5AE613B1 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=X1RJRL+H174463KacSrd0gReJ50xDDPeFMtaCDUS+Eg=; b=d/aGTYIkuaLeKR//dJ8JIO17F EhT0pjaNVPgurN7ANc2bifkeilSGonFh4dO6YaG8cdZZ+XQnBbIa9/Y+NuaICyo3yF/tzen801H+g l20fGDLZDH2LzOmbX6h8QnO5SrYWqqZ8eNYseHuFb+Y6JuaaC8nMCu3pI/nnViju8VxnUdKQ/Mjsw 3dD/5WXg+2/iajsTNlBHVI6YkK3xhNfFDES/PFcYtWBNJ9Ig3Dqmzl1DXa5RYsVcfcX2E9hMsFjQF gqtpx5uGS8gQPp6iA4Yy9BiyXoaqj181VICNkXPw0cptNOGZMHhmyll/rwaJBekOlbD8bUSKXBfNx bcaQHu2iA==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lWNLA-00A3Xl-Hg; Tue, 13 Apr 2021 18:00:47 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lWNL7-00A3XP-BC for linux-arm-kernel@desiato.infradead.org; Tue, 13 Apr 2021 18:00:41 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=3FAnfQSoKgfT0iYMpUqDuU2u68J3kfKiyASbLtU3BHs=; b=wYoljFngY+rTAnj4llRRzNLSg8 FQ0QWmmJ8O7016kwSoc8iHD0mb2RP0al6smrj04qvnaRHzFLH6uAKsKc1J4cLTEvfR6eYtFQURvdF kktUiX//BI5czgvlsz4MQl8DF2B/Nln95cuU1kGNwqHMYEnvqybXVEvU1wybKSYXrcD77CjNUOfDb 566/knKuqLI40krjSn4J29+/qQDB7R4RxspNH6YqbNFsXkfNrapeRyvM9oh/jkHyEYRCXaw2BRr/K iEyjWGNEuKBXqlSWH2swfB0tZ420yEh6rKCmMaBRDoVDee0m78XgPHIZvrCf/dSGXDg587iiIJ1j9 7xulzfoA==; Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lWNL4-007EtY-HU for linux-arm-kernel@lists.infradead.org; Tue, 13 Apr 2021 18:00:40 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id AAB07613B6; Tue, 13 Apr 2021 18:00:35 +0000 (UTC) Date: Tue, 13 Apr 2021 19:00:33 +0100 From: Catalin Marinas To: Liam Howlett Cc: Andre Przywara , Will Deacon , Peter Collingbourne , "linux-arm-kernel@lists.infradead.org" , "linux-kernel@vger.kernel.org" , "netdev@vger.kernel.org" , "bpf@vger.kernel.org" , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Amit Daniel Kachhap Subject: Re: [PATCH] arch/arm64/kernel/traps: Use find_vma_intersection() in traps for setting si_code Message-ID: <20210413180030.GA31164@arm.com> References: <20210407150940.542103-1-Liam.Howlett@Oracle.com> <20210412174343.GG2060@arm.com> <20210413143035.7zrct6a3up42uaoo@revolver> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20210413143035.7zrct6a3up42uaoo@revolver> User-Agent: Mutt/1.10.1 (2018-07-13) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210413_110038_663038_209FE4FF X-CRM114-Status: GOOD ( 38.07 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Tue, Apr 13, 2021 at 04:52:34PM +0000, Liam Howlett wrote: > * Catalin Marinas [210412 13:44]: > > On Wed, Apr 07, 2021 at 03:11:06PM +0000, Liam Howlett wrote: > > > find_vma() will continue to search upwards until the end of the virtual > > > memory space. This means the si_code would almost never be set to > > > SEGV_MAPERR even when the address falls outside of any VMA. The result > > > is that the si_code is not reliable as it may or may not be set to the > > > correct result, depending on where the address falls in the address > > > space. > > > > > > Using find_vma_intersection() allows for what is intended by only > > > returning a VMA if it falls within the range provided, in this case a > > > window of 1. > > > > > > Signed-off-by: Liam R. Howlett > > > --- > > > arch/arm64/kernel/traps.c | 3 ++- > > > 1 file changed, 2 insertions(+), 1 deletion(-) > > > > > > diff --git a/arch/arm64/kernel/traps.c b/arch/arm64/kernel/traps.c > > > index a05d34f0e82a..a44007904a64 100644 > > > --- a/arch/arm64/kernel/traps.c > > > +++ b/arch/arm64/kernel/traps.c > > > @@ -383,9 +383,10 @@ void force_signal_inject(int signal, int code, unsigned long address, unsigned i > > > void arm64_notify_segfault(unsigned long addr) > > > { > > > int code; > > > + unsigned long ut_addr = untagged_addr(addr); > > > > > > mmap_read_lock(current->mm); > > > - if (find_vma(current->mm, untagged_addr(addr)) == NULL) > > > + if (find_vma_intersection(current->mm, ut_addr, ut_addr + 1) == NULL) > > > code = SEGV_MAPERR; > > > else > > > code = SEGV_ACCERR; [...] > > I don't think your change is entirely correct either. We can have a > > fault below the vma of a stack (with VM_GROWSDOWN) and > > find_vma_intersection() would return NULL but it should be a SEGV_ACCERR > > instead. > > I'm pretty sure I am missing something. From what you said above, I > think this means that there can be a user cache fault below the stack > which should notify the user application that they are not allowed to > expand the stack by sending a SIGV_ACCERR in the si_code? Is this > expected behaviour or am I missing a code path to this function? My point was that find_vma() may return a valid vma where addr < vm_end but also addr < vm_addr. It's the responsibility of the caller to check that that vma can be expanded (VM_GROWSDOWN) and we do something like this in __do_page_fault(). find_vma_intersection(), OTOH, requires addr >= vm_start. If we hit this case (addr < vm_start), normally we'd first need to check whether it's expandable and, if not, return MAPERR. If it's expandable, it should be ACCERR since something else caused the fault. Now, I think at least for user_cache_maint_handler(), we can assume that __do_page_fault() handled any expansion already, so we don't need to check it here. In this case, your find_vma_intersection() check should work. Are there other cases where we invoke arm64_notify_segfault() without a prior fault? I think in swp_handler() we can bail out early before we even attempted the access so we may report MAPERR but ACCERR is a better indication. Also in sys_rt_sigreturn() we always call it as arm64_notify_segfault(regs->sp). I'm not sure that's correct in all cases, see restore_altstack(). I guess this code needs some tidying up. > > Maybe this should employ similar checks as __do_page_fault() (with > > expand_stack() and VM_GROWSDOWN). > > You mean the code needs to detect endianness and to check if this is an > attempt to expand the stack for both cases? Nothing to do with endianness, just the relation between the address and the vma->vm_start and whether the vma can be expanded down. -- Catalin _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel