From patchwork Wed Feb 15 02:37:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zev Weiss X-Patchwork-Id: 13141233 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 5320AC05027 for ; Wed, 15 Feb 2023 02:38:26 +0000 (UTC) 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:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=V5ksiR/Ruadg6w0nFUpHSvM1CRXCZ7n4XwOpTEP2pN4=; b=AxzxeZrjKrmhmi YCy3vRcz6g1MwEQSP+pUVx1j00wd/uIml4iaLAOfZ7fuvVsBH15q5KhfoIMQ3Ls6XSrAhCgxoOecu E1CV9uXFThxpfsRrEHbg4sdPLoDKE0gXwo7ExRvvx4k0cAW9FEfNcZ9jOCVx2TxusapN1xoqZXUxc tc09qEXKcp3V8Qls0AdIU8fXoWYKky06jhNeOrtkcS984wVkKSCbysc6oXfr6Hbj4GhI+XfRDeId8 +96Pam9cxPsySix7wHBTZwOuC8S8KNGpbAI8oDk4elpcq8aQMMPiYkXkSmRT67hfvx94xq2LnvEVU vl+MnFu9BxYAUfS2tU9A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pS7fg-004PHl-GO; Wed, 15 Feb 2023 02:37:24 +0000 Received: from thorn.bewilderbeest.net ([71.19.156.171]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pS7fc-004PGK-Pr for linux-arm-kernel@lists.infradead.org; Wed, 15 Feb 2023 02:37:22 +0000 Received: from hatter.bewilderbeest.net (97-113-250-99.tukw.qwest.net [97.113.250.99]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: zev) by thorn.bewilderbeest.net (Postfix) with ESMTPSA id 78EE282; Tue, 14 Feb 2023 18:37:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bewilderbeest.net; s=thorn; t=1676428634; bh=af7ZZHxNFz5At1W5VcQd3z15hu8uNlmxF78QrinEHLI=; h=From:To:Cc:Subject:Date:From; b=aVyUaHtFSzNtr/mVZp/EHscaR1r95cK7AjlOCc9sNAt9p8qVaYnmXFEQc/tAuZowX OXyz7xek75iLOswKPlM/KLEzQWnwGsMr/vpMg6bjijNcZOJHPJcCZCsnIRL5EBxSAm zrhKoelBh0PmjI65azTNbBFdAqafW5/3ALNUHS0Q= From: Zev Weiss To: linux-arm-kernel@lists.infradead.org, kasan-dev@googlegroups.com Cc: Andrew Jeffery , Anshuman Khandual , Arnd Bergmann , Dinh Nguyen , Russell King , Sam Ravnborg , Stafford Horne , Zev Weiss , linux-kernel@vger.kernel.org, openbmc@lists.ozlabs.org, Andrey Ryabinin , Alexander Potapenko , Andrey Konovalov , Dmitry Vyukov , Vincenzo Frascino Subject: [PATCH] ARM: uaccess: Fix KASAN false-positives Date: Tue, 14 Feb 2023 18:37:06 -0800 Message-Id: <20230215023706.19453-1-zev@bewilderbeest.net> X-Mailer: git-send-email 2.39.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230214_183720_859846_28A1B329 X-CRM114-Status: GOOD ( 10.66 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Andrew Jeffery __copy_to_user_memcpy() and __clear_user_memset() had been calling memcpy() and memset() respectively, leading to false-positive KASAN reports when starting userspace: [ 10.707901] Run /init as init process [ 10.731892] process '/bin/busybox' started with executable stack [ 10.745234] ================================================================== [ 10.745796] BUG: KASAN: user-memory-access in __clear_user_memset+0x258/0x3ac [ 10.747260] Write of size 2687 at addr 000de581 by task init/1 Use __memcpy() and __memset() instead to allow userspace access, which is of course the intent of these functions. Signed-off-by: Andrew Jeffery Signed-off-by: Zev Weiss Reviewed-by: Arnd Bergmann --- arch/arm/lib/uaccess_with_memcpy.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c index 14eecaaf295f..e4c2677cc1e9 100644 --- a/arch/arm/lib/uaccess_with_memcpy.c +++ b/arch/arm/lib/uaccess_with_memcpy.c @@ -116,7 +116,7 @@ __copy_to_user_memcpy(void __user *to, const void *from, unsigned long n) tocopy = n; ua_flags = uaccess_save_and_enable(); - memcpy((void *)to, from, tocopy); + __memcpy((void *)to, from, tocopy); uaccess_restore(ua_flags); to += tocopy; from += tocopy; @@ -178,7 +178,7 @@ __clear_user_memset(void __user *addr, unsigned long n) tocopy = n; ua_flags = uaccess_save_and_enable(); - memset((void *)addr, 0, tocopy); + __memset((void *)addr, 0, tocopy); uaccess_restore(ua_flags); addr += tocopy; n -= tocopy;