From patchwork Fri Jun 21 11:35:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Leoshkevich X-Patchwork-Id: 13707344 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 E8828C27C4F for ; Fri, 21 Jun 2024 11:38:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E97DE8D0160; Fri, 21 Jun 2024 07:37:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E21B28D0163; Fri, 21 Jun 2024 07:37:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C22EF8D0160; Fri, 21 Jun 2024 07:37:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 9119D8D0163 for ; Fri, 21 Jun 2024 07:37:44 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 5DA6A1A0DE6 for ; Fri, 21 Jun 2024 11:37:44 +0000 (UTC) X-FDA: 82254696048.23.77B249E Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by imf18.hostedemail.com (Postfix) with ESMTP id 20E701C000E for ; Fri, 21 Jun 2024 11:37:41 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=aYXtoMYb; dmarc=pass (policy=none) header.from=ibm.com; spf=pass (imf18.hostedemail.com: domain of iii@linux.ibm.com designates 148.163.158.5 as permitted sender) smtp.mailfrom=iii@linux.ibm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718969854; a=rsa-sha256; cv=none; b=oNyHucFqlc53+hvj2nqEaZ7N2FpPVX2S9BWc/HJO2dhZbrhAJAKolKB48FoZ0dpX+TZBqs PWslypPj+WZcm3IO/Qp2ksuW0sD3tuMlmJVgGcPy53grTeqS6O76sZIdFUscM091ym83wN T6MzgGFbViF4eIWPbihDTjQvQbNpfe4= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=aYXtoMYb; dmarc=pass (policy=none) header.from=ibm.com; spf=pass (imf18.hostedemail.com: domain of iii@linux.ibm.com designates 148.163.158.5 as permitted sender) smtp.mailfrom=iii@linux.ibm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1718969854; 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=N4eruTEOLAVkIlkU/S6xQTMHDZMmtMhtRMBCfBh/gGtPq4QMN6BKc6zDj++VruzT+ZtCIp 6XifJwEjRkvsUuLiE4TDHBFCfKFgNo3UTLnYmoeQDi2EEc2lyPumMO8JwBYS3JGSNZuZoi bGRqRoeQ5qTlvOHIBt+ws/oCt+ApdFo= Received: from pps.filterd (m0353724.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 45LAoUL6014184; Fri, 21 Jun 2024 11:37:36 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=aYXtoMYbe4ekJIpkZtshNGmrQ6X8P UbBp/BljzbxZCdVdMQt9qhCP+Ypn/RoUcw1lQV8kFAiKPexaQgb9A/CZDJuoq+Hv 85BsDXb6gD2XLeAvY0tNddxCXnCIJtuyAKSSuGiSo3zY+TccZGsUgW09105F7d53 EFOqispB0NPA+I1RZmgElnZjXwLnfI6MJU799olTfwDPLf9DwB7a2nXfYpAjy7Lh 4SoFNnGqGT4TPK+ky9RHoxnxxxEA/3lDY7PoUjfUGs7gF5dkPFiqZYAlPP0UxNmI o6BgjwaiPDHk/SeMLEtZ3e+9LJEEBfNbMutGdGyAH86DEOf7kfEhc3C4w== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3yw7t5046c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 21 Jun 2024 11:37:36 +0000 (GMT) Received: from m0353724.ppops.net (m0353724.ppops.net [127.0.0.1]) by pps.reinject (8.18.0.8/8.18.0.8) with ESMTP id 45LBbZ56017560; Fri, 21 Jun 2024 11:37:35 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 3yw7t50469-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 21 Jun 2024 11:37:35 +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 45L9Lx4G030885; Fri, 21 Jun 2024 11:37:34 GMT Received: from smtprelay01.fra02v.mail.ibm.com ([9.218.2.227]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3yvrssxvbw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 21 Jun 2024 11:37:34 +0000 Received: from smtpav01.fra02v.mail.ibm.com (smtpav01.fra02v.mail.ibm.com [10.20.54.100]) by smtprelay01.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 45LBbSjg49676548 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Jun 2024 11:37:30 GMT Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B14842004E; Fri, 21 Jun 2024 11:37:28 +0000 (GMT) Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 27B452004D; Fri, 21 Jun 2024 11:37:28 +0000 (GMT) Received: from black.boeblingen.de.ibm.com (unknown [9.155.200.166]) by smtpav01.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 21 Jun 2024 11:37:28 +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 v7 32/38] s390/string: Add KMSAN support Date: Fri, 21 Jun 2024 13:35:16 +0200 Message-ID: <20240621113706.315500-33-iii@linux.ibm.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240621113706.315500-1-iii@linux.ibm.com> References: <20240621113706.315500-1-iii@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: 3PFulpmb0GyW_EvRMDVFj7MrXJtxbV1X X-Proofpoint-GUID: XQwQMTK_IdbRjv4p0bY5Pn4_ph8BXBKO 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-21_04,2024-06-21_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 malwarescore=0 phishscore=0 clxscore=1015 priorityscore=1501 impostorscore=0 mlxlogscore=999 suspectscore=0 mlxscore=0 adultscore=0 bulkscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2406140001 definitions=main-2406210084 X-Rspamd-Queue-Id: 20E701C000E X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: ohrui1tmednxhs4w5mcfd1t6rhgusku8 X-HE-Tag: 1718969861-468069 X-HE-Meta: U2FsdGVkX18BQutw81A3Cavce+J7yXO/bxfOvu0JgX76mjxMKDkk6EQXhaa61lD9qQWKyBVbNbDuKE4oW7N7FkHQeqjLwmAbd+M4vGL94tSeO64lm41DyG7oAueE8Y5nuW+4AvaV0cnA+w+ZWMizSe0CmW7DXc2BzycsP4JonyNITH2Mk3pCB4PSEBFgtVl7rFPsobmYGnK8b6unoa9zluDP2S/4FtrHHOcC6CnJDQAavKvuvSRKdJnGWymX1TXrOL77owpYmqaNvgmUDaXHKFMH2E6pBvuegPzasPKCcNqzd1l470RO4ag42MihbFChrxfKZSh3dUEnWz6/jjdDinIdI/DKYeb+RIj3AGo9QaId9Chjr5vc6ux5b5rINm6iB4YvhB5Gr79jYCch5D8J2ShiO8X3oxjMt7DvTo45jrV0afuiQSiH4WCpyruPtoss3JTKvt6AZLAvfKfhdCv5d6TVvp5M3B6SVVVXsaREiECULv9JmrRILwKU2Sm7QLu4tJy0QiErY6F/jKNsOfao636/cnPatPiGCyAmr2x/a5R+pqIBqfZPVdmBlwseNEHRx5iCvyGC2sgwoiQL243bCHNcBw6WH4DESWGCTv3X1r22JxhjsH+mII9CVKV4FhochDDYZhzuBWcZDr8kaiplaY/X7QPxuuo9lIVGlxQ+TPNfpR/CR02M1Za8P1O0zy7oCsiDu5o05ywYkMeCfsvnDJ3hj6MEA8vzTIfkYRMh5SaT3N5Pj0BU1GXIejV9lB5sFxO/mnMM9HCG5DVH0aXQvnl5KIfGWbGE0SiDb9JjWLS1+cjyyCgzh2yuUeuZ+WLea73N/kGrH3tpGx1+N+Lfv5UqTUWqpJFquDJrAjjacujrmtA2ywM7zmvGm/jSxGkph75hen1ettVbCzYdkLkkxklO+2X1S90IY6WeEYbK13r0oNHaNgwKuIpcvyCuAxVfS+n9r0GaV9D/HTtsXAc fNrf3z5R 61NUoUA6CQlC1AtEXjFFsOFTU3n537Qgv4lxAa4ajl7owXQCByf1AIlsH4rDyaGKsRvVEMS3mEvP0N7AvLOwOh68bwLXPGe0UVgCpW6ehSV5nOH1Bx2f3U0y2Lk4HseppMHW3/uN8dRWd4phkdCa17H0G6lhdtvMW8mpBBp5BDxlCdR2/9RNOMqH6wMYI1XQdUtpX5hn5V7SWLQn6r+/MnFEm2U7Yfu1CM3GGR3UuJzoC8LO5nBcwHbwKWEucprqee6Pn0H2uGQzLkeZ+spuXTHxEgDTc6B3eF/qUDeJ4uy74044crRvC+BAfTz9KuKdcC8URr+i3R+2ze3J1z7kO3IIZ4cbuK4+U8Fk2 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))