Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp3581870imm; Mon, 13 Aug 2018 14:28:55 -0700 (PDT) X-Google-Smtp-Source: AA+uWPw1SqbAYIKmG2X7YE4cVqQfwRSPqxylRHpRCMR6/gxA+W0q1uOxSmFiFtXCiiBNkScuWBmv X-Received: by 2002:a62:93d4:: with SMTP id r81-v6mr20365764pfk.55.1534195735372; Mon, 13 Aug 2018 14:28:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534195735; cv=none; d=google.com; s=arc-20160816; b=Cpd/6Fac4seY8QiL01jz05B+ZoZrNakepbUcmXT9VqfOhI61LsKAmScOSaxFSGLMgp xbgfdsaSbh+Dk08X99QEKsOVvAkhvBxg7tL/1htJ/qMeUruu0kIxnnpRjPPej7TKZZHX 7CuVx0FsUugl98Oh6afhjIyGjgE8CnF2zYIpfOtUoyE0DkJoylarbJcP1b2bn/ps9CiG Qfoum6PcuWISiyu+KqSTVrv3Ugnb9kp157TDTp3/ODTsTH92+JgcsUm51rYuiuLgqsH3 QxAegiz8FHtLqDIHcYZfmEHsqiGq/DoyAsOfjlFS7xeGIdhVVr7tVqLoGpWkcDjL/h4n 5yuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=XF/aSDeNTlDcWLygopA6Hy98hoLeqUiaTG/VtXAJbKk=; b=TP1rPEVeL+22JF/DTHYSxIelAntvtlys8KFwS+Oj/VuxTpikX3svCwR+QIUIN1V9q6 obfRo0CsP88jy4cX5Lofub70tKRY0x4vT33+1eW9X3h5GGNG6khWPU8sEb3OtIDoCcA2 2rnLtq2Lcx5a0uwz/ZR/tISSIanQhsUHiLRYnInlOHlHQdTU+0iAopvFVhmTWBg6CP+l X8d1tAx5Sov9ml71SBN2eXoVNY01qTMtM/sEu6LIgtDBDkPYYwtI4wHjv7PZsRdP0CxF 5TolWBtRwZGmKg1ENqiK1AqSBouBLgW1IykUEUGzDASLuEdec2xoULuqMhPdcYJqbDuL 9vxQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f89-v6si15156770plf.20.2018.08.13.14.28.39; Mon, 13 Aug 2018 14:28:55 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730438AbeHNALG (ORCPT + 99 others); Mon, 13 Aug 2018 20:11:06 -0400 Received: from mout.kundenserver.de ([212.227.126.133]:44585 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729245AbeHNALG (ORCPT ); Mon, 13 Aug 2018 20:11:06 -0400 Received: from wuerfel.lan ([109.193.40.16]) by mrelayeu.kundenserver.de (mreue002 [212.227.15.129]) with ESMTPA (Nemesis) id 0M16aW-1g8vcM2BFA-00tC3M; Mon, 13 Aug 2018 23:27:02 +0200 From: Arnd Bergmann To: Michael Chan , "David S. Miller" Cc: Arnd Bergmann , Vasundhara Volam , Scott Branden , Andy Gospodarek , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] bnxt_en: avoid string overflow for record->system_name Date: Mon, 13 Aug 2018 23:26:54 +0200 Message-Id: <20180813212700.2681499-1-arnd@arndb.de> X-Mailer: git-send-email 2.18.0 X-Provags-ID: V03:K1:gH6T27BtgypcwrQwANOFw6VbcUIQ7DkW+PBxph1zc2WO063OYYW 2zQ6k+BKwShTWB76QKb4x1QhTP5aotQ78Q8yWzzLmYic0aD822fwoLepOIkft/Z+lAw9sFB Yf1HogllWYCOk3kv2kItROR5gYmp1/1JvuUc651iarMKKDEaBH/kffc7Rm6WVmtrjd22O6r zkGlZiB+msOSCTp7CeIjQ== X-UI-Out-Filterresults: notjunk:1;V01:K0:UElvnY30Nu8=:EfGJLYWqscyl6H/hyYt81x cjjUqengUYR5b+pKESXvBMt+W0r4ko5f19S9jFQKAPt1dnMiEt4HyRqEiE7FAmGWNb6NpoCdM 9FnZbk7in0Z7gYk56NFWd9/AVFGX0SCYPXJjBu7kCdWjBYg+PxzEfYRfmkEcrc6J4OY3851co 4+2dMkodAdhgrHzVGZMnr7QpaJhx8ozbOKTboAYpE+UEcAiPbRMAs8eQR7yyBcHd5ZcaYf7Wv U35vHG7VTbsnUPbdcDsCydekOivNmWG4vA+gS+RNRJjzRQDHAQOLWbwJ0TUzNc3ouOMYyjV78 4PHdYpxKVhPIZ1r96rbe5afi7+bbVFNkrzLp7syZUEqWIUB2pQaqdikEy247Yv1OqBz2rkgST YByhyc+CVIVPOAO7ZEFJuxgMWAX8uZfqNkpiki30MdkwMhTR9ZPuIs/wWOwPiC0WIYExQebyP jgyuOURmu7KXVQe3FDc+zfZz8PPImy2RjZzt40m4svP4tbqMSLRaWnP1T1+Cgze/t+KOf5oT5 xAa4pW6RSHc+1v9+2uB8PDNPPuuQG+xZurZDaBDp0OUL+nmtifhC3SO3faexm3KQLxDBwshyF MauVV+S8jw9fAX1gPMzassRPwLQJvANm9+cJHmFF3g25kIACTvne/c6gJvSQ8Fl+ZR2gQqEgK MlrdYxIsXtac2Vayon2FqeMeelxD93ZmVC8ZPgVdWerrzQdii4NWQhnRtHGinhDEp0/E= Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The utsname()->nodename string may be 64 bytes long, and it gets copied without the trailing nul byte into the shorter record->system_name, as gcc now warns: In file included from include/linux/bitmap.h:9, from include/linux/ethtool.h:16, from drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c:13: In function 'strncpy', inlined from 'bnxt_fill_coredump_record' at drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c:2863:2: include/linux/string.h:254:9: error: '__builtin_strncpy' output truncated before terminating nul copying as many bytes from a string as its length [-Werror=stringop-truncation] Using strlcpy() at least avoids overflowing the destination buffer and adds proper nul-termination. It may still truncate long names though, which probably can't be solved here. Fixes: 6c5657d085ae ("bnxt_en: Add support for ethtool get dump.") Signed-off-by: Arnd Bergmann --- drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c b/drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c index b1602ea64372..e52d7af3ab3e 100644 --- a/drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c @@ -2860,8 +2860,8 @@ bnxt_fill_coredump_record(struct bnxt *bp, struct bnxt_coredump_record *record, record->low_version = 0; record->high_version = 1; record->asic_state = 0; - strncpy(record->system_name, utsname()->nodename, - strlen(utsname()->nodename)); + strlcpy(record->system_name, utsname()->nodename, + sizeof(record->system_name)); record->year = cpu_to_le16(tm.tm_year); record->month = cpu_to_le16(tm.tm_mon); record->day = cpu_to_le16(tm.tm_mday); -- 2.18.0