linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Sabyrzhan Tasbolatov <snovitoll@gmail.com>
To: andreyknvl@gmail.com
Cc: akpm@linux-foundation.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, snovitoll@gmail.com,
	vincenzo.frascino@arm.com, elver@google.com, corbet@lwn.net,
	alexs@kernel.org, siyanteng@loongson.cn,
	2023002089@link.tyut.edu.cn, workflows@vger.kernel.org,
	linux-doc@vger.kernel.org
Subject: [PATCH v2 1/3] kasan: move checks to do_strncpy_from_user
Date: Sun, 13 Oct 2024 18:02:09 +0500	[thread overview]
Message-ID: <20241013130211.3067196-2-snovitoll@gmail.com> (raw)
In-Reply-To: <20241013130211.3067196-1-snovitoll@gmail.com>

Since in the commit 2865baf54077("x86: support user address masking instead
of non-speculative conditional") do_strncpy_from_user() is called from
multiple places, we should sanitize the kernel *dst memory and size
which were done in strncpy_from_user() previously.

Fixes: 2865baf54077 ("x86: support user address masking instead of non-speculative conditional")
Signed-off-by: Sabyrzhan Tasbolatov <snovitoll@gmail.com>
---
 lib/strncpy_from_user.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
index 989a12a6787..f36ad821176 100644
--- a/lib/strncpy_from_user.c
+++ b/lib/strncpy_from_user.c
@@ -31,6 +31,9 @@ static __always_inline long do_strncpy_from_user(char *dst, const char __user *s
 	const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
 	unsigned long res = 0;
 
+	kasan_check_write(dst, count);
+	check_object_size(dst, count, false);
+
 	if (IS_UNALIGNED(src, dst))
 		goto byte_at_a_time;
 
@@ -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();
-- 
2.34.1



  reply	other threads:[~2024-10-13 13:01 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     ` Sabyrzhan Tasbolatov [this message]
2024-10-13 16:04       ` [PATCH v2 1/3] kasan: move checks to do_strncpy_from_user 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
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=20241013130211.3067196-2-snovitoll@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).