Commit 1a3241ff authored by Andrey Ryabinin's avatar Andrey Ryabinin Committed by Linus Torvalds

lib/strscpy: Shut up KASAN false-positives in strscpy()

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: default avatarAndrey Ryabinin <aryabinin@virtuozzo.com>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 7f1e541f
...@@ -203,7 +203,7 @@ ssize_t strscpy(char *dest, const char *src, size_t count) ...@@ -203,7 +203,7 @@ ssize_t strscpy(char *dest, const char *src, size_t count)
while (max >= sizeof(unsigned long)) { while (max >= sizeof(unsigned long)) {
unsigned long c, data; unsigned long c, data;
c = *(unsigned long *)(src+res); c = read_word_at_a_time(src+res);
if (has_zero(c, &data, &constants)) { if (has_zero(c, &data, &constants)) {
data = prep_zero_mask(c, data, &constants); data = prep_zero_mask(c, data, &constants);
data = create_zero_mask(data); data = create_zero_mask(data);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment