lkml.org 
[lkml]   [2022]   [Aug]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    Date
    Subject[PATCH v5 30/44] kcov: kmsan: unpoison area->list in kcov_remote_area_put()
    From
    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 <glider@google.com>
    ---

    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 <linux/fs.h>
    #include <linux/hashtable.h>
    #include <linux/init.h>
    +#include <linux/kmsan-checks.h>
    #include <linux/mm.h>
    #include <linux/preempt.h>
    #include <linux/printk.h>
    @@ -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)
    --
    2.37.2.672.g94769d06f0-goog
    \
     
     \ /
      Last update: 2022-08-26 17:15    [W:3.308 / U:0.052 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site