Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp5067645rwb; Tue, 8 Aug 2023 20:14:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFQPtHehh28UhTH4Gxvj9x1awAHYhp1pPENmFMW2jvS1yFLeLf+q5wmfQ/xN9W07wfWXl/f X-Received: by 2002:a17:906:9bc9:b0:99c:56d1:7c71 with SMTP id de9-20020a1709069bc900b0099c56d17c71mr1146000ejc.26.1691550874152; Tue, 08 Aug 2023 20:14:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691550874; cv=none; d=google.com; s=arc-20160816; b=SO/teGh7MWz5CU5yR/ymMlI++dPOXAdoX2sL17YFe7HPHgYtlcQd4FV/Ci2zgb93/U DnZMhc1Xf7XHiB1/YfoKKYsD8kbEooUPdAAiN8YJW+ZS9T9E2ivnnZMGi+CEIt8elfRm yebZJshMQWYnR+bDJ57Qjf3BdZpCE2xdfIlMhpFKySNMuxitycX37KovXTtb+yWAfl18 b7hxxH2NYramExNHWBRC3CPfqwRATsPKGHgWh0TrL618wWeNJWn7LDrrZGfou0rOIySc tt6AELDTYETWeNvNbFCqmADg8TsF2oOCl1+8Ads5zY2uTqLQv6vWkwzaId2gvdlBwabv kEtg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=iX6M2UKFLcRt1nqYfq3s5PH558wdGqVG8//yeJOH72k=; fh=/0j8XoJyesvQi/8g99ROabMIKCpcAO7hnGGcUWX5aY4=; b=khKCkYxUnOFe95TvmNNGND5aCZ8dJ41yVVwJTfZTaGV62MM3WwuskZcI6Z3YMjuyxf 57ifwQMyya8+gtVCttvx0ZMbjrFJb6Eq5934He2q7unthsdtrw8/tvTtZZN3SLuS9Syu 2il4q1kFiiM8sj1OkI4BK5Bzaea7HRG+o4P8X+TxqeZ8NTlbBGzgoGgoJEPqZ9TAzbk0 DjX1YqsvucMV0EZB4YRscYYZ9E33gJ/z4FpeUbl0RjeMechSclK2l3t+myBbtUuegGHg vbrx4ucFWTlDbPu2c68X87hLy00pHwGw4nKxRvUMVl8ry9qyB6A7l+xmnAWd8ybDWjDt pcFA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p23-20020a170906b21700b0099cbed6da42si6033318ejz.157.2023.08.08.20.14.09; Tue, 08 Aug 2023 20:14:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229903AbjHICNi (ORCPT + 99 others); Tue, 8 Aug 2023 22:13:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229780AbjHICNh (ORCPT ); Tue, 8 Aug 2023 22:13:37 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 318151BCD; Tue, 8 Aug 2023 19:13:36 -0700 (PDT) Received: from kwepemm600007.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4RLD8k2zPxzrSXp; Wed, 9 Aug 2023 10:12:22 +0800 (CST) Received: from localhost.localdomain (10.67.165.2) by kwepemm600007.china.huawei.com (7.193.23.208) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Wed, 9 Aug 2023 10:13:33 +0800 From: Jijie Shao To: , , , , , CC: , , , , , , , Subject: [PATCH net] net: hns3: fix strscpy causing content truncation issue Date: Wed, 9 Aug 2023 10:09:02 +0800 Message-ID: <20230809020902.1941471-1-shaojijie@huawei.com> X-Mailer: git-send-email 2.30.0 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemm600007.china.huawei.com (7.193.23.208) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Hao Chen hns3_dbg_fill_content()/hclge_dbg_fill_content() is aim to integrate some items to a string for content, and we add '\n' and '\0' in the last two bytes of content. strscpy() will add '\0' in the last byte of destination buffer(one of items), it result in finishing content print ahead of schedule and some dump content truncation. One Error log shows as below: cat mac_list/uc UC MAC_LIST: Expected: UC MAC_LIST: FUNC_ID MAC_ADDR STATE pf 00:2b:19:05:03:00 ACTIVE The destination buffer is length-bounded and not required to be NUL-terminated, so just change strscpy() to memcpy() to fix it. Fixes: 1cf3d5567f27 ("net: hns3: fix strncpy() not using dest-buf length as length issue") Signed-off-by: Hao Chen Signed-off-by: Jijie Shao --- drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c | 4 ++-- drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c b/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c index 52546f625c8b..f276b5ecb431 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c @@ -464,9 +464,9 @@ static void hns3_dbg_fill_content(char *content, u16 len, if (result) { if (item_len < strlen(result[i])) break; - strscpy(pos, result[i], strlen(result[i])); + memcpy(pos, result[i], strlen(result[i])); } else { - strscpy(pos, items[i].name, strlen(items[i].name)); + memcpy(pos, items[i].name, strlen(items[i].name)); } pos += item_len; len -= item_len; diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c index 409db2e70965..0fb2eaee3e8a 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c @@ -111,9 +111,9 @@ static void hclge_dbg_fill_content(char *content, u16 len, if (result) { if (item_len < strlen(result[i])) break; - strscpy(pos, result[i], strlen(result[i])); + memcpy(pos, result[i], strlen(result[i])); } else { - strscpy(pos, items[i].name, strlen(items[i].name)); + memcpy(pos, items[i].name, strlen(items[i].name)); } pos += item_len; len -= item_len; -- 2.30.0