From patchwork Fri Jun 21 00:25:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Leoshkevich X-Patchwork-Id: 13706634 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 AA1BAC2BA18 for ; Fri, 21 Jun 2024 00:39:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 358DB8D0110; Thu, 20 Jun 2024 20:39:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 307CA8D0108; Thu, 20 Jun 2024 20:39:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1A8B18D0110; Thu, 20 Jun 2024 20:39:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id EE5548D0108 for ; Thu, 20 Jun 2024 20:39:34 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 726E71602C5 for ; Fri, 21 Jun 2024 00:39:34 +0000 (UTC) X-FDA: 82253037468.14.E177A38 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by imf19.hostedemail.com (Postfix) with ESMTP id 413861A000F for ; Fri, 21 Jun 2024 00:39:32 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=jiBtDJef; spf=pass (imf19.hostedemail.com: domain of iii@linux.ibm.com designates 148.163.158.5 as permitted sender) smtp.mailfrom=iii@linux.ibm.com; dmarc=pass (policy=none) header.from=ibm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1718930362; 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=twgTpfHCjImRnKDbwT1fFnn3UXy6li/j6Qe1IMbE5zU=; b=5cNcIrctV1PyV7XEqv6oe3MQYDe7YXHTFqdEX2LJCAftbSbnbsnOT/Hxj7K71TujfCokuS URxrxpwEWJVpuFQ14VzQwHj9ueIyiVGfCOtAeDno/JHWMmj/szfjCd7YOjj3EXD/wurCRW ouYfDLJZtH8MouG++rRiFAnhg1Lu5OA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718930362; a=rsa-sha256; cv=none; b=n1y45iXdV8W0Lfcf2UD2oPHo8uIl7O+vCCQtHaff2oyLktq3jxsgvCDn1aSyIESwNO0VTL gbY7Cppdrvd6/afRNnHn6itByeo6p2JeseCXgMXI9Jq5RqwSNaEquJYgD0Ju5hUjajwI4x ws/aBCtohTR270+l93cUATGpVffeb3E= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=jiBtDJef; spf=pass (imf19.hostedemail.com: domain of iii@linux.ibm.com designates 148.163.158.5 as permitted sender) smtp.mailfrom=iii@linux.ibm.com; dmarc=pass (policy=none) header.from=ibm.com Received: from pps.filterd (m0353723.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 45L0R8Nr030442; Fri, 21 Jun 2024 00:27:08 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=pp1; bh=twgTpfHCjImRn KDbwT1fFnn3UXy6li/j6Qe1IMbE5zU=; b=jiBtDJefwSZ0adJcvj47iUoK2awHM ZRkLbMucF/4MbIjhPN/tzA/AH6d3ETPaAkD4jGiOWaRJ9/FgLRvEAggS8HiGxzcs h5gdgas8/h3szis7aJDEpXWdjkNrSLCgFnZDRFr/cPsNcyDG7z3bEGU4Jzp76+Kh 9NpH+dF05JLKb+Mvi7pG5M5XhD3IvPC5EjG39FM0QolK+Jm1qBWESpu6L6bdWLm8 G9FuasFsRjjkmXCpX7w4YKMCehVcKxRYHtXGiHf7bcx5sCGPnkxGU50Ao92RqvEA tTCqQA5NE0vO+t9+9OsIzbGxS0l+tyu+fZh2L07QL2YM+evsdwpjF9L+w== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3yvw8m05k6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 21 Jun 2024 00:27:07 +0000 (GMT) Received: from m0353723.ppops.net (m0353723.ppops.net [127.0.0.1]) by pps.reinject (8.18.0.8/8.18.0.8) with ESMTP id 45L0R7Kj030413; Fri, 21 Jun 2024 00:27:07 GMT Received: from ppma22.wdc07v.mail.ibm.com (5c.69.3da9.ip4.static.sl-reverse.com [169.61.105.92]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3yvw8m05k1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 21 Jun 2024 00:27:07 +0000 (GMT) Received: from pps.filterd (ppma22.wdc07v.mail.ibm.com [127.0.0.1]) by ppma22.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 45L0Mhnu030888; Fri, 21 Jun 2024 00:27:06 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3yvrsstn43-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 21 Jun 2024 00:27:06 +0000 Received: from smtpav01.fra02v.mail.ibm.com (smtpav01.fra02v.mail.ibm.com [10.20.54.100]) by smtprelay03.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 45L0R0hd56689060 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Jun 2024 00:27:02 GMT Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6000820040; Fri, 21 Jun 2024 00:27:00 +0000 (GMT) Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 40E5D20043; Fri, 21 Jun 2024 00:26:59 +0000 (GMT) Received: from heavy.ibm.com (unknown [9.171.10.44]) by smtpav01.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 21 Jun 2024 00:26:59 +0000 (GMT) From: Ilya Leoshkevich To: Alexander Gordeev , Alexander Potapenko , Andrew Morton , Christoph Lameter , David Rientjes , Heiko Carstens , Joonsoo Kim , Marco Elver , Masami Hiramatsu , Pekka Enberg , Steven Rostedt , Vasily Gorbik , Vlastimil Babka Cc: Christian Borntraeger , Dmitry Vyukov , Hyeonggon Yoo <42.hyeyoo@gmail.com>, kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-s390@vger.kernel.org, linux-trace-kernel@vger.kernel.org, Mark Rutland , Roman Gushchin , Sven Schnelle , Ilya Leoshkevich Subject: [PATCH v6 33/39] s390/string: Add KMSAN support Date: Fri, 21 Jun 2024 02:25:07 +0200 Message-ID: <20240621002616.40684-34-iii@linux.ibm.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240621002616.40684-1-iii@linux.ibm.com> References: <20240621002616.40684-1-iii@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: DCrf_kw9F0ThMge5E2Hiq5L8_HHpB9Db X-Proofpoint-ORIG-GUID: 94o7KX1XsNd8aCWgl6SdTmdusc7KBk8Q X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-06-20_11,2024-06-20_04,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 priorityscore=1501 suspectscore=0 clxscore=1015 impostorscore=0 mlxscore=0 bulkscore=0 lowpriorityscore=0 spamscore=0 mlxlogscore=999 malwarescore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2406140001 definitions=main-2406210001 X-Stat-Signature: acfm1fk7r5gctuzjirrx4tbu3chaokpb X-Rspamd-Queue-Id: 413861A000F X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1718930372-789470 X-HE-Meta: U2FsdGVkX1+CdXh08nXtLLzNGrGRS6IPQOA7cLss7/3hf4wXLhitPGbbpKKCVhf94AokZcp1nh8vrlv2Uxn0HDbnMZMDwwU7AYQKY548edoX6YZZ6ejrl1ydhlGxYTIWKfCwAdI02/ydaXKt6ne9B/hWZyJMyfa2nwLYhtlpPbBcOhBYmIfDoIWuIndOWPLHh67OlorLoCwaeTcMNzYgV2gBPtYneyYR50I+GPUDj52D5ee3ecjL/cs4MbKLEn0OhaPGoInW/LO0m/XHEeoLhOmb0JodgRT9Zrw30yqfZwUMn4c013Xu1M+2pQkCoSKMMZh8vETAm1GOe+TOZO0wnudQz8Tmo62NcSD7pP3sJHi2NfdxYCNC+E9IjDoPnt+4M2dyJH8oEaPRwKCSGOQ25rS86VIFHO+/eGR09Kx/JvW9vncE9J/TwUB1+vk/JumClA9Cx2Lb1/NFlenNVtMIsw5480UeWQcFFg9cOVaXunmZ5c3x4N80wIzdXCQhCw061hBaSllkvjgcSfF5GcJRe/BVd251GaLyY9lJMEfZRuUZCD5ftIV6kpKrMAOlRcXPx4N2GamHSqk+JCbDUzNVgUC9xill6nLW0o29EEGx8AzNTbq0+IX18IpxPy26FhlJhxo1Zmn8LNHUQrYYmNWqZy/PMvMRR9954tGG36hqvVGPhPD8GfcsvS5RQ7dX6WJ4XCuFqg3WrxEcTejGOL9kRwDekK9xyW0r06LSrDoRK1gKSTRgQhW5vVq9RDJ+2lcC6xDwWf303dUIGeZ8xwKg9mgKtydz8PLtWI44mHRhDphq6LaLoMT3aUaSVLy6NWn3O7+ryW8B+/wgSOh0wYNR+tqMWozztZNpqcLqqqmhIiqX/OR7KX5YCyzxUIYpMAUdsv2epB60BpbWjS3b1QonPCfN0NHE9y71YGlLbQHcfKYbuT8xFC8XYfDbMlpx/RbMwNS5eIcTzFIUfZcvAUt ZI3dSQOc 4lspKhcdaxqW17tcdq4xKlQcii+Z+AiW8Jw7Xiuy9rHKtAOCTz+zly+CtQ/TIw76EmbU7/7nUe1UNW8/m3zPdLi0p8V0tU/eWVF12KVLLUhitbSlrgTsmhThyGUR9x9wDojJwX3nq2tvG0+GDh/u9d1zyU+F6S14SoCq3WAyxl4PU/HvnyS/c8pYpHHDN2A6ELf8eupTaBuShhHwiH2SBrDvpd1poFLeM9gMX8FSkTIPtF17OjxgaHZlVdT/WoDy72dYO/FB9AZySK02yt86jmKg79A== 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: List-Subscribe: List-Unsubscribe: Add KMSAN support for the s390 implementations of the string functions. Do this similar to how it's already done for KASAN, except that the optimized memset{16,32,64}() functions need to be disabled: it's important for KMSAN to know that they initialized something. The way boot code is built with regard to string functions is problematic, since most files think it's configured with sanitizers, but boot/string.c doesn't. This creates various problems with the memset64() definitions, depending on whether the code is built with sanitizers or fortify. This should probably be streamlined, but in the meantime resolve the issues by introducing the IN_BOOT_STRING_C macro, similar to the existing IN_ARCH_STRING_C macro. Reviewed-by: Alexander Potapenko Acked-by: Heiko Carstens Signed-off-by: Ilya Leoshkevich --- arch/s390/boot/string.c | 16 ++++++++++++++++ arch/s390/include/asm/string.h | 20 +++++++++++++++----- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/arch/s390/boot/string.c b/arch/s390/boot/string.c index faccb33b462c..f6b9b1df48a8 100644 --- a/arch/s390/boot/string.c +++ b/arch/s390/boot/string.c @@ -1,11 +1,18 @@ // SPDX-License-Identifier: GPL-2.0 +#define IN_BOOT_STRING_C 1 #include #include #include #undef CONFIG_KASAN #undef CONFIG_KASAN_GENERIC +#undef CONFIG_KMSAN #include "../lib/string.c" +/* + * Duplicate some functions from the common lib/string.c + * instead of fully including it. + */ + int strncmp(const char *cs, const char *ct, size_t count) { unsigned char c1, c2; @@ -22,6 +29,15 @@ int strncmp(const char *cs, const char *ct, size_t count) return 0; } +void *memset64(uint64_t *s, uint64_t v, size_t count) +{ + uint64_t *xs = s; + + while (count--) + *xs++ = v; + return s; +} + char *skip_spaces(const char *str) { while (isspace(*str)) diff --git a/arch/s390/include/asm/string.h b/arch/s390/include/asm/string.h index 351685de53d2..2ab868cbae6c 100644 --- a/arch/s390/include/asm/string.h +++ b/arch/s390/include/asm/string.h @@ -15,15 +15,12 @@ #define __HAVE_ARCH_MEMCPY /* gcc builtin & arch function */ #define __HAVE_ARCH_MEMMOVE /* gcc builtin & arch function */ #define __HAVE_ARCH_MEMSET /* gcc builtin & arch function */ -#define __HAVE_ARCH_MEMSET16 /* arch function */ -#define __HAVE_ARCH_MEMSET32 /* arch function */ -#define __HAVE_ARCH_MEMSET64 /* arch function */ void *memcpy(void *dest, const void *src, size_t n); void *memset(void *s, int c, size_t n); void *memmove(void *dest, const void *src, size_t n); -#ifndef CONFIG_KASAN +#if !defined(CONFIG_KASAN) && !defined(CONFIG_KMSAN) #define __HAVE_ARCH_MEMCHR /* inline & arch function */ #define __HAVE_ARCH_MEMCMP /* arch function */ #define __HAVE_ARCH_MEMSCAN /* inline & arch function */ @@ -36,6 +33,9 @@ void *memmove(void *dest, const void *src, size_t n); #define __HAVE_ARCH_STRNCPY /* arch function */ #define __HAVE_ARCH_STRNLEN /* inline & arch function */ #define __HAVE_ARCH_STRSTR /* arch function */ +#define __HAVE_ARCH_MEMSET16 /* arch function */ +#define __HAVE_ARCH_MEMSET32 /* arch function */ +#define __HAVE_ARCH_MEMSET64 /* arch function */ /* Prototypes for non-inlined arch strings functions. */ int memcmp(const void *s1, const void *s2, size_t n); @@ -44,7 +44,7 @@ size_t strlcat(char *dest, const char *src, size_t n); char *strncat(char *dest, const char *src, size_t n); char *strncpy(char *dest, const char *src, size_t n); char *strstr(const char *s1, const char *s2); -#endif /* !CONFIG_KASAN */ +#endif /* !defined(CONFIG_KASAN) && !defined(CONFIG_KMSAN) */ #undef __HAVE_ARCH_STRCHR #undef __HAVE_ARCH_STRNCHR @@ -74,20 +74,30 @@ void *__memset16(uint16_t *s, uint16_t v, size_t count); void *__memset32(uint32_t *s, uint32_t v, size_t count); void *__memset64(uint64_t *s, uint64_t v, size_t count); +#ifdef __HAVE_ARCH_MEMSET16 static inline void *memset16(uint16_t *s, uint16_t v, size_t count) { return __memset16(s, v, count * sizeof(v)); } +#endif +#ifdef __HAVE_ARCH_MEMSET32 static inline void *memset32(uint32_t *s, uint32_t v, size_t count) { return __memset32(s, v, count * sizeof(v)); } +#endif +#ifdef __HAVE_ARCH_MEMSET64 +#ifdef IN_BOOT_STRING_C +void *memset64(uint64_t *s, uint64_t v, size_t count); +#else static inline void *memset64(uint64_t *s, uint64_t v, size_t count) { return __memset64(s, v, count * sizeof(v)); } +#endif +#endif #if !defined(IN_ARCH_STRING_C) && (!defined(CONFIG_FORTIFY_SOURCE) || defined(__NO_FORTIFY))