qlge: avoid memcpy buffer overflow
Subsystems (3)
PATCH 1/1 qlge: avoid memcpy buffer overflow
gcc-8.0.0 (snapshot) points out that we copy a variable-length string into a fixed length field using memcpy() with the destination length, and that ends up copying whatever follows the string:
inlined from 'ql_core_dump' at drivers/net/ethernet/qlogic/qlge/qlge_dbg.c:1106:2:drivers/net/ethernet/qlogic/qlge/qlge_dbg.c:708:2: error: 'memcpy' reading 15 bytes from a region of size 14 [-Werror=stringop-overflow=]
memcpy(seg_hdr->description, desc, (sizeof(seg_hdr->description)) - 1);
Changing it to use strncpy() will instead zero-pad the destination, which seems to be the right thing to do here.
The bug is probably harmless, but it seems like a good idea to address it in stable kernels as well, if only for the purpose of building with gcc-8 without warnings.
---
Doesn't seem urgent to me, so please queue it for net-next if it looks ok.
Interestingly, the hardened memcpy() functions in linux/string.h never caught this problem event though I think they should have, but gcc-8 found it by default.
--- drivers/net/ethernet/qlogic/qlge/qlge_dbg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/qlogic/qlge/qlge_dbg.c +1 -1
@@ -705,7 +705,7 @@ static void ql_build_coredump_seg_header( seg_hdr->cookie =MPI_COREDUMP_COOKIE ; seg_hdr->segNum = seg_number; seg_hdr->segSize = seg_size; -memcpy (seg_hdr->description, desc, (sizeof (seg_hdr->description)) -1 ); +strncpy (seg_hdr->description, desc, (sizeof (seg_hdr->description)) -1 ); }/*
Signature · 1 line
2.9.0
From: Arnd Bergmann <[email protected]>
Date: Wed, 23 Aug 2017 15:59:49 +0200
Quoted 8 lines
gcc-8.0.0 (snapshot) points out that we copy a variable-length string into a fixed length field using
memcpy()with the destination length, and that ends up copying whatever follows the string:inlined from '
ql_core_dump' atdrivers/net/ethernet/qlogic/qlge/qlge_dbg.c:1106:2:drivers/net/ethernet/qlogic/qlge/qlge_dbg.c:708:2: error: 'memcpy' reading 15 bytes from a region of size 14 [-Werror=stringop-overflow=]
memcpy(seg_hdr->description, desc, (sizeof(seg_hdr->description)) - 1);
Quoted 8 lines
Changing it to use
strncpy()will instead zero-pad the destination, which seems to be the right thing to do here.The bug is probably harmless, but it seems like a good idea to address it in stable kernels as well, if only for the purpose of building with gcc-8 without warnings.
Please don't use explicit stable CC:'ing for networking changes.
Quoted 2 lines
Fixes a61f80261306 ("qlge: Add ethtool register dump function.")Signed-off-by Arnd Bergmann <[email protected]>
Applied to 'net' and queued up for -stable, thanks.