From patchwork Mon Nov 14 11:43:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Slaby X-Patchwork-Id: 13042175 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2922AC433FE for ; Mon, 14 Nov 2022 11:45:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A7D046B0073; Mon, 14 Nov 2022 06:45:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A2C736B0074; Mon, 14 Nov 2022 06:45:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8F56E6B0075; Mon, 14 Nov 2022 06:45:42 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 80CC16B0073 for ; Mon, 14 Nov 2022 06:45:42 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 5C4061C6654 for ; Mon, 14 Nov 2022 11:45:42 +0000 (UTC) X-FDA: 80131868124.02.F9486A7 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf08.hostedemail.com (Postfix) with ESMTP id 011CA160006 for ; Mon, 14 Nov 2022 11:45:40 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 1983361090; Mon, 14 Nov 2022 11:45:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8E91DC43470; Mon, 14 Nov 2022 11:45:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1668426339; bh=88jaPx4iCX4zMvSz58mQ2Zj5p3k63uCxoL6FcunYz3s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ivICbmQi7wHzNyqcXXy2gBkoVBoBCTmkhvCzCikjByib4s8RaoY1lW4WmY9i9fJB5 fYZtyMMcxvFxBADEGFKQdsa3WruxjgLmBiWGmXivBeRy8kLTjLOmEAweToWxhQ6yz+ x0LdG1T+pvu8StRDeYlGH0Tdyy/ePWCQ/Sv+rDu7l45RUSDts6OddVrDlDVLJAdfl8 +GmcClU8zPprpmtMhRrIPMLXfJ8PvLzwBu49jJzmOaY+cmjBFdgkwJ1Rc5viBYm/GK /AbTQVDinVxn/OvJ40QkgSYd9IXHHQ9KE/H5v6KLBpoVlHLMGb92iJ1uONOwOTZGtC 5+9YnP17R7gUg== From: "Jiri Slaby (SUSE)" To: linux-kernel@vger.kernel.org Cc: Martin Liska , Andrey Ryabinin , Alexander Potapenko , Andrey Konovalov , Dmitry Vyukov , Vincenzo Frascino , Andrew Morton , kasan-dev@googlegroups.com, linux-mm@kvack.org, Jiri Slaby Subject: [PATCH 42/46] mm/kasan, lto: Mark kasan mem{cpy,move,set} as __used Date: Mon, 14 Nov 2022 12:43:40 +0100 Message-Id: <20221114114344.18650-43-jirislaby@kernel.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221114114344.18650-1-jirislaby@kernel.org> References: <20221114114344.18650-1-jirislaby@kernel.org> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1668426341; a=rsa-sha256; cv=none; b=LqLB18ED6L0JWCRWZ+L7ligMxBilhcS7M2LqAFthyetHTBljUPegKHUCaGwqzqRNy6d319 k5kMk3Xavf2CKNNVnzdPc7LflO/NmUcVquAFABWsjr1MfIWfQrmY0TsFkViGg1R28s+x6S LrKJ10/wWqPLJ58WC9b8gZ5e5tcWVOk= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=ivICbmQi; spf=pass (imf08.hostedemail.com: domain of jirislaby@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=jirislaby@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1668426341; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=BfbFJP9xIxthF4S61VznWCy99JUkc3m8GUdJ+Jei+2g=; b=7Pr1QTs67s4sHY3PojHHb5tHaxG7tloTK314Y84CVZfzHNP4MfZCmgHP8nVvl/NgLxcemO N/eU/uhtwFP9sOO+zOF08W1K+8nYoi2gPVOH1LhB0cJ7CiTgEON9/0QbyryNTELyor5zIZ 2UV/wobVBUFC1Z7tfZqDavB1DDB6riE= X-Stat-Signature: jkohn1bq6ky5a3knna1csuakbwsznqqe Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=ivICbmQi; spf=pass (imf08.hostedemail.com: domain of jirislaby@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=jirislaby@kernel.org; dmarc=pass (policy=none) header.from=kernel.org X-Rspamd-Server: rspam10 X-Rspam-User: X-Rspamd-Queue-Id: 011CA160006 X-HE-Tag: 1668426340-380167 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Martin Liska gcc doesn't always recognize that memcpy/set/move called through __builtins are referenced because the reference happens too late in the RTL expansion phase. This can make LTO to drop them, leading to undefined symbols. Mark them as __used to avoid that. Cc: Andrey Ryabinin Cc: Alexander Potapenko Cc: Andrey Konovalov Cc: Dmitry Vyukov Cc: Vincenzo Frascino Cc: Andrew Morton Cc: kasan-dev@googlegroups.com Cc: linux-mm@kvack.org Signed-off-by: Martin Liska Signed-off-by: Jiri Slaby --- mm/kasan/shadow.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mm/kasan/shadow.c b/mm/kasan/shadow.c index 0e3648b603a6..94c98feea9c8 100644 --- a/mm/kasan/shadow.c +++ b/mm/kasan/shadow.c @@ -39,7 +39,7 @@ bool __kasan_check_write(const volatile void *p, unsigned int size) EXPORT_SYMBOL(__kasan_check_write); #undef memset -void *memset(void *addr, int c, size_t len) +__used void *memset(void *addr, int c, size_t len) { if (!kasan_check_range((unsigned long)addr, len, true, _RET_IP_)) return NULL; @@ -49,7 +49,7 @@ void *memset(void *addr, int c, size_t len) #ifdef __HAVE_ARCH_MEMMOVE #undef memmove -void *memmove(void *dest, const void *src, size_t len) +__used void *memmove(void *dest, const void *src, size_t len) { if (!kasan_check_range((unsigned long)src, len, false, _RET_IP_) || !kasan_check_range((unsigned long)dest, len, true, _RET_IP_)) @@ -60,7 +60,7 @@ void *memmove(void *dest, const void *src, size_t len) #endif #undef memcpy -void *memcpy(void *dest, const void *src, size_t len) +__used void *memcpy(void *dest, const void *src, size_t len) { if (!kasan_check_range((unsigned long)src, len, false, _RET_IP_) || !kasan_check_range((unsigned long)dest, len, true, _RET_IP_)) From patchwork Mon Nov 14 11:43:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Slaby X-Patchwork-Id: 13042176 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D7253C4332F for ; Mon, 14 Nov 2022 11:45:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 610CD6B0074; Mon, 14 Nov 2022 06:45:51 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5BF946B0075; Mon, 14 Nov 2022 06:45:51 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 488456B0078; Mon, 14 Nov 2022 06:45:51 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 3AD746B0074 for ; Mon, 14 Nov 2022 06:45:51 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id EE4B840646 for ; Mon, 14 Nov 2022 11:45:50 +0000 (UTC) X-FDA: 80131868460.07.343860D Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf10.hostedemail.com (Postfix) with ESMTP id 79F0DC0004 for ; Mon, 14 Nov 2022 11:45:50 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 8B09BB80E78; Mon, 14 Nov 2022 11:45:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E18D3C433B5; Mon, 14 Nov 2022 11:45:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1668426347; bh=Vp8sXRjsUE/N3VsCm0HTjAxgxp+yKdf3km9PrguLdDQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EFbgopP7Xnz3OCxeyZ9dcO7w77PdM+IjWJR+aVFwRb07CIksjaoVGfWRstf783N3H E9KmA6woJ2FGqfK90S6TJFAAg5qqUMfIZnpNnD41beNsjEwz7rSxXUrO/OrMHRPSV3 kDGkTCXO58rfI0ilFhyev9a6eZAWQ4x6BDFE2vqHEpHf0eHS/AIvBpS/g2iCLWeQCw tuPzy3sFNcoiPdUxzbGfFS2cjgRdxlor4gHE27/K7pGeaQwOwKcjJnL6WF/8Y/rjRI BS2gkGyi1GVd1B+Xzolmhmm9kcReS83I2v/sHxf4/uIXfQZgFX5WQhRWeZYl4WEm3q I0gUgpxAvcQJw== From: "Jiri Slaby (SUSE)" To: linux-kernel@vger.kernel.org Cc: Martin Liska , Andrey Ryabinin , Alexander Potapenko , Andrey Konovalov , Dmitry Vyukov , Vincenzo Frascino , Andrew Morton , kasan-dev@googlegroups.com, linux-mm@kvack.org, Jiri Slaby Subject: [PATCH 45/46] kasan, lto: remove extra BUILD_BUG() in memory_is_poisoned Date: Mon, 14 Nov 2022 12:43:43 +0100 Message-Id: <20221114114344.18650-46-jirislaby@kernel.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221114114344.18650-1-jirislaby@kernel.org> References: <20221114114344.18650-1-jirislaby@kernel.org> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1668426350; a=rsa-sha256; cv=none; b=UmBaI43+wADf1nwxn8V7b8SfjRrYWVpyqxfrgGX0tCzXbBop5gdUslt9a9QkfQAw4x9wCN fEDSxuu7bWnEv8vNEJ7RXUE+R6OfrvnLhwLk+PBcTD5w51mimIJ+bseZtlEoXyOsp/Zdp9 v3/3X5G6nHRrxNgFPrq4IcPAQmXUI50= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=EFbgopP7; spf=pass (imf10.hostedemail.com: domain of jirislaby@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=jirislaby@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1668426350; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=WKn9laZEOJi3RLi6Cjh54rnSbYfEE4oIQi1+zqu/7Pw=; b=NtSH1coMrT33kn5lkTG8o4o4nz8hXzRcltO/CGQtGxaPsVd26okc+czfUBmnF6oT677cjt 2x35NM9GAULOcs7pCtsuZ2gIEPtErw+lvjyZcjSsbgb78GzvWCszm/FR88R/AiSxyY2AAh 1b5cacxuvXUadGF73naYiJDZwSWWDxo= X-Rspam-User: X-Stat-Signature: ohg1w1bu4j53yj1qgem67oe99fo5c5d1 X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 79F0DC0004 Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=EFbgopP7; spf=pass (imf10.hostedemail.com: domain of jirislaby@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=jirislaby@kernel.org; dmarc=pass (policy=none) header.from=kernel.org X-HE-Tag: 1668426350-889250 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Martin Liska The function memory_is_poisoned() can handle any size which can be propagated by LTO later on. So we can end up with a constant that is not handled in the switch. Thus just break and call memory_is_poisoned_n() which handles arbitrary size to avoid build errors with gcc LTO. Cc: Andrey Ryabinin Cc: Alexander Potapenko Cc: Andrey Konovalov Cc: Dmitry Vyukov Cc: Vincenzo Frascino Cc: Andrew Morton Cc: kasan-dev@googlegroups.com Cc: linux-mm@kvack.org Signed-off-by: Martin Liska Signed-off-by: Jiri Slaby Reviewed-by: Andrey Konovalov --- mm/kasan/generic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/kasan/generic.c b/mm/kasan/generic.c index d8b5590f9484..d261f83c6687 100644 --- a/mm/kasan/generic.c +++ b/mm/kasan/generic.c @@ -152,7 +152,7 @@ static __always_inline bool memory_is_poisoned(unsigned long addr, size_t size) case 16: return memory_is_poisoned_16(addr); default: - BUILD_BUG(); + break; } }