From patchwork Tue May 28 10:48:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 13676465 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 E19AAC25B78 for ; Tue, 28 May 2024 10:48:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 727976B007B; Tue, 28 May 2024 06:48:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6D7476B0095; Tue, 28 May 2024 06:48:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 59EBB6B0098; Tue, 28 May 2024 06:48:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 3D0926B007B for ; Tue, 28 May 2024 06:48:17 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id BAE6C16048E for ; Tue, 28 May 2024 10:48:16 +0000 (UTC) X-FDA: 82167480192.07.9AD230B Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) by imf29.hostedemail.com (Postfix) with ESMTP id 12A8A120007 for ; Tue, 28 May 2024 10:48:13 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=gUfNpfff; spf=pass (imf29.hostedemail.com: domain of 3bLZVZgYKCGkNSPKLYNVVNSL.JVTSPUbe-TTRcHJR.VYN@flex--glider.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3bLZVZgYKCGkNSPKLYNVVNSL.JVTSPUbe-TTRcHJR.VYN@flex--glider.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1716893294; 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-type:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=168aCLfPuYgGXMseZYgeOmJsf4bgrF3NmHxiEDuMCbc=; b=ngOIlTtaP99cDzaF6LUnj8sIY2aCjBZetouOw+WzXIyZkFtHyyfvf4hdCqzjj20EkXXVKD SW545mTlN2vj7gljKL/kTIkp5YnsAC0n8xfL9NFO5JhG7cKLk3ERq0D6JeP1T0ruKSiWnW qQl8eSLWF+J2XBKroqd9+kQEp5kiOCA= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=gUfNpfff; spf=pass (imf29.hostedemail.com: domain of 3bLZVZgYKCGkNSPKLYNVVNSL.JVTSPUbe-TTRcHJR.VYN@flex--glider.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3bLZVZgYKCGkNSPKLYNVVNSL.JVTSPUbe-TTRcHJR.VYN@flex--glider.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1716893294; a=rsa-sha256; cv=none; b=QR0lYndOQ/00+BJbFOnN5WEX+olvaeV2JGsIJO/grvji4cwvE8qo2dF3qA3PM6qEyLKOBx 3/HbF4LjXBD1o7tOWFtk7AOBUfVlmNXQzlDF5yIo34fQZh65tHdgPhaXH8aPwZr7qutYb2 WxNkEyqr+UzVU1eu7PGHoS1n0kRtx1o= Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-62a1e9807c0so7795247b3.0 for ; Tue, 28 May 2024 03:48:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1716893293; x=1717498093; darn=kvack.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=168aCLfPuYgGXMseZYgeOmJsf4bgrF3NmHxiEDuMCbc=; b=gUfNpfffOuCZ8TpWw6DMZr5cajz/AtZF5bKBmGb7CryOkbDsU3zoZInEmexY6lkkU3 +A4kjBtz4L6nms/mFvALuKa49YxyhznLCReCoFbwEEtSqKU+Wgw+HYVKT/I+L96q4GFm ldSfGsjJfrXhfxqkuEtDshZ4KtlECx0DUAwEOJeIEy1p4fkneeUI/tb55qmWNTN+68K1 53XdDxwQqDq4glmvXX6QsiLIWmTYqXvT/YrEyJkAqLXMRMPKTXXJbqXMyCJZlcTU5EzA yDYLNh5XFHgSAyPL6R77ER7uZmzmz0itEBN5cevyXRWaSIHHIoaB1+B/CU8IWtWYmVxo BBkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716893293; x=1717498093; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=168aCLfPuYgGXMseZYgeOmJsf4bgrF3NmHxiEDuMCbc=; b=nqadpIHT1Isr5PvUULslbVO9X7/2LbUlb5FczWSthTbaiwkauTvAndEiLIGt6t10bP zsyKasGJceK8FRzaH8gikSjf8QwXQEUd3xiqvstKKU36AkQemjx8JErwjtwggA8goaBf fb4XHC+LfQ/JAvcOJ1PBwLfQA78Z5tzt2y5MGs6hXe+1ICY0CJ4w1DvCQX+HJEVdtANm 1tq5f7TH7PXkXhSr0I0jUPPvA10sLOUd/6R2CsKUnIvI+fzg74Jfe4ApGyGQBKW8L+UT 2HiUYUiFOqxo2p7rhmgPzW64KxJ9o7iTncaYAuZ/K3i7uzDXKkkOJqv1ApjBgATNJ01V /CAw== X-Forwarded-Encrypted: i=1; AJvYcCUsNMSoCjc6kIJQYXKl/QClKMliWws0Pq7cnpmtMy3EtpoFISt6OFbKQ6PnMOpyLdhqiTn0Xgsy/J8rXRtxR6dAS0c= X-Gm-Message-State: AOJu0YzEtztJv6+Kg+hlidPoj25TSua1MTXviwsCiCOC2Y+PKz93gg5H /ObHAKz1orR8r0oPLX6WHMGN90bBwOityohFDPscIZTi2SZFFh2k9Zosems75Lece5h+qD8owDY g/g== X-Google-Smtp-Source: AGHT+IEDWQiLMhofWJRVp2xMhEilUEioPkayeNWYBHymPh/j08uSwId41HBaCP4sI/H4bKASCeL6PRXSLEM= X-Received: from glider.muc.corp.google.com ([2a00:79e0:9c:201:6416:417e:596:420a]) (user=glider job=sendgmr) by 2002:a05:690c:600b:b0:611:5a9d:bb0e with SMTP id 00721157ae682-62a076284d6mr32629097b3.4.1716893292893; Tue, 28 May 2024 03:48:12 -0700 (PDT) Date: Tue, 28 May 2024 12:48:06 +0200 Mime-Version: 1.0 X-Mailer: git-send-email 2.45.1.288.g0e0cd299f1-goog Message-ID: <20240528104807.738758-1-glider@google.com> Subject: [PATCH 1/2] kmsan: do not wipe out origin when doing partial unpoisoning From: Alexander Potapenko To: glider@google.com Cc: elver@google.com, dvyukov@google.com, akpm@linux-foundation.org, bjohannesmeyer@gmail.com, linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, linux-mm@kvack.org X-Rspam-User: X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 12A8A120007 X-Stat-Signature: xsh4tjji1e7qyinpzfp74kipcdhc3b31 X-HE-Tag: 1716893293-318866 X-HE-Meta: U2FsdGVkX19GjEJBjX8HLg2h5VTVAeaI/ASTOUiMB+f0muNW9Rt+BJUWDZNkJ5TlCVUCQNUzRC3yL11g3xGCDAtLPNGabcQ01iGAypbtDgvnnBFsSJkTkuooNNVPVI3G3saScPRNAPkVcWiWZrguF0XQz6yU4HX9TjFb3AUXjIRi9fn8JeZ8de9LLyXoQx194GGsVp8a3RokkPumq10tY5w3h6saTQX9UQbAOOx939s9JFYjeanyKieWDXQ/819c0X3mb7oFsPcUI0z2R3GYTU3LXB4RbHZba/mBYQkDe+j540Q9pEeeZLtRc0jZ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/kEMbMgkQt46axdqkL464OQgfnSKlqBex/Bzp+dXD8HaIsOp2HLlgnG/8Bsy9tuKdZ16Kd445aiB7FCwenSA00CKDJu1nG3m5XBgM8wdbH+5am3Kx+9WVSB1Jvcs9u2C7vN5wuM4xZiLbKXfSLwESZfMIp5g9p+dPNHHFF6XTnPnaaZa8+Rzap/bRZSEOUxUBsdWdqvYyIAzO8f9B5052KcqDCwJxvVpJib13Akznr0TXJKMgpJcsaRr+YQko+xjOflhWBjEJlZzfWzJdElmCUyrMaYzUhhsM5NPl83og== X-Bogosity: Ham, tests=bogofilter, spamicity=0.007677, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: As noticed by Brian, KMSAN should not be zeroing the origin when unpoisoning parts of a four-byte uninitialized value, e.g.: char a[4]; kmsan_unpoison_memory(a, 1); This led to false negatives, as certain poisoned values could receive zero origins, preventing those values from being reported. To fix the problem, check that kmsan_internal_set_shadow_origin() writes zero origins only to slots which have zero shadow. Reported-by: Brian Johannesmeyer Link: https://lore.kernel.org/lkml/20240524232804.1984355-1-bjohannesmeyer@gmail.com/T/ Fixes: f80be4571b19 ("kmsan: add KMSAN runtime core") Signed-off-by: Alexander Potapenko Reviewed-by: Marco Elver Tested-by: Brian Johannesmeyer --- mm/kmsan/core.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/mm/kmsan/core.c b/mm/kmsan/core.c index cf2d70e9c9a5f..95f859e38c533 100644 --- a/mm/kmsan/core.c +++ b/mm/kmsan/core.c @@ -196,8 +196,7 @@ void kmsan_internal_set_shadow_origin(void *addr, size_t size, int b, u32 origin, bool checked) { u64 address = (u64)addr; - void *shadow_start; - u32 *origin_start; + u32 *shadow_start, *origin_start; size_t pad = 0; KMSAN_WARN_ON(!kmsan_metadata_is_contiguous(addr, size)); @@ -225,8 +224,16 @@ void kmsan_internal_set_shadow_origin(void *addr, size_t size, int b, origin_start = (u32 *)kmsan_get_metadata((void *)address, KMSAN_META_ORIGIN); - for (int i = 0; i < size / KMSAN_ORIGIN_SIZE; i++) - origin_start[i] = origin; + /* + * If the new origin is non-zero, assume that the shadow byte is also non-zero, + * and unconditionally overwrite the old origin slot. + * If the new origin is zero, overwrite the old origin slot iff the + * corresponding shadow slot is zero. + */ + for (int i = 0; i < size / KMSAN_ORIGIN_SIZE; i++) { + if (origin || !shadow_start[i]) + origin_start[i] = origin; + } } struct page *kmsan_vmalloc_to_page_or_null(void *vaddr) From patchwork Tue May 28 10:48:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 13676466 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 D5BCFC25B78 for ; Tue, 28 May 2024 10:48:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 63D106B0099; Tue, 28 May 2024 06:48:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5ECCB6B009A; Tue, 28 May 2024 06:48:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4B6AB6B009B; Tue, 28 May 2024 06:48:20 -0400 (EDT) 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 258D66B0099 for ; Tue, 28 May 2024 06:48:20 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id C009AA0439 for ; Tue, 28 May 2024 10:48:19 +0000 (UTC) X-FDA: 82167480318.14.927E8DA Received: from mail-ej1-f73.google.com (mail-ej1-f73.google.com [209.85.218.73]) by imf02.hostedemail.com (Postfix) with ESMTP id E1CA98000E for ; Tue, 28 May 2024 10:48:17 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=Efqsy2rg; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf02.hostedemail.com: domain of 3b7ZVZgYKCGwQVSNObQYYQVO.MYWVSXeh-WWUfKMU.YbQ@flex--glider.bounces.google.com designates 209.85.218.73 as permitted sender) smtp.mailfrom=3b7ZVZgYKCGwQVSNObQYYQVO.MYWVSXeh-WWUfKMU.YbQ@flex--glider.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1716893298; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=RTgy0iA5o4eiMLkf5DZA1XVIVBf+wcR0MiDC6AwIp5o=; b=cHCK+zz9cWebAmn46R41MsjdW2HzZ0WERVP5M9XhpVCVlNTsC3dXy14y3hmkqXLQVUHV/v sbIe0Qzg2Ru/BaghsnNCy5PmvLMG3FfpgrIU6z+3+rtzFl58glhECe/s8TuuY6AzM4Ce+A +TgLx8etDfUqT7om5WlCMZy7c5qHj5Q= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=Efqsy2rg; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf02.hostedemail.com: domain of 3b7ZVZgYKCGwQVSNObQYYQVO.MYWVSXeh-WWUfKMU.YbQ@flex--glider.bounces.google.com designates 209.85.218.73 as permitted sender) smtp.mailfrom=3b7ZVZgYKCGwQVSNObQYYQVO.MYWVSXeh-WWUfKMU.YbQ@flex--glider.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1716893298; a=rsa-sha256; cv=none; b=0UWLIU9h1+MV1fih18un6oWnB8v+etfn1G/iVdfSPNz5QZs+4VNjlil4T3XuZIg/tUmyg8 K4vRmmiS9DH3cxA0EmArf3e0q6ow6Iwby3krdtLl+WTz4Rm9/6vy4n9dOTwQcD4o4JQ7TQ Sre/2HEHeHGnBW1itjVSNwkg4No7NLc= Received: by mail-ej1-f73.google.com with SMTP id a640c23a62f3a-a6335fdc8easo34508466b.3 for ; Tue, 28 May 2024 03:48:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1716893296; x=1717498096; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=RTgy0iA5o4eiMLkf5DZA1XVIVBf+wcR0MiDC6AwIp5o=; b=Efqsy2rg4587M7eO0JbIFk3Uif3rH+oF7bEPCbiKbnxYG7i2c7lE+ZqW7iUGTQnm1d jkq++n9GP0mKwpYOmIr6J1rFGBGIw9D/mVhR6met/Sv/o2x9qQQ06aIvgnEjMa9IZmKw 7kHFe/TVQqHlrk2Xw5WO4QK6fInnk54o8F5NJP6XJceADqbL4erEBWS7G8+jTTazqLxV AXOefGEwiEYCUXnd/9tG+NEJCJdV7C6PSr8bdOWxeXvAcIKG23QB3q6QrC/D3fwhjoIT jHe17A3QioK4zJnUYCwC5rWpMBU0y9fKtmTH215j431BjVDdzziw6jmdMYSrjwIlLl5s cqQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716893296; x=1717498096; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=RTgy0iA5o4eiMLkf5DZA1XVIVBf+wcR0MiDC6AwIp5o=; b=tIO3t1KRd5kuB6DyLhBia8WG7u493F1tBkkTYgv7Tzcqp6L4rIt/gOs5F4wRsG0cqS F9L5OsWsEFDt0/8YBIhFBzf4HZMY6/RKyUfMG5NSeJXtr7Rwkm6NRM4/7CKU2EZW3XkQ 3RKlyxxnDC7x+C2iwpQDvsRKCnzWrkG12i2u7+y/1eBSrXrQ9tnkZd8QX8PfVEzuSfPY yQx/OQYdeIlsZ7ubUHjVPCCB9COu0S+6UkYev9gB+E/MAur15IVqgH/H+swm4MlJWJRO JGTkIrUE5Jo5dU6c5aT3Ic3lMSFKt10PcIqaqeU7LehgprX3NJzNX+FeE3fx0KXOKDPe ucCA== X-Forwarded-Encrypted: i=1; AJvYcCXhNyCyOAh241JD1CmMTxF5KIWNfKBdaRweMyfthC9y8Ow1rwTc60yYi3UafsJSVBxwW+vB71XpQu9sVqmLRAx0Zzo= X-Gm-Message-State: AOJu0Yy5ok9dUPrFs27VG3LBiy1jCEGnaxXsNRIZXH/WSgzJAn4KmuEy /NlvVlSoFB77EtXZugPR6zxpZkItkjKNEMdLkbPPcoUMThThunFP03PIBw0djF5yFulWeBGi6Vx WIQ== X-Google-Smtp-Source: AGHT+IET+wqbCwieBcRKi1iNrPHSEZCrZnq1lsNKlL4c9ImOIZieVkTk1hpvy/CeH7ks20L//eHDRYvdSOU= X-Received: from glider.muc.corp.google.com ([2a00:79e0:9c:201:6416:417e:596:420a]) (user=glider job=sendgmr) by 2002:a17:906:478c:b0:a61:9678:91e2 with SMTP id a640c23a62f3a-a62642e76e2mr1061566b.9.1716893295944; Tue, 28 May 2024 03:48:15 -0700 (PDT) Date: Tue, 28 May 2024 12:48:07 +0200 In-Reply-To: <20240528104807.738758-1-glider@google.com> Mime-Version: 1.0 References: <20240528104807.738758-1-glider@google.com> X-Mailer: git-send-email 2.45.1.288.g0e0cd299f1-goog Message-ID: <20240528104807.738758-2-glider@google.com> Subject: [PATCH 2/2] kmsan: introduce test_unpoison_memory() From: Alexander Potapenko To: glider@google.com Cc: elver@google.com, dvyukov@google.com, akpm@linux-foundation.org, bjohannesmeyer@gmail.com, linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, linux-mm@kvack.org X-Rspamd-Queue-Id: E1CA98000E X-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TF67lGQ lUpqrjghIs2JSGd+BThaZ4gIQF2z1fMT4ivIzO3mqWDG8luAfmlKOpNeCukeJ6/wjB3mFQVRPr2rKwNmB9JuguVSSHqKuunIGNcTYBhsM27wYCy7yy3VBb/JBvzEZCLc28KJWF+mlykRrZ8sllqLqYUvuglloUGGW1BX1Lvdq8k4rgf9JRYAILXApWU9OAHBqlTwuc5ePjG3mrL4+CHYAo+Mn4v5GhfCnqzCafx3ODe4DC67Q95RTFtZLOgcv1Bp4uxcGY2d17qfXbDHav4oIAnVGxlMr+c7W4CxsqPhNQsVNpJ31ITYxyP9hO6zOtp2lvXZhdONQ/XJt26cPGhY7GDDiXUw+wvzajwTPL5nNm32PUR9XvtTvK6D3qCd6Llu255M+K9agTjCOw1BlrTT8QitkfjovNHMoY1ycN9dwjJjJc5n6MGuKUPI0orBaD5y9RO0TC8Z2tblSOk3wIzlPSAQOUM+EfVOK4A4ncIRpsdla4JyQH6jLr/PM/N6Ayjg+x3UpIqoqOmBh6pvp+9BGVBF5e8OOusi12jyno/nFdulYr+pxhHDV9TqhkSLsZNey1g6xAGR/w5udRi9fRDDtEed6ucNpuLkamQPdc3QU+avyjOWnzQDuMKVm44qDmoCgdwjjdQSHHaLck/M= 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: From: Brian Johannesmeyer Add a regression test to ensure that kmsan_unpoison_memory() works the same as an unpoisoning operation added by the instrumentation. The test has two subtests: one that checks the instrumentation, and one that checks kmsan_unpoison_memory(). Each subtest initializes the first byte of a 4-byte buffer, then checks that the other 3 bytes are uninitialized. Signed-off-by: Brian Johannesmeyer Link: https://lore.kernel.org/lkml/20240524232804.1984355-1-bjohannesmeyer@gmail.com/T/ [glider@google.com: change description, remove comment about failing test case] Signed-off-by: Alexander Potapenko --- mm/kmsan/kmsan_test.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/mm/kmsan/kmsan_test.c b/mm/kmsan/kmsan_test.c index 07d3a3a5a9c52..018069aba92be 100644 --- a/mm/kmsan/kmsan_test.c +++ b/mm/kmsan/kmsan_test.c @@ -614,6 +614,32 @@ static void test_stackdepot_roundtrip(struct kunit *test) KUNIT_EXPECT_TRUE(test, report_matches(&expect)); } +/* + * Test case: ensure that kmsan_unpoison_memory() and the instrumentation work + * the same. + */ +static void test_unpoison_memory(struct kunit *test) +{ + EXPECTATION_UNINIT_VALUE_FN(expect, "test_unpoison_memory"); + volatile char a[4], b[4]; + + kunit_info( + test, + "unpoisoning via the instrumentation vs. kmsan_unpoison_memory() (2 UMR reports)\n"); + + /* Initialize a[0] and check a[1]--a[3]. */ + a[0] = 0; + kmsan_check_memory((char *)&a[1], 3); + KUNIT_EXPECT_TRUE(test, report_matches(&expect)); + + report_reset(); + + /* Initialize b[0] and check b[1]--b[3]. */ + kmsan_unpoison_memory((char *)&b[0], 1); + kmsan_check_memory((char *)&b[1], 3); + KUNIT_EXPECT_TRUE(test, report_matches(&expect)); +} + static struct kunit_case kmsan_test_cases[] = { KUNIT_CASE(test_uninit_kmalloc), KUNIT_CASE(test_init_kmalloc), @@ -637,6 +663,7 @@ static struct kunit_case kmsan_test_cases[] = { KUNIT_CASE(test_memset64), KUNIT_CASE(test_long_origin_chain), KUNIT_CASE(test_stackdepot_roundtrip), + KUNIT_CASE(test_unpoison_memory), {}, };