Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

wlcore: Fix buffer overrun by snprintf due to incorrect buffer size

The size of the buffer than can be written to is currently incorrect, it is
always the size of the entire buffer even though the snprintf is writing
as position pos into the buffer. Fix this by setting the buffer size to be
the number of bytes left in the buffer, namely sizeof(buf) - pos.

Addresses-Coverity: ("Out-of-bounds access")
Fixes: 7b0e2c4f6be3 ("wlcore: fix overlapping snprintf arguments in debugfs")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
Link: https://lore.kernel.org/r/20210419141405.180582-1-colin.king@canonical.com

authored by

Colin Ian King and committed by
Kalle Valo
a9a4c080 bb43e571

+1 -1
+1 -1
drivers/net/wireless/ti/wlcore/debugfs.h
··· 84 84 wl1271_debugfs_update_stats(wl); \ 85 85 \ 86 86 for (i = 0; i < len && pos < sizeof(buf); i++) \ 87 - pos += snprintf(buf + pos, sizeof(buf), \ 87 + pos += snprintf(buf + pos, sizeof(buf) - pos, \ 88 88 "[%d] = %d\n", i, stats->sub.name[i]); \ 89 89 \ 90 90 return wl1271_format_buffer(userbuf, count, ppos, "%s", buf); \