Received: by 2002:ab2:620c:0:b0:1ef:ffd0:ce49 with SMTP id o12csp1412798lqt; Wed, 20 Mar 2024 03:19:05 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWTgRVh7t3FjvyoX4wql9onhS4pncqOf1AEGy4xvE3Te+U5aixA6VPdhPl1Jpe5I5bf7tpXwif4b1M7sy55eSntv3QciORqon7SvPQ82w== X-Google-Smtp-Source: AGHT+IE4lCRAJOfNDfCtMCh1grA2fKYclyYwBLvSEZ1YJveNceeFdJXUOLHINOA1h8F+9fC2kMaF X-Received: by 2002:ae9:e317:0:b0:788:2ada:3a3d with SMTP id v23-20020ae9e317000000b007882ada3a3dmr1310135qkf.24.1710929945562; Wed, 20 Mar 2024 03:19:05 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710929945; cv=pass; d=google.com; s=arc-20160816; b=Xq3WcFJJDaX3EEsNFUhCuc/5sXs50AKRbFImeePPM892/jyx4vj9BVzz/W53Va3osU N5NH6G44d4udyC/t4wRXV1oG2j+zaCSuJR7IgUNHLazVvufMUHIILi+sFIk9xp9f9WFR ybiN3ZPzcPXrPFIxFz5Fczw6bVJAerVparnot0DRg/u6q+HUy1VAotCf5IBKunZuI4Cy y6+fRtY7wlcKx3/OfwMP8eisKXViQrhx0YA5TPCHaoyqVfYwJiAbFUC5kJxYW4BReCLB ItfskbXG9ejp/U2qDqzXUcu321WLZoBCbY7lFi6da46Z2w4xGhrd4Qf8AtBmgzubBif6 tlSA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:dkim-signature; bh=Pe97FWHITdYkiCtSSFDy2YJv9pSAbWKeZZSBy5Rk1y0=; fh=x/fHlgTsrOt/CaALWdqTTVIajC+u+kTk9xjkgcqPf7Y=; b=C9tCWF6oO6iM2ue8f5cj1fr5x2IFL+QuJH0UTbT3NaD0VWHGDXSqyRJco1X0jHk+rV UduJOnxL677L9zEcQgRymV7b7/F6Fz0LaimW4NqEt/0syUfvQx8DU8rF0saTwEO1/AuQ 3JdgPjrIADJVOI9z7gqcP7MkbEIEcWHYACxD2keQq7g7rSlSWkVvoZ0Xe7sWj7+3V+AX kZRm2Zj1lPvH7sqhsNRBPvXD5j21scsfBWXTE5U0KUm8fodw5cfrkR8FMasGc6F0daef 6M0z4A64ajv94ic7mR/Wx7dwQH++nBMuOJI9z1sS1FC5LTK9S93PRxOrQmpY50eMkixz +tFw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=iQOMFP5U; arc=pass (i=1 spf=pass spfdomain=flex--glider.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-108745-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-108745-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id x20-20020ae9f814000000b0078a00e932f2si6229121qkh.276.2024.03.20.03.19.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Mar 2024 03:19:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-108745-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=iQOMFP5U; arc=pass (i=1 spf=pass spfdomain=flex--glider.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-108745-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-108745-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 3F5051C22104 for ; Wed, 20 Mar 2024 10:19:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EE79C3CF51; Wed, 20 Mar 2024 10:18:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="iQOMFP5U" Received: from mail-ed1-f74.google.com (mail-ed1-f74.google.com [209.85.208.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6AD393BB50 for ; Wed, 20 Mar 2024 10:18:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.74 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710929939; cv=none; b=GDlBGQknxIQhXyiFOmAV6svY3CC3QWeS923ZVHKz+8ogDH6TdXL/0VrkbOqVMs722rzHllgeJNFeJY8n3/tPnSUPr4ifGEsgHzywp+oIy/Q6nNEeECacCBdI+txIat0XrC8tJS/W9SykpVxGfyhM2r0BXs2/zQ9fAy+xMZ8zGfE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710929939; c=relaxed/simple; bh=AmAmCe23OTfeKAUnrQCYn3TUQz3Ynnj28Y0Z07KqhW4=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=rK5S+K+TnlcBHXtNi9YMjv69u0QW4035PakI/QgLHtusWfUQoQRvpsCYQa3ngDm5RhUWLJyy8nwKOGH3o3vS/YPP4P2Ox+tf1J7eRQMOCSTW5RqV4uQJptAu53d6N8o51M5t6a/JcumPd3t0O/pziXPU7RkpgfmjMB933jrf+xI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--glider.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=iQOMFP5U; arc=none smtp.client-ip=209.85.208.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--glider.bounces.google.com Received: by mail-ed1-f74.google.com with SMTP id 4fb4d7f45d1cf-559555e38b0so4162692a12.3 for ; Wed, 20 Mar 2024 03:18:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1710929936; x=1711534736; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=Pe97FWHITdYkiCtSSFDy2YJv9pSAbWKeZZSBy5Rk1y0=; b=iQOMFP5U4iw6oP25OGP2qZaurAI92VB639kebcVe75DUBSRnKufnKTtyq+LJ+nDTl6 dcpYNKmbJASQ5QbXT7JBCGMHdEctVNKlgi7jHIn+PUKYo0B/aG/HY5ofmqgwCBuHbPrR IhvqOY350VoVyOxmtN+KEe4vKA+kgMUKUBSCjNcxozQBI6RfEIEXOAkfWK31axtCjfz/ VU74PlfVOi3lsTTpQd3kHqx3diSvgxWpmqZqzs4mLw/BTzCjViK/wyKAn4uDBXKTuHYr wtRR/mI37yB+TX3InBGAnnNwN+7Trbvg8FBDZJ1i9gNS5ek89fB1NdUAPu1YrOQ2spW8 iyyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710929936; x=1711534736; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=Pe97FWHITdYkiCtSSFDy2YJv9pSAbWKeZZSBy5Rk1y0=; b=kiOavtW5YmrkmClOS0gIV8PJyHlh8kFcGpZnqOtIt3oamemylMhcPm/krAMgbhBRpJ tLDYVcF+iYAS5fOxcaxuCiTc8aAuwiUi1ROFAPjmH/wLl/pf7sKoHtUcEzQZg8iqXiLV AC1Gv0ZIHw7bnX7gR5okpUo76X9nfxg2uqhSxbZ0bbTIzrQtiOtK3p14DbUyeBl9/QvI hP/UzNwk5Td2Sfvjs1vRoh3lzdaaJRkLsqP7pFxh6jl9LTz4QA5J4zZ26eR7ww+6+cgf +flWhjgcSyOjAVL9k9q17WmgJvEXXAqJPkzS9+VnxrA8khtea/ZnW2xJDFu5J+umhKWJ et9A== X-Gm-Message-State: AOJu0YxIrYDPfy+1sktgEBPOaHGrjUldF+a+qVxIfD0GtHy0tdkcUGx7 MlzdYgWGWoibd7TThJtOOZio3jvGvub0KDCiXsn6HfH2WZmcgfsLQ/HM9V08rtNDSi9TcioFy91 Ybg== X-Received: from glider.muc.corp.google.com ([2a00:79e0:9c:201:2234:4e4b:bcf0:406e]) (user=glider job=sendgmr) by 2002:a05:6402:3893:b0:568:a515:30e8 with SMTP id fd19-20020a056402389300b00568a51530e8mr77979edb.0.1710929935435; Wed, 20 Mar 2024 03:18:55 -0700 (PDT) Date: Wed, 20 Mar 2024 11:18:49 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.44.0.291.gc1ea87d7ee-goog Message-ID: <20240320101851.2589698-1-glider@google.com> Subject: [PATCH v2 1/3] mm: kmsan: implement kmsan_memmove() From: Alexander Potapenko To: glider@google.com, akpm@linux-foundation.org Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, kasan-dev@googlegroups.com, tglx@linutronix.de, x86@kernel.org, Tetsuo Handa , Dmitry Vyukov , Marco Elver , Linus Torvalds Content-Type: text/plain; charset="UTF-8" Provide a hook that can be used by custom memcpy implementations to tell KMSAN that the metadata needs to be copied. Without that, false positive reports are possible in the cases where KMSAN fails to intercept memory initialization. Link: https://lore.kernel.org/all/3b7dbd88-0861-4638-b2d2-911c97a4cadf@I-love.SAKURA.ne.jp/ Suggested-by: Tetsuo Handa Signed-off-by: Alexander Potapenko Cc: Dmitry Vyukov Cc: Marco Elver Cc: Linus Torvalds --- include/linux/kmsan-checks.h | 15 +++++++++++++++ mm/kmsan/hooks.c | 11 +++++++++++ 2 files changed, 26 insertions(+) diff --git a/include/linux/kmsan-checks.h b/include/linux/kmsan-checks.h index c4cae333deec5..e1082dc40abc2 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() - Notify KMSAN about a data copy within kernel. + * @to: destination address in the kernel. + * @from: source address in the kernel. + * @size: number of bytes to copy. + * + * Invoked after non-instrumented version (e.g. implemented using assembly + * code) of memmove()/memcpy() is called, in order to copy KMSAN's metadata. + */ +void kmsan_memmove(void *to, const void *from, size_t to_copy); + #else static inline void kmsan_poison_memory(const void *address, size_t size, @@ -78,6 +89,10 @@ static inline void kmsan_copy_to_user(void __user *to, const void *from, { } +static inline void kmsan_memmove(void *to, const void *from, size_t to_copy) +{ +} + #endif #endif /* _LINUX_KMSAN_CHECKS_H */ diff --git a/mm/kmsan/hooks.c b/mm/kmsan/hooks.c index 5d6e2dee5692a..364f778ee226d 100644 --- a/mm/kmsan/hooks.c +++ b/mm/kmsan/hooks.c @@ -285,6 +285,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(void *to, const void *from, size_t size) +{ + if (!kmsan_enabled || kmsan_in_runtime()) + return; + + kmsan_enter_runtime(); + kmsan_internal_memmove_metadata(to, (void *)from, size); + kmsan_leave_runtime(); +} +EXPORT_SYMBOL(kmsan_memmove); + /* Helper function to check an URB. */ void kmsan_handle_urb(const struct urb *urb, bool is_out) { -- 2.44.0.291.gc1ea87d7ee-goog