]> git.baikalelectronics.ru Git - kernel.git/commit
ext4: fix warning about stack corruption
authorArnd Bergmann <arnd@arndb.de>
Sun, 6 Aug 2017 01:57:46 +0000 (21:57 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Sun, 6 Aug 2017 01:57:46 +0000 (21:57 -0400)
commit882a543852a5d2e52e3f2b30d527eb27080783b6
treea4dd4d788489bb17f724d029988e7c2b8a4f3c7e
parentfe76c9c6670700a1ceda157339b3972ba72fda72
ext4: fix warning about stack corruption

After commit 62d1034f53e3 ("fortify: use WARN instead of BUG for now"),
we get a warning about possible stack overflow from a memcpy that
was not strictly bounded to the size of the local variable:

    inlined from 'ext4_mb_seq_groups_show' at fs/ext4/mballoc.c:2322:2:
include/linux/string.h:309:9: error: '__builtin_memcpy': writing between 161 and 1116 bytes into a region of size 160 overflows the destination [-Werror=stringop-overflow=]

We actually had a bug here that would have been found by the warning,
but it was already fixed last year in commit 9e7de93563e2 ("ext4: fix
stack memory corruption with 64k block size").

This replaces the fixed-length structure on the stack with a variable-length
structure, using the correct upper bound that tells the compiler that
everything is really fine here. I also change the loop count to check
for the same upper bound for consistency, but the existing code is
already correct here.

Note that while clang won't allow certain kinds of variable-length arrays
in structures, this particular instance is fine, as the array is at the
end of the structure, and the size is strictly bounded.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
fs/ext4/mballoc.c