From patchwork Fri Aug 26 15:07:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 12956203 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 B9533ECAAD4 for ; Fri, 26 Aug 2022 15:09:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 54FD894000A; Fri, 26 Aug 2022 11:09:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4B12B940007; Fri, 26 Aug 2022 11:09:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3052994000E; Fri, 26 Aug 2022 11:09:38 -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 1D575940007 for ; Fri, 26 Aug 2022 11:09:38 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id D6F8E80E37 for ; Fri, 26 Aug 2022 15:09:37 +0000 (UTC) X-FDA: 79842077994.01.079D194 Received: from mail-ed1-f74.google.com (mail-ed1-f74.google.com [209.85.208.74]) by imf21.hostedemail.com (Postfix) with ESMTP id 47C9F1C001B for ; Fri, 26 Aug 2022 15:09:37 +0000 (UTC) Received: by mail-ed1-f74.google.com with SMTP id z6-20020a05640240c600b0043e1d52fd98so1241700edb.22 for ; Fri, 26 Aug 2022 08:09:36 -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; bh=RpdJ5KT5GAuxqWidUZuS2M2CiPNp+gZwFhAUBa4xHko=; b=TJz1UTJBESEdKuAr0m8ClDSUAjamVWg2DEv+2WQqCh6Zcxv2oRD55g+O0oye9l40zE VbOvZ3R60SbIN++3IKS2yh90SOwgtqzaCgsQtPATI2d4WJvG5qImDFrX2yJUjrWx8T39 MQQKFjvZ3fA1TYUVsHaA5FR0hdMwNCkK7TJVCIsBqtjkpd/DAEBvNeqI5bfg6Gepswe+ l1jCxIh1lrZEBivplg5yDUBpa6io4UGCJ9ztmW+CUFCm1dTP8QhVkTov1blbHQ6U4xC3 IWO5hCXy6iolpqSQIc2bH9AGoDcxJQSD0LkhoSBkctagTpdhEEFLo7Y5mpIRWVWOlKNE COTA== 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; bh=RpdJ5KT5GAuxqWidUZuS2M2CiPNp+gZwFhAUBa4xHko=; b=0l/nwL+deL6D0RPFyVtsIVb3sti+1mYrGGr6m28UoUECOT1H2l+YRQOGIHUOTXyP6E ZxfgczQFaqTd+7i/5VF+nCe9Fqpr1bMsvuf3kL4u9YZFT/X3cWqnDgZOo1x3JUGwFR1v 0mGJgwcAla6DeTWJev8qh075AZ3Af5dmgxHxNkEbMIsx5WO0zpgUCPSBNpyb/zVM7Lu6 pJUx+Xg1gIjOZsaY0exp4gJXfRbIA5/7rmh0hkfGfN51//M8LZeO8Aj5miNjNPUSkuK3 8XC/D20Bb8Pq2wv3fTib2lcaKTGHMTn5M9hZdmsEty9+azj4/xb2E6miZwNK1AIA2ReZ YuFg== X-Gm-Message-State: ACgBeo25X+HBiD5WIsE8ybwatiZXnXRl5m4sQuXTkjLd0k1N66+d8Zlz buL1XsNsOTCpDgCpnlmnVLnOGDrFeeo= X-Google-Smtp-Source: AA6agR5j/r012ARsOS/cLTFyia8pItWWXJH9zXKKE4ubXclVuI6mHNquDQgDo/C5PUvhnsbEwfNt5cuHLt4= X-Received: from glider.muc.corp.google.com ([2a00:79e0:9c:201:5207:ac36:fdd3:502d]) (user=glider job=sendgmr) by 2002:a17:907:2173:b0:73d:c95d:1179 with SMTP id rl19-20020a170907217300b0073dc95d1179mr5669815ejb.89.1661526576513; Fri, 26 Aug 2022 08:09:36 -0700 (PDT) Date: Fri, 26 Aug 2022 17:07:53 +0200 In-Reply-To: <20220826150807.723137-1-glider@google.com> Mime-Version: 1.0 References: <20220826150807.723137-1-glider@google.com> X-Mailer: git-send-email 2.37.2.672.g94769d06f0-goog Message-ID: <20220826150807.723137-31-glider@google.com> Subject: [PATCH v5 30/44] 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 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 , 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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1661526577; a=rsa-sha256; cv=none; b=mOW4Y/kvS8D04z8RAqH6VS3smfYaTnchBD/DgcXZEWmkJ7ZllP1N6lwx2kIm/g+ZlB8Q8N VP3AjZ0s29YUhXfGR8hU3c5VBRwVk/SlNorWJJ9ucpF0KrmC8+ZgHAwp0rc2Az4bWJRent 7r++6biJ+SiKaxtTE23btm7bv+JvxtM= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=TJz1UTJB; spf=pass (imf21.hostedemail.com: domain of 3MOIIYwYKCDcZebWXkZhhZeX.Vhfebgnq-ffdoTVd.hkZ@flex--glider.bounces.google.com designates 209.85.208.74 as permitted sender) smtp.mailfrom=3MOIIYwYKCDcZebWXkZhhZeX.Vhfebgnq-ffdoTVd.hkZ@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=1661526577; 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=RpdJ5KT5GAuxqWidUZuS2M2CiPNp+gZwFhAUBa4xHko=; b=NwFrZKS6cjGO48xQ72RgUu/wxYhWvCyjW0QtFT2j7JgJdSKMjbNQXnDj3nA6vaNedm4UFt PAUImdeWBtTQLkj7hjl4nnOAZxTGahhXkAKwJHSL3pnTglpRzpizCjrt5xUtbwCTNfj4nj C1NSYhjD1OebdkqAYD75YVD827vJChQ= X-Rspam-User: Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=TJz1UTJB; spf=pass (imf21.hostedemail.com: domain of 3MOIIYwYKCDcZebWXkZhhZeX.Vhfebgnq-ffdoTVd.hkZ@flex--glider.bounces.google.com designates 209.85.208.74 as permitted sender) smtp.mailfrom=3MOIIYwYKCDcZebWXkZhhZeX.Vhfebgnq-ffdoTVd.hkZ@flex--glider.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspamd-Server: rspam08 X-Stat-Signature: kxtee9oayrjf4hj3rddy7cx4ad7q463o X-Rspamd-Queue-Id: 47C9F1C001B X-HE-Tag: 1661526577-975384 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)