From: Sabyrzhan Tasbolatov <snovitoll@gmail.com>
To: Andrey Konovalov <andreyknvl@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
2023002089@link.tyut.edu.cn, alexs@kernel.org, corbet@lwn.net,
dvyukov@google.com, elver@google.com, glider@google.com,
kasan-dev@googlegroups.com, linux-doc@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-mm@kvack.org,
ryabinin.a.a@gmail.com, siyanteng@loongson.cn,
vincenzo.frascino@arm.com, workflows@vger.kernel.org
Subject: Re: [PATCH RESEND v3 2/3] kasan: migrate copy_user_test to kunit
Date: Tue, 15 Oct 2024 15:53:35 +0500 [thread overview]
Message-ID: <CACzwLxgJaOL9RXkhAZEosmFDzp-D4=gGfhSh3d5scBRBaq76pw@mail.gmail.com> (raw)
In-Reply-To: <CA+fCnZcwoL3qWhKsmgCCPDeAW0zpKGn=H7F8w8Fmsg+7-Y8p3g@mail.gmail.com>
On Tue, Oct 15, 2024 at 6:18 AM Andrey Konovalov <andreyknvl@gmail.com> wrote:
>
> On Tue, Oct 15, 2024 at 1:10 AM Andrew Morton <akpm@linux-foundation.org> wrote:
> >
> > On Mon, 14 Oct 2024 07:57:00 +0500 Sabyrzhan Tasbolatov <snovitoll@gmail.com> wrote:
> >
> > > Migrate the copy_user_test to the KUnit framework to verify out-of-bound
> > > detection via KASAN reports in copy_from_user(), copy_to_user() and
> > > their static functions.
> > >
> > > This is the last migrated test in kasan_test_module.c, therefore delete
> > > the file.
> > >
> >
> > x86_64 allmodconfig produces:
> >
> > vmlinux.o: warning: objtool: strncpy_from_user+0x8a: call to __check_object_size() with UACCESS enabled
I've missed this warning during x86_64 build, sorry.
>
> Too bad. I guess we have to duplicate both kasan_check_write and
> check_object_size before both do_strncpy_from_user calls in
> strncpy_from_user.
Shall we do it once in strncpy_from_user() as I did in v1?
Please let me know as I've tested in x86_64 and arm64 -
there is no warning during kernel build with the diff below.
These checks are for kernel pointer *dst only and size:
kasan_check_write(dst, count);
check_object_size(dst, count, false);
And there are 2 calls of do_strncpy_from_user,
which are implemented in x86 atm per commit 2865baf54077,
and they are relevant to __user *src address, AFAIU.
long strncpy_from_user()
if (can_do_masked_user_access()) {
src = masked_user_access_begin(src);
retval = do_strncpy_from_user(dst, src, count, count);
user_read_access_end();
}
if (likely(src_addr < max_addr)) {
if (user_read_access_begin(src, max)) {
retval = do_strncpy_from_user(dst, src, count, max);
user_read_access_end();
---
diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
index 989a12a6787..6dc234913dd 100644
--- a/lib/strncpy_from_user.c
+++ b/lib/strncpy_from_user.c
@@ -120,6 +120,9 @@ long strncpy_from_user(char *dst, const char
__user *src, long count)
if (unlikely(count <= 0))
return 0;
+ kasan_check_write(dst, count);
+ check_object_size(dst, count, false);
+
if (can_do_masked_user_access()) {
long retval;
@@ -142,8 +145,6 @@ long strncpy_from_user(char *dst, const char
__user *src, long count)
if (max > count)
max = count;
- kasan_check_write(dst, count);
- check_object_size(dst, count, false);
if (user_read_access_begin(src, max)) {
retval = do_strncpy_from_user(dst, src, count, max);
user_read_access_end();
next prev parent reply other threads:[~2024-10-15 10:52 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-11 7:16 [PATCH] kasan: migrate copy_user_test to kunit Sabyrzhan Tasbolatov
2024-10-11 9:13 ` Sabyrzhan Tasbolatov
2024-10-12 22:49 ` Andrey Konovalov
2024-10-13 6:33 ` Sabyrzhan Tasbolatov
2024-10-12 22:46 ` Andrey Konovalov
2024-10-13 13:02 ` [PATCH v2 0/3] kasan: migrate the last module test " Sabyrzhan Tasbolatov
2024-10-13 13:02 ` [PATCH v2 1/3] kasan: move checks to do_strncpy_from_user Sabyrzhan Tasbolatov
2024-10-13 16:04 ` Andrey Konovalov
2024-10-13 13:02 ` [PATCH v2 2/3] kasan: migrate copy_user_test to kunit Sabyrzhan Tasbolatov
2024-10-13 16:02 ` Andrey Konovalov
2024-10-13 18:20 ` [PATCH v3 " Sabyrzhan Tasbolatov
2024-10-13 20:25 ` Andrey Konovalov
2024-10-14 2:56 ` [PATCH RESEND v3 0/3] kasan: migrate the last module test " Sabyrzhan Tasbolatov
2024-10-14 2:56 ` [PATCH RESEND v3 1/3] kasan: move checks to do_strncpy_from_user Sabyrzhan Tasbolatov
2024-10-14 2:57 ` [PATCH RESEND v3 2/3] kasan: migrate copy_user_test to kunit Sabyrzhan Tasbolatov
2024-10-14 23:10 ` Andrew Morton
2024-10-15 1:18 ` Andrey Konovalov
2024-10-15 10:53 ` Sabyrzhan Tasbolatov [this message]
2024-10-15 23:16 ` Andrey Konovalov
2024-10-16 13:17 ` [PATCH v4 0/3] kasan: migrate the last module test " Sabyrzhan Tasbolatov
2024-10-16 13:18 ` [PATCH v4 1/3] kasan: move checks to do_strncpy_from_user Sabyrzhan Tasbolatov
2024-10-16 13:18 ` [PATCH v4 2/3] kasan: migrate copy_user_test to kunit Sabyrzhan Tasbolatov
2024-10-16 13:18 ` [PATCH v4 3/3] kasan: delete CONFIG_KASAN_MODULE_TEST Sabyrzhan Tasbolatov
2024-10-14 2:57 ` [PATCH RESEND v3 " Sabyrzhan Tasbolatov
2024-10-13 13:02 ` [PATCH v2 " Sabyrzhan Tasbolatov
2024-10-13 16:03 ` Andrey Konovalov
2024-10-13 18:21 ` [PATCH v3 " Sabyrzhan Tasbolatov
2024-10-13 20:25 ` Andrey Konovalov
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='CACzwLxgJaOL9RXkhAZEosmFDzp-D4=gGfhSh3d5scBRBaq76pw@mail.gmail.com' \
--to=snovitoll@gmail.com \
--cc=2023002089@link.tyut.edu.cn \
--cc=akpm@linux-foundation.org \
--cc=alexs@kernel.org \
--cc=andreyknvl@gmail.com \
--cc=corbet@lwn.net \
--cc=dvyukov@google.com \
--cc=elver@google.com \
--cc=glider@google.com \
--cc=kasan-dev@googlegroups.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ryabinin.a.a@gmail.com \
--cc=siyanteng@loongson.cn \
--cc=vincenzo.frascino@arm.com \
--cc=workflows@vger.kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).