From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932068AbdHWOA1 (ORCPT ); Wed, 23 Aug 2017 10:00:27 -0400 Received: from mout.kundenserver.de ([212.227.17.13]:59208 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754001AbdHWOAZ (ORCPT ); Wed, 23 Aug 2017 10:00:25 -0400 From: Arnd Bergmann To: Harish Patil , Manish Chopra , Dept-GELinuxNICDev@cavium.com Cc: Arnd Bergmann , stable@vger.kernel.org, "David S. Miller" , Kees Cook , "Gustavo A. R. Silva" , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] [net-next] qlge: avoid memcpy buffer overflow Date: Wed, 23 Aug 2017 15:59:49 +0200 Message-Id: <20170823135958.1379527-1-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 X-Provags-ID: V03:K0:TU1e+L20TrqTTjlcHJ0VEJDTGH+ZBqzEf7AsD6pUd3GUsohD5jK MFqU9dw8SIKM1nobq9uR49wBBWs1aYD+51D4J0vSjPP72RB4Zn81+H3FP7uPj5s1f6wdXeU gg17PyV+21pcIwC2rLhm8DiN07NG8N0Rrc1hr/TFE9jiWME4fBjVmePLZE7P1bVGhGI3ZM9 SQGwJHgafFQUMApVdJgQw== X-UI-Out-Filterresults: notjunk:1;V01:K0:Wh1sPM98ALM=:Keb4z8fgYF3r7+o1bK7MHf USmcvnWtHWsb2AQmmEYLlSK2x0Dn+Q+V3jyqfDErWnDkcQSmtmgrBPeWoeFq49SsDmeQsCDXT 4h/osBC5pe46nkHUTeRdUIg2YT56F8kHvk/J4gqb2uE5CTaxEe7bi5PykMH06EWEaCltT5bBo Fg48wCuzJX9H/MbeIsp1X2DXOFXu+4NgoyASyMpu5teJzt8Wg25ia/CMD5zGeEf2KsO95//J4 9ttrNxodnRbL5JBpe/oJ3uzUfffQjSehLUk3USKGAtf5NoCHbaK2l16R4BE11M7BYvbBjnxB9 hgxoL7c99+MPL6CYduGwxt8q9VxB7NU+Twy+YhMgVX0O3CZ6RAaqKv9wjpXGe6IWtckuiyR6L E371Ih5X+svd2Z359rBUtW0Li2GBoHLuDzI6+ws9GoDo72kE2rYv8GwNDjO8R69AfiSd/NAFX FD6tMfnWRku2mT67Rlf1WL6IY/NDitA0Tjlj3+TrWL7GQrMyYvLujaHGL1ErQGcznTn9z7qt8 sfmMRYilA9A55tMez2RUhjjSyohllfzVgf7+3bBQdnfLE3Xg+a+5PXRqPY5gbveng8karAdcl wDirNVidZ0d+t2FlPUY2Q+KuUQnUtKxQ5hXNqZKTBh2u97hpRIwLec4zAvfl+0G/7aXpc0X3Q m2oEM00PY+890tq7GfFkayQeql4r1hzG4OKCO31XLwQnLRkWcr8FugqYgsoFb2vluUrrstHBn 2A4qoScbpwUw9+0/A0ZtqTqdA9s50Xde7Soewg== Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Cc: stable@vger.kernel.org Fixes: a61f80261306 ("qlge: Add ethtool register dump function.") Signed-off-by: Arnd Bergmann --- 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(-) diff --git a/drivers/net/ethernet/qlogic/qlge/qlge_dbg.c b/drivers/net/ethernet/qlogic/qlge/qlge_dbg.c index 458d55ba423f..fe2599b83d09 100644 --- a/drivers/net/ethernet/qlogic/qlge/qlge_dbg.c +++ b/drivers/net/ethernet/qlogic/qlge/qlge_dbg.c @@ -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); } /* -- 2.9.0