linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Sabyrzhan Tasbolatov <snovitoll@gmail.com>
To: akpm@linux-foundation.org, dvyukov@google.com
Cc: andreyknvl@gmail.com, linux-mm@kvack.org,
	linux-kernel@vger.kernel.org, snovitoll@gmail.com
Subject: [PATCH] mm, kasan: proper instrument _kernel_nofault
Date: Mon, 30 Sep 2024 15:24:05 +0500	[thread overview]
Message-ID: <20240930102405.2227124-1-snovitoll@gmail.com> (raw)

In commit 88ad9dc30bbf("mm, kasan: instrument
copy_from/to_kernel_nofault"), both src and dst were checked which might
lead to the false-positive reports.

Regular instrument_read() for copy_from and instrument_write() for
copy_to triggers KASAN reports in mm/kasan_test_c.c
copy_from_to_kernel_nofault_oob() kunit test.

Tested on x86_64, arm64 with CONFIG_KASAN_SW_TAGS using the latest linux-next
tree, where this commit has been merged today.

Reported-by: Dmitry Vyukov <dvyukov@google.com>
Closes: https://bugzilla.kernel.org/show_bug.cgi?id=210505
Signed-off-by: Sabyrzhan Tasbolatov <snovitoll@gmail.com>
---
 mm/maccess.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/mm/maccess.c b/mm/maccess.c
index 2c4251df46c..f752f0c0fa3 100644
--- a/mm/maccess.c
+++ b/mm/maccess.c
@@ -32,7 +32,7 @@ long copy_from_kernel_nofault(void *dst, const void *src, size_t size)
 		return -ERANGE;
 
 	pagefault_disable();
-	instrument_memcpy_before(dst, src, size);
+	instrument_read(src, size);
 	if (!(align & 7))
 		copy_from_kernel_nofault_loop(dst, src, size, u64, Efault);
 	if (!(align & 3))
@@ -40,7 +40,6 @@ long copy_from_kernel_nofault(void *dst, const void *src, size_t size)
 	if (!(align & 1))
 		copy_from_kernel_nofault_loop(dst, src, size, u16, Efault);
 	copy_from_kernel_nofault_loop(dst, src, size, u8, Efault);
-	instrument_memcpy_after(dst, src, size, 0);
 	pagefault_enable();
 	return 0;
 Efault:
@@ -65,7 +64,7 @@ long copy_to_kernel_nofault(void *dst, const void *src, size_t size)
 		align = (unsigned long)dst | (unsigned long)src;
 
 	pagefault_disable();
-	instrument_memcpy_before(dst, src, size);
+	instrument_write(dst, size);
 	if (!(align & 7))
 		copy_to_kernel_nofault_loop(dst, src, size, u64, Efault);
 	if (!(align & 3))
@@ -73,7 +72,6 @@ long copy_to_kernel_nofault(void *dst, const void *src, size_t size)
 	if (!(align & 1))
 		copy_to_kernel_nofault_loop(dst, src, size, u16, Efault);
 	copy_to_kernel_nofault_loop(dst, src, size, u8, Efault);
-	instrument_memcpy_after(dst, src, size, 0);
 	pagefault_enable();
 	return 0;
 Efault:
-- 
2.34.1



                 reply	other threads:[~2024-09-30 10:23 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20240930102405.2227124-1-snovitoll@gmail.com \
    --to=snovitoll@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=andreyknvl@gmail.com \
    --cc=dvyukov@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.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).