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.7 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,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 BD786C11F68 for ; Tue, 29 Jun 2021 08:37:38 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 8EAFA61DE4 for ; Tue, 29 Jun 2021 08:37:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8EAFA61DE4 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=bombadil.20210309; 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=64Lfiy9R9jBvzjP8FtURc3DSKp/uHzYJDPVO5u/AXKE=; b=szBCm4sNskwZwA UeuKtOyU4olY1nbbrE32mweujV2JmjfPtuFO0D2gS+sJAMNBMqO5Qyv2BqYVbrryxirpBM0NGo/YV anlmm6LHhmrZDB2rLc3iFSXdCD1Nm+TtGrKTsCdw2McaRREmvwr46N+j8GK8zpoGg9rFk7fsDMzyJ kPc596tvQjGuMzFJRpQPbVH2HqAE2T2lb/AHHK+LWfrwT9BU45nWTUm+xop07OcKZ0wxgFEAds6KW b5c80QoDQ2XU9uLILJEeVvOLQU9C8vDXGobozcnkTF4H1kkEr05ma3QJsJpjR4vKz5DQllvCXrj+1 oncvMRnGdV/av37hkaFg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ly9DI-00ADmi-Fk; Tue, 29 Jun 2021 08:35:25 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ly98z-00AC3F-I2 for linux-arm-kernel@lists.infradead.org; Tue, 29 Jun 2021 08:30:59 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0ECD161DD1; Tue, 29 Jun 2021 08:30:54 +0000 (UTC) Date: Tue, 29 Jun 2021 09:30:52 +0100 From: Catalin Marinas To: Robin Murphy Cc: Chen Huang , Al Viro , Matthew Wilcox , Christoph Hellwig , Mark Rutland , Andrew Morton , Stephen Rothwell , Randy Dunlap , Will Deacon , Linux ARM , linux-mm , open list Subject: Re: [BUG] arm64: an infinite loop in generic_perform_write() Message-ID: <20210629083052.GA10900@arm.com> References: <1c635945-fb25-8871-7b34-f475f75b2caf@huawei.com> <27fbb8c1-2a65-738f-6bec-13f450395ab7@arm.com> <20210624185554.GC25097@arm.com> <20210625103905.GA20835@arm.com> <7f14271a-9b2f-1afc-3caf-c4e5b36efa73@arm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <7f14271a-9b2f-1afc-3caf-c4e5b36efa73@arm.com> 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-20210629_013057_714863_EEE9C554 X-CRM114-Status: GOOD ( 24.56 ) 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 Mon, Jun 28, 2021 at 05:22:30PM +0100, Robin Murphy wrote: > From: Robin Murphy > Subject: [PATCH] arm64: Avoid premature usercopy failure > > Al reminds us that the usercopy API must only return complete failure > if absolutely nothing could be copied. Currently, if userspace does > something silly like giving us an unaligned pointer to Device memory, > or a size which overruns MTE tag bounds, we may fail to honour that > requirement when faulting on a multi-byte access even though a smaller > access could have succeeded. > > Add a mitigation to the fixup routines to fall back to a single-byte > copy if we faulted on a larger access before anything has been written > to the destination, to guarantee making *some* forward progress. We > needn't be too concerned about the overall performance since this should > only occur when callers are doing something a bit dodgy in the first > place. Particularly broken userspace might still be able to trick > generic_perform_write() into an infinite loop by targeting write() at > an mmap() of some read-only device register where the fault-in load > succeeds but any store synchronously aborts such that copy_to_user() is > genuinely unable to make progress, but, well, don't do that... > > Reported-by: Chen Huang > Suggested-by: Al Viro > Signed-off-by: Robin Murphy Thanks Robin for putting this together. I'll write some MTE kselftests to check for regressions in the future. > diff --git a/arch/arm64/lib/copy_from_user.S b/arch/arm64/lib/copy_from_user.S > index 95cd62d67371..5b720a29a242 100644 > --- a/arch/arm64/lib/copy_from_user.S > +++ b/arch/arm64/lib/copy_from_user.S > @@ -29,7 +29,7 @@ > .endm > .macro ldrh1 reg, ptr, val > - user_ldst 9998f, ldtrh, \reg, \ptr, \val > + user_ldst 9997f, ldtrh, \reg, \ptr, \val > .endm > .macro strh1 reg, ptr, val > @@ -37,7 +37,7 @@ > .endm > .macro ldr1 reg, ptr, val > - user_ldst 9998f, ldtr, \reg, \ptr, \val > + user_ldst 9997f, ldtr, \reg, \ptr, \val > .endm > .macro str1 reg, ptr, val > @@ -45,7 +45,7 @@ > .endm > .macro ldp1 reg1, reg2, ptr, val > - user_ldp 9998f, \reg1, \reg2, \ptr, \val > + user_ldp 9997f, \reg1, \reg2, \ptr, \val > .endm > .macro stp1 reg1, reg2, ptr, val > @@ -53,8 +53,10 @@ > .endm > end .req x5 > +srcin .req x15 > SYM_FUNC_START(__arch_copy_from_user) > add end, x0, x2 > + mov srcin, x1 > #include "copy_template.S" > mov x0, #0 // Nothing to copy > ret > @@ -63,6 +65,12 @@ EXPORT_SYMBOL(__arch_copy_from_user) > .section .fixup,"ax" > .align 2 > +9997: cmp dst, dstin > + b.ne 9998f > + // Before being absolutely sure we couldn't copy anything, try harder > +USER(9998f, ldtrb tmp1w, [srcin]) > + strb tmp1w, [dstin] > + add dst, dstin, #1 Nitpick: can we do just strb tmb1w, [dst], #1? It matches the strb1 macro in this file. Either way, it looks fine to me. Reviewed-by: Catalin Marinas _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel