From: Andrey Konovalov <andreyknvl@gmail.com>
To: Sabyrzhan Tasbolatov <snovitoll@gmail.com>
Cc: elver@google.com, akpm@linux-foundation.org, bpf@vger.kernel.org,
dvyukov@google.com, glider@google.com,
kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org,
linux-mm@kvack.org, ryabinin.a.a@gmail.com,
syzbot+61123a5daeb9f7454599@syzkaller.appspotmail.com,
vincenzo.frascino@arm.com
Subject: Re: [PATCH v5] mm, kasan, kmsan: copy_from/to_kernel_nofault
Date: Thu, 10 Oct 2024 23:39:11 +0200 [thread overview]
Message-ID: <CA+fCnZfs6bwdxkKPWWdNCjFH6H6hs0pFjaic12=HgB4b=Vv-xw@mail.gmail.com> (raw)
In-Reply-To: <20241010131130.2903601-1-snovitoll@gmail.com>
On Thu, Oct 10, 2024 at 3:10 PM Sabyrzhan Tasbolatov
<snovitoll@gmail.com> wrote:
>
> diff --git a/mm/kasan/kasan_test_c.c b/mm/kasan/kasan_test_c.c
> index a181e4780d9d..cb6ad84641ec 100644
> --- a/mm/kasan/kasan_test_c.c
> +++ b/mm/kasan/kasan_test_c.c
> @@ -1954,6 +1954,42 @@ static void rust_uaf(struct kunit *test)
> KUNIT_EXPECT_KASAN_FAIL(test, kasan_test_rust_uaf());
> }
>
> +static void copy_to_kernel_nofault_oob(struct kunit *test)
> +{
> + char *ptr;
> + char buf[128];
> + size_t size = sizeof(buf);
> +
> + /* This test currently fails with the HW_TAGS mode.
> + * The reason is unknown and needs to be investigated. */
> + ptr = kmalloc(size - KASAN_GRANULE_SIZE, GFP_KERNEL);
> + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr);
> + OPTIMIZER_HIDE_VAR(ptr);
> +
> + if (IS_ENABLED(CONFIG_KASAN_SW_TAGS)) {
> + /* Check that the returned pointer is tagged. */
> + KUNIT_EXPECT_GE(test, (u8)get_tag(ptr), (u8)KASAN_TAG_MIN);
> + KUNIT_EXPECT_LT(test, (u8)get_tag(ptr), (u8)KASAN_TAG_KERNEL);
> + }
It appears you deleted a wrong check. I meant the checks above, not
the CONFIG_KASAN_HW_TAGS one.
> +
> + /*
> + * We test copy_to_kernel_nofault() to detect corrupted memory that is
> + * being written into the kernel. In contrast, copy_from_kernel_nofault()
> + * is primarily used in kernel helper functions where the source address
> + * might be random or uninitialized. Applying KASAN instrumentation to
> + * copy_from_kernel_nofault() could lead to false positives.
> + * By focusing KASAN checks only on copy_to_kernel_nofault(),
> + * we ensure that only valid memory is written to the kernel,
> + * minimizing the risk of kernel corruption while avoiding
> + * false positives in the reverse case.
> + */
> + KUNIT_EXPECT_KASAN_FAIL(test,
> + copy_to_kernel_nofault(&buf[0], ptr, size));
> + KUNIT_EXPECT_KASAN_FAIL(test,
> + copy_to_kernel_nofault(ptr, &buf[0], size));
Nit: empty line before kfree.
> + kfree(ptr);
> +}
next prev parent reply other threads:[~2024-10-10 21:39 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-05 9:23 [PATCH] mm, kmsan: instrument copy_from_kernel_nofault Sabyrzhan Tasbolatov
2024-10-05 10:36 ` Marco Elver
2024-10-05 16:48 ` [PATCH v2 0/1] mm, kasan, kmsan: copy_from/to_kernel_nofault Sabyrzhan Tasbolatov
2024-10-05 16:48 ` [PATCH v2 1/1] " Sabyrzhan Tasbolatov
2024-10-08 8:31 ` Marco Elver
2024-10-08 8:46 ` Sabyrzhan Tasbolatov
2024-10-08 9:27 ` Marco Elver
2024-10-08 10:15 ` [PATCH v3] " Sabyrzhan Tasbolatov
2024-10-08 11:35 ` Marco Elver
2024-10-08 19:29 ` [PATCH v4] " Sabyrzhan Tasbolatov
2024-10-08 19:34 ` Marco Elver
2024-10-08 19:42 ` Sabyrzhan Tasbolatov
2024-10-09 21:39 ` Andrew Morton
2024-10-09 20:18 ` Andrey Konovalov
2024-10-09 20:34 ` Marco Elver
2024-10-10 13:11 ` [PATCH v5] " Sabyrzhan Tasbolatov
2024-10-10 21:39 ` Andrey Konovalov [this message]
2024-10-11 3:53 ` [PATCH v6] " Sabyrzhan Tasbolatov
2024-10-12 22:45 ` Andrey Konovalov
2024-10-15 11:05 ` Sabyrzhan Tasbolatov
2024-10-08 19:39 ` [PATCH v3] " Sabyrzhan Tasbolatov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CA+fCnZfs6bwdxkKPWWdNCjFH6H6hs0pFjaic12=HgB4b=Vv-xw@mail.gmail.com' \
--to=andreyknvl@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=bpf@vger.kernel.org \
--cc=dvyukov@google.com \
--cc=elver@google.com \
--cc=glider@google.com \
--cc=kasan-dev@googlegroups.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ryabinin.a.a@gmail.com \
--cc=snovitoll@gmail.com \
--cc=syzbot+61123a5daeb9f7454599@syzkaller.appspotmail.com \
--cc=vincenzo.frascino@arm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox