From patchwork Thu Sep 15 15:04:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 12977547 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 00625C6FA89 for ; Thu, 15 Sep 2022 15:05:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8BFBD8001C; Thu, 15 Sep 2022 11:05:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7F94680007; Thu, 15 Sep 2022 11:05:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 69CD68001C; Thu, 15 Sep 2022 11:05:59 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 5593880007 for ; Thu, 15 Sep 2022 11:05:59 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 39A0E160571 for ; Thu, 15 Sep 2022 15:05:59 +0000 (UTC) X-FDA: 79914644838.20.45F3E85 Received: from mail-lf1-f73.google.com (mail-lf1-f73.google.com [209.85.167.73]) by imf13.hostedemail.com (Postfix) with ESMTP id ABF64200B4 for ; Thu, 15 Sep 2022 15:05:58 +0000 (UTC) Received: by mail-lf1-f73.google.com with SMTP id e4-20020a195004000000b004979e6a0c88so5647183lfb.22 for ; Thu, 15 Sep 2022 08:05:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date; bh=TqyxH/L5MkAtosS0jWqWllGGzUIesiLdVg3wG3p7XtY=; b=LKBPWrq4xXW7nEQB2ZmDRYo6z5ym4Le1THr8Xz3k7EBYLNOSha3Vhju0WXExFwXMZf pX6jviKwXYf/T1MVZ+5qxS4JaETzqBr+L0yjL5rYhmxXUekA0TEsSA8YRxYi5D0uDvsb NYOOkM/oK63TRvOnG9gJka71MFo0nVJFHOFee0NXtYOWDnMFjeaNsT8i5fOuOTX0XMgC 9VElsJE6GI8Iftk760oZrEHYu4XwhnR8azD6+iL8qrR3RuQo3Z8mAHYtnOhgWEQY18jM DMru+t4Du9cAUzTuKfSbPWE/QnbKa8dlrPg29e6mY17/hRx4CrdxOfA4n95mDK9E6Nlc EkVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date; bh=TqyxH/L5MkAtosS0jWqWllGGzUIesiLdVg3wG3p7XtY=; b=LqZsqV5QzjKJ5oxUcph31j0yrVnPvUREZ/EsySGeQ6j2wukibX97hTknNDJxMIS+9S MJ7QP+Z+miwUU9//iVQFFShXhy7lambeEcHFWFj8JF99HfRWDRoIz+DdLoEh5XIehtXf O8FghH3TVmy2ifaOfC3YApu7zKZZy6Ye8bwwQXA1dPnpTw8+vSLpFfXr+pJRw6ZBazhM /BpFnnwcx7MDjsnTUXilrI8UfaEiUCyw/G8h4flw2dJdyGbDdVrGOjonZZYlW+fW3DK+ FuV9NKzxitZNu/3juGSp4s11Vlg8wfmFL63F0AhReAjmrEnndr6OfU9u6MROFLT3fT7L +28A== X-Gm-Message-State: ACrzQf2apvYEIjsuTzMMuDgSFsmswvV+N1/3JvITj+23HkD46WCkSsbP btjSD8hMl5iRecShqJumaCD0hcJfFp4= X-Google-Smtp-Source: AMsMyM51rNDLMIp7ozypIEsAXT0sulEDSz8gW5q4dALqMyH7lyGzgXjlA9GkTEeN37i0dxQ1XBCtNaS0ipQ= X-Received: from glider.muc.corp.google.com ([2a00:79e0:9c:201:686d:27b5:495:85b7]) (user=glider job=sendgmr) by 2002:a05:6512:3d2:b0:494:6546:dc1f with SMTP id w18-20020a05651203d200b004946546dc1fmr129949lfp.6.1663254357164; Thu, 15 Sep 2022 08:05:57 -0700 (PDT) Date: Thu, 15 Sep 2022 17:04:03 +0200 In-Reply-To: <20220915150417.722975-1-glider@google.com> Mime-Version: 1.0 References: <20220915150417.722975-1-glider@google.com> X-Mailer: git-send-email 2.37.2.789.g6183377224-goog Message-ID: <20220915150417.722975-30-glider@google.com> Subject: [PATCH v7 29/43] kcov: kmsan: unpoison area->list in kcov_remote_area_put() From: Alexander Potapenko To: glider@google.com Cc: Alexander Viro , Alexei Starovoitov , Andrew Morton , Andrey Konovalov , Andy Lutomirski , Arnd Bergmann , Borislav Petkov , Christoph Hellwig , Christoph Lameter , David Rientjes , Dmitry Vyukov , Eric Biggers , Eric Dumazet , Greg Kroah-Hartman , Herbert Xu , Ilya Leoshkevich , Ingo Molnar , Jens Axboe , Joonsoo Kim , Kees Cook , Marco Elver , Mark Rutland , Matthew Wilcox , "Michael S. Tsirkin" , Pekka Enberg , Peter Zijlstra , Petr Mladek , Stephen Rothwell , Steven Rostedt , Thomas Gleixner , Vasily Gorbik , Vegard Nossum , Vlastimil Babka , kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1663254358; 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=TqyxH/L5MkAtosS0jWqWllGGzUIesiLdVg3wG3p7XtY=; b=exuoC7UMww+wngKCLvcsP1ZcwScLiqCVZEKvDfGqjDlhyM664aHRp1N3g74mxv/OTdPnu+ FBaslw9OGcsS5brGMpPFSbbLEZMuiGtryBdLjv8K9zHEGgc6YqwydRw13nPRPVVVf/mvvM fLiWsRDcOxpm+95/qWCCFrkLHDEXQ2E= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=LKBPWrq4; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf13.hostedemail.com: domain of 3VT8jYwYKCIAkpmhivksskpi.gsqpmry1-qqozego.svk@flex--glider.bounces.google.com designates 209.85.167.73 as permitted sender) smtp.mailfrom=3VT8jYwYKCIAkpmhivksskpi.gsqpmry1-qqozego.svk@flex--glider.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1663254358; a=rsa-sha256; cv=none; b=ROR+LQmkFeiyE1kw6Lk2cUWVqGUYYJwUkX0WcOU0qxQ3lvrglLus7gUgtwzb4yXGmO/rLQ ae/QeJyS6j0r1Yna1iiqUhkOicB+EmZ2w8DX5IcWxoJEf18eTGa4KCrMZs73CbZF8xHvfi MCoG0ESMt5DMM69Ims9g3OC43Enrk+I= Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=LKBPWrq4; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf13.hostedemail.com: domain of 3VT8jYwYKCIAkpmhivksskpi.gsqpmry1-qqozego.svk@flex--glider.bounces.google.com designates 209.85.167.73 as permitted sender) smtp.mailfrom=3VT8jYwYKCIAkpmhivksskpi.gsqpmry1-qqozego.svk@flex--glider.bounces.google.com X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: ABF64200B4 X-Stat-Signature: u6f4gzff7f6gc3igq6p3s48o1urrhdr8 X-HE-Tag: 1663254358-835177 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: KMSAN does not instrument kernel/kcov.c for performance reasons (with CONFIG_KCOV=y virtually every place in the kernel invokes kcov instrumentation). Therefore the tool may miss writes from kcov.c that initialize memory. When CONFIG_DEBUG_LIST is enabled, list pointers from kernel/kcov.c are passed to instrumented helpers in lib/list_debug.c, resulting in false positives. To work around these reports, we unpoison the contents of area->list after initializing it. Signed-off-by: Alexander Potapenko --- v4: -- change sizeof(type) to sizeof(*ptr) -- swap kcov: and kmsan: in the subject Link: https://linux-review.googlesource.com/id/Ie17f2ee47a7af58f5cdf716d585ebf0769348a5a --- kernel/kcov.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/kernel/kcov.c b/kernel/kcov.c index e19c84b02452e..e5cd09fd8a050 100644 --- a/kernel/kcov.c +++ b/kernel/kcov.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -152,6 +153,12 @@ static void kcov_remote_area_put(struct kcov_remote_area *area, INIT_LIST_HEAD(&area->list); area->size = size; list_add(&area->list, &kcov_remote_areas); + /* + * KMSAN doesn't instrument this file, so it may not know area->list + * is initialized. Unpoison it explicitly to avoid reports in + * kcov_remote_area_get(). + */ + kmsan_unpoison_memory(&area->list, sizeof(area->list)); } static notrace bool check_kcov_mode(enum kcov_mode needed_mode, struct task_struct *t)