Received: by 2002:a05:7412:b101:b0:e2:908c:2ebd with SMTP id az1csp2856215rdb; Wed, 15 Nov 2023 12:35:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IHHtQNBoH5gMK9Ka79+4ijoddPT50i2xl+2HN1OrsAvM3O5gcSsu/20uPQ8+qxkdhNdJ/XH X-Received: by 2002:a05:6a21:a59f:b0:186:2257:6228 with SMTP id gd31-20020a056a21a59f00b0018622576228mr16439108pzc.19.1700080528578; Wed, 15 Nov 2023 12:35:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700080528; cv=none; d=google.com; s=arc-20160816; b=VAxAGjqHhEC0xHPczTVXdnPlfshDDYiRbfaOHkfsVLRyo4YwLdM9dxiFOgA3yc8C3U t5tX7LwZzunc4N9b3U5CPgDUHdOFtITUY/rC/P0duqEGZWKo8E0k+X96UQxTPWQhvAXj nOcOBhSE7mel0nGtRg1NHjWtFypmvse7fW0XOkLc19DO48I4p6lk7O5bdLmZEQ3TUWfH 0LpHY8W7D4ksMgOpYEMBZeVeSHRLvgFycxKoNf7Sm1n8NwUWlj9GkTD871X2aiWvenup JwywGaCtum1ivKwGyewaIMJfhErKK4w8s1nf5Vezx+sjiEOzoYsIXCS4n3AcQGI+CRtK Ikzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=kILyw5cdgjGn5/bq6lT/7Km7hA/yuzYatpUTfjRHTeA=; fh=Mk/+hh3KXEiY642GJit3QcoQ60j/OUZTCvigu+jTRuo=; b=YuwA6EO/kcl75lAJmAf1IfKdYdIT4TgqyGj1tzgsnLqIzcV24UOdH1L4N95VsLH8V3 aFpnjRuU5iOVXtshHrkABfb0Rtm2pbVNSnQF/Fg68mJgkIGGVwAWRDbb0h3UXQWP79wl zokRUQsD9VVmK0QjZybf4OyGO7Lh9Y5j9DO+iopVt6QYZ4HUC/QheMVFWkc0Y5XxZp59 Q4nmSrCrHVf9t0j6ZKxDB8M2LNcjXYf0kDS4UWXycclu71hVzwTckX1bgFGB79sO19Hu m0eHmCSkbQTpOXxuS6yMxBf7JSLJbJRqrp9WClRqWMxjF3VcHy7yl7ojgm2dIsPIMybH JZbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=oL5sLjSW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id p3-20020a63e643000000b005b8ef498e2fsi10379449pgj.181.2023.11.15.12.35.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Nov 2023 12:35:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=oL5sLjSW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id EE82880BE2FB; Wed, 15 Nov 2023 12:35:26 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344554AbjKOUfS (ORCPT + 99 others); Wed, 15 Nov 2023 15:35:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56972 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344481AbjKOUe7 (ORCPT ); Wed, 15 Nov 2023 15:34:59 -0500 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7CC14172A; Wed, 15 Nov 2023 12:34:49 -0800 (PST) Received: from pps.filterd (m0360072.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3AFKTjqx023176; Wed, 15 Nov 2023 20:34:29 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=kILyw5cdgjGn5/bq6lT/7Km7hA/yuzYatpUTfjRHTeA=; b=oL5sLjSWmr/gtMhjJL7JzsK4iexVduc7Zh7DY0jvhRMY+K0caQw0xyf3M47BP55000EY DniyVGoEvJA48XvRTWtF2WsEojgnvAQq7zreNwFioenCxYH3w0r+3RFCjK0usz+tgcjf wmK5TSc0nPrYcmZW9zbOB+KU8YNhk+i0Xex4s/Id7HgguMNXCIW0ozL2OC0Lg85/phXi YStPxg7pDpBhWcFf9EQ3+xO7CXnQ8AQjtW6SnwCrP4QhBcMFgBqYTEIVsDNLD9HVSBXb OYSDQx2u2fD0d+xOSqEbzxUwTg2nDOgeSpQNLnckhB4GU3euu/GCkGr5aiIZrjTzGBip Iw== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3ud52r846v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 15 Nov 2023 20:34:28 +0000 Received: from m0360072.ppops.net (m0360072.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 3AFKTkn4023256; Wed, 15 Nov 2023 20:34:28 GMT Received: from ppma11.dal12v.mail.ibm.com (db.9e.1632.ip4.static.sl-reverse.com [50.22.158.219]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3ud52r846e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 15 Nov 2023 20:34:27 +0000 Received: from pps.filterd (ppma11.dal12v.mail.ibm.com [127.0.0.1]) by ppma11.dal12v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 3AFKJ0V7024857; Wed, 15 Nov 2023 20:34:26 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 3uapn1sj5e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 15 Nov 2023 20:34:26 +0000 Received: from smtpav01.fra02v.mail.ibm.com (smtpav01.fra02v.mail.ibm.com [10.20.54.100]) by smtprelay04.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 3AFKYOMw40894804 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 15 Nov 2023 20:34:24 GMT Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 039E820043; Wed, 15 Nov 2023 20:34:24 +0000 (GMT) Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A8BF620040; Wed, 15 Nov 2023 20:34:22 +0000 (GMT) Received: from heavy.boeblingen.de.ibm.com (unknown [9.179.9.51]) by smtpav01.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 15 Nov 2023 20:34:22 +0000 (GMT) From: Ilya Leoshkevich To: Alexander Gordeev , Alexander Potapenko , Andrew Morton , Christoph Lameter , David Rientjes , 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 09/32] kmsan: Introduce kmsan_memmove_metadata() Date: Wed, 15 Nov 2023 21:30:41 +0100 Message-ID: <20231115203401.2495875-10-iii@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231115203401.2495875-1-iii@linux.ibm.com> References: <20231115203401.2495875-1-iii@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-GUID: _DluWkg_or4n634NGc6XmkFZtcUvSsfY X-Proofpoint-ORIG-GUID: 4Wi2DjioGwv31onDtsbO8JdqEX7Bd4Hn X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.987,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-11-15_20,2023-11-15_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 impostorscore=0 lowpriorityscore=0 adultscore=0 clxscore=1015 priorityscore=1501 mlxscore=0 phishscore=0 spamscore=0 mlxlogscore=999 suspectscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311060000 definitions=main-2311150163 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 15 Nov 2023 12:35:27 -0800 (PST) It is useful to manually copy metadata in order to describe the effects of memmove()-like logic in uninstrumented code or inline asm. Introduce kmsan_memmove_metadata() for this purpose. Signed-off-by: Ilya Leoshkevich --- include/linux/kmsan-checks.h | 14 ++++++++++++++ mm/kmsan/hooks.c | 11 +++++++++++ 2 files changed, 25 insertions(+) diff --git a/include/linux/kmsan-checks.h b/include/linux/kmsan-checks.h index c4cae333deec..5218973f0ad0 100644 --- a/include/linux/kmsan-checks.h +++ b/include/linux/kmsan-checks.h @@ -61,6 +61,17 @@ void kmsan_check_memory(const void *address, size_t size); void kmsan_copy_to_user(void __user *to, const void *from, size_t to_copy, size_t left); +/** + * kmsan_memmove_metadata() - Copy kernel memory range metadata. + * @dst: start of the destination kernel memory range. + * @src: start of the source kernel memory range. + * @n: size of the memory ranges. + * + * KMSAN will treat the destination range as if its contents were memmove()d + * from the source range. + */ +void kmsan_memmove_metadata(void *dst, const void *src, size_t n); + #else static inline void kmsan_poison_memory(const void *address, size_t size, @@ -77,6 +88,9 @@ static inline void kmsan_copy_to_user(void __user *to, const void *from, size_t to_copy, size_t left) { } +static inline void kmsan_memmove_metadata(void *dst, const void *src, size_t n) +{ +} #endif diff --git a/mm/kmsan/hooks.c b/mm/kmsan/hooks.c index eafc45f937eb..4d477a0a356c 100644 --- a/mm/kmsan/hooks.c +++ b/mm/kmsan/hooks.c @@ -286,6 +286,17 @@ void kmsan_copy_to_user(void __user *to, const void *from, size_t to_copy, } EXPORT_SYMBOL(kmsan_copy_to_user); +void kmsan_memmove_metadata(void *dst, const void *src, size_t n) +{ + if (!kmsan_enabled || kmsan_in_runtime()) + return; + + kmsan_enter_runtime(); + kmsan_internal_memmove_metadata(dst, (void *)src, n); + kmsan_leave_runtime(); +} +EXPORT_SYMBOL(kmsan_memmove_metadata); + /* Helper function to check an URB. */ void kmsan_handle_urb(const struct urb *urb, bool is_out) { -- 2.41.0