mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrey Ryabinin <aryabinin@virtuozzo.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
	Rasmus Villemoes <rasmus.villemoes@prevas.dk>,
	linux-kernel@vger.kernel.org, Dmitry Vyukov <dvyukov@google.com>,
	Kees Cook <keescook@chromium.org>, Eryu Guan <eguan@redhat.com>,
	Alexander Potapenko <glider@google.com>,
	Chris Metcalf <metcalf@alum.mit.edu>,
	David Laight <David.Laight@aculab.com>,
	kasan-dev <kasan-dev@googlegroups.com>,
	Alexander Viro <viro@zeniv.linux.org.uk>,
	Andrey Ryabinin <aryabinin@virtuozzo.com>
Subject: [PATCH 3/5] lib/strscpy: Shut up KASAN false-positives in strscpy()
Date: Thu,  1 Feb 2018 21:00:50 +0300	[thread overview]
Message-ID: <20180201180052.32643-3-aryabinin@virtuozzo.com> (raw)
In-Reply-To: <20180201180052.32643-1-aryabinin@virtuozzo.com>

strscpy() performs the word-at-a-time optimistic reads. So it may
may access the memory past the end of the object, which is perfectly fine
since strscpy() doesn't use that (past-the-end) data and makes sure the
optimistic read won't cross a page boundary.

Use new read_word_at_a_time() to shut up the KASAN.

Note that this potentially could hide some bugs. In example bellow,
stscpy() will copy more than we should (1-3 extra uninitialized bytes):

        char dst[8];
        char *src;

        src = kmalloc(5, GFP_KERNEL);
        memset(src, 0xff, 5);
        strscpy(dst, src, 8);

Signed-off-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
---
 lib/string.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/string.c b/lib/string.c
index 64a9e33f1daa..2c0900a5d51a 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -203,7 +203,7 @@ ssize_t strscpy(char *dest, const char *src, size_t count)
 	while (max >= sizeof(unsigned long)) {
 		unsigned long c, data;
 
-		c = *(unsigned long *)(src+res);
+		c = read_word_at_a_time(src+res);
 		if (has_zero(c, &data, &constants)) {
 			data = prep_zero_mask(c, data, &constants);
 			data = create_zero_mask(data);
-- 
2.13.6

  parent reply	other threads:[~2018-02-01 18:01 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-01 18:00 [PATCH 1/5] compiler.h, kasan: Avoid duplicating __read_once_size_nocheck() Andrey Ryabinin
2018-02-01 18:00 ` [PATCH 2/5] compiler.h: Add read_word_at_a_time() function Andrey Ryabinin
2018-02-01 18:00 ` Andrey Ryabinin [this message]
2018-02-01 18:00 ` [PATCH 4/5] fs/dcache: Use read_word_at_a_time() in dentry_string_cmp() Andrey Ryabinin
2018-02-01 18:00 ` [PATCH 5/5] fs: dcache: Revert "manually unpoison dname after allocation to shut up kasan's reports" Andrey Ryabinin
2018-02-01 18:28 ` [PATCH 1/5] compiler.h, kasan: Avoid duplicating __read_once_size_nocheck() Linus Torvalds
2018-02-01 20:14   ` Andrey Ryabinin
2018-02-01 20:26     ` Linus Torvalds

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=20180201180052.32643-3-aryabinin@virtuozzo.com \
    --to=aryabinin@virtuozzo.com \
    --cc=David.Laight@aculab.com \
    --cc=akpm@linux-foundation.org \
    --cc=dvyukov@google.com \
    --cc=eguan@redhat.com \
    --cc=glider@google.com \
    --cc=kasan-dev@googlegroups.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=metcalf@alum.mit.edu \
    --cc=rasmus.villemoes@prevas.dk \
    --cc=torvalds@linux-foundation.org \
    --cc=viro@zeniv.linux.org.uk \
    /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

all inboxes | Powered by JetHome®