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=-4.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=no 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 788EEC433F5 for ; Fri, 10 Sep 2021 11:39:39 +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 3F682611C0 for ; Fri, 10 Sep 2021 11:39:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 3F682611C0 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=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=Jx4P3BEHUmLNe03EsqfYmRH+sD83e3O2vQ3J4eEemko=; b=Bhds2BMiV7C8H9 ubrY2WK+g+PokEntRfO0UN0UdkT4wtnq+bbS5qku1GRY0pBqlZiy0qJYuo282ZwvUQ4Lo33yU8PY/ LXL9EnytIh1VpAu1rm0SEG57GjZun0sLa1V7nPQv6ay2l8bMdOCZweEIR8ECaefdcW9xK7boWnv4a MAr0ePC1+ur4CiIQVzChSbodBHdCDSfNTGS1C3ZSSYb5gKtTCUVMKeeT2IELjifftxY0OJs4TuBa0 jdYq0fc3E5L5LBRbpw4lGQNu9tC3UcuF0BDHYVDCzwCPeW9ub14G9IEWFXlx1sw2wyfcAb84VSkRD Vb+TkVbDwx+i2EXOv/9g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mOepf-00CdAd-Ao; Fri, 10 Sep 2021 11:36:35 +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 1mOepb-00CdAD-VH for linux-arm-kernel@lists.infradead.org; Fri, 10 Sep 2021 11:36:33 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2B77B61100; Fri, 10 Sep 2021 11:36:30 +0000 (UTC) Date: Fri, 10 Sep 2021 12:36:26 +0100 From: Catalin Marinas To: Peter Collingbourne Cc: Robin Murphy , Will Deacon , Linux ARM , Mark Rutland , Evgenii Stepanov , Alexander Potapenko , Andrey Konovalov Subject: Re: [PATCH v2 6/8] arm64: Import latest memcpy()/memmove() implementation Message-ID: References: <3c953af43506581b2422f61952261e76949ba711.1622128527.git.robin.murphy@arm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210910_043632_067561_24096BFF X-CRM114-Status: GOOD ( 24.94 ) 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 Hi Peter, On Thu, Sep 09, 2021 at 05:35:54PM -0700, Peter Collingbourne wrote: > (apologies for breaking the threading, I wasn't subscribed to > linux-arm-kernel when you sent this) lore.kernel.org has some instructions on how to download the message and reply to it. > It looks like this patch breaks the KASAN unit tests when running in > HW tags mode. You can construct a config that reproduces the problem > with something like: > > make O=out defconfig > scripts/config --file out/.config -e CONFIG_KUNIT -e CONFIG_KASAN -e > CONFIG_KASAN_HW_TAGS -e CONFIG_KASAN_KUNIT_TEST > yes '' | make O=out syncconfig > > With that the "kmalloc_memmove_invalid_size" test fails and causes the > kernel panic below. > > What appears to be going on is that whereas the old memcpy > implementation ends up returning early after not copying very much > data if supplied a "negative" size as a side effect of using > conditional branches that implement signed comparisons (e.g. b.ge on > line 75), the new implementation does not exit early and attempts to > copy a large amount of data backwards 4 bytes (after having disabled > MTE early on as a result of a tag mismatch) until it hits a read-only > page and causes a panic. Treating the size argument as unsigned long is the correct way, it matches the function prototype. > I'm not sure what the correct fix should be. It seems that at least > when KASAN is enabled we should be able to catch these invalid memcpys > somehow, print an error report and ideally abort the entire operation. > But we should do so without causing a performance impact in the usual > case. I'm not convinced that's a valid test. Do we have any statement somewhere on what a valid size for memmove/memcpy is? We could artificially limit it to VA_BITS or even to 63 bits so that it stays a positive number but the generic memmove() implementation doesn't do such checks either. Since the memcpy/memmove routines don't have a fail-safe mode, the only thing the kernel can do on an MTE fault is to disable tag checking, report it and continue. What you need instead is copy_*_kernel_nofault in the kasan tests as they return the number of bytes copied. My suggestion for a quick fix would be to remove the kasan test. -- Catalin _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel