From patchwork Mon Aug 13 21:26:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 144045 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp3545897ljj; Mon, 13 Aug 2018 14:27:11 -0700 (PDT) X-Google-Smtp-Source: AA+uWPzhQeCubC3R4Vqzj0vCeRBoiDq6qMGKvopEP+oRusqvMoKn1QOEDPxelDbn1+OmzG13P/ao X-Received: by 2002:a65:58c8:: with SMTP id e8-v6mr3426941pgu.96.1534195631567; Mon, 13 Aug 2018 14:27:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534195631; cv=none; d=google.com; s=arc-20160816; b=rGtQG3gjX7M6aYmDbZz/JXhKpvvobbL9G9OplZJrq5DtDac+eZi30KzuvUJZhjj9Zo 7o7jy8yBn/aHNQ2/slkgELzq4nu5CBf5AYpJ9KHrX+ibVThXbZxWCOeiubjg8llfCMPH JkJfupAXLXYJ0i+/eT/ZQul3LcTdB0G0MmWZymqfprTo4lbUySUH4fZdI4n6OlwzCavW L53wG6USwloBAVKWE7T1AgBtR9mft/A2wS8gzqDRvneTSlWVOBmCq7ecBUyGopEU7zJE 86IiSTBMtNd+s2xJ44acRKlwkCdyZmRuB92jwjqZbOGwT6tmIVVeqiL4n1A2VOnHFU0j Eb9g== 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 b28-v6si19442701pfe.265.2018.08.13.14.27.11; Mon, 13 Aug 2018 14:27:11 -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 S1730526AbeHNALG (ORCPT + 31 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(-) -- 2.18.0 Acked-by: Michael Chan 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);