Received: by 2002:a05:6358:51dd:b0:131:369:b2a3 with SMTP id 29csp815385rwl; Thu, 10 Aug 2023 01:55:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE5Ek9JL+KWQnjQHNQe8evKPyJgvRVzdRXL9fk67w8mujk3MYevHNLbw91sBxNA12DAK91w X-Received: by 2002:a17:902:9a91:b0:1bc:9c49:f8ce with SMTP id w17-20020a1709029a9100b001bc9c49f8cemr1392823plp.4.1691657702920; Thu, 10 Aug 2023 01:55:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691657702; cv=none; d=google.com; s=arc-20160816; b=yysH6UUhtpzBtN73HtUATXJb5Au6eWhW8/Bpi1qA0g10p3QMHHO57Stiouf7KU12a9 rtF6KG1n+QVK8FkJF0/mKF1pVYMUrHm+9NuL2SEBQT6ExHpYEhAlAK3Ed3AA55llbZdz SkgaLt7p85aIJ+5OAyjV32+Eh23f+EhUflmKURhhrgjfKlDYiNNpxL/k6RMiqe9KU14O I8aw3/gWigX04dvt5LtET2OxkM9TUyVZnjlZWyy36C5gMWvYkMxLxStx74S3rVZ5C64j 5fRivfzo/DprnU6nigLhftNDxLAjjoCaSAR/p7I0Jq2XtAw9aofBjALcYpi+Mue0MMQm Qj8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:to:subject:cc:user-agent:mime-version:date:message-id; bh=oT8M4bVVkN3P+GJoBzcFnquP14Qo8rlLiZdgEQK+/Fc=; fh=95KLAlG6pngOv6CagXDjyNFlY58aw7aNZ3hhN2K7ldY=; b=szQpO0B55MqkSYGN6rycF0Q/IWIcIO0GyF6mBmo5GItz3E3p3AfGncxAKapPgKA1Y7 ekua8+TIUY7KZX8Qms560mBtxio2PMnjPupd87X0eU8Eqn2SbZ42OKTCVCN3uKiu5S/f /EmemUefh2xdyc7DOJsYEfBlWvvovYnVcwebikWRzdopI70xVLlT0l0rsocA6/g6E7My zMtkhyt65Jg3y1iilqOEoOS2fP8LLkc9eDXkAW6Me8E0c5aBZIFbHnAdCR8bb25GOdnC yWhdEWOsUAdwQ8QXLnl2CduNAmvrlUjVsha5XnLPU0+/8zdPScGut5qAbb2PJiJJAPvF SLrQ== 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 u15-20020a170902e80f00b001b9e8ebe5a0si1086505plg.613.2023.08.10.01.54.50; Thu, 10 Aug 2023 01:55:02 -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 S232278AbjHJHp5 (ORCPT + 99 others); Thu, 10 Aug 2023 03:45:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231517AbjHJHp4 (ORCPT ); Thu, 10 Aug 2023 03:45:56 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A92610F6; Thu, 10 Aug 2023 00:45:54 -0700 (PDT) Received: from kwepemm600007.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4RLzR2095YztS7B; Thu, 10 Aug 2023 15:42:22 +0800 (CST) Received: from [10.69.136.139] (10.69.136.139) 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; Thu, 10 Aug 2023 15:45:51 +0800 Message-ID: <7c44c161-9c86-8c60-f031-6d77d6c28c20@huawei.com> Date: Thu, 10 Aug 2023 15:45:50 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird CC: , , , , , , , , , , , , , Subject: Re: [PATCH net] net: hns3: fix strscpy causing content truncation issue To: Leon Romanovsky References: <20230809020902.1941471-1-shaojijie@huawei.com> <20230809070302.GR94631@unreal> From: Jijie Shao In-Reply-To: <20230809070302.GR94631@unreal> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.69.136.139] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) 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 on 2023/8/9 15:03, Leon Romanovsky wrote: > On Wed, Aug 09, 2023 at 10:09:02AM +0800, Jijie Shao wrote: >> 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. > I think that you should change to strtomem() and not use plain memcpy(). > > Thanks Hi: We tried to replace memcpy with strtomem, but errors was reported during compilation: /kernel/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c: In function ‘hclge_dbg_fill_content.part.0’: /kernel/include/linux/compiler_types.h:397:38: error: call to ‘__compiletime_assert_519’ declared with attribute error: BUILD_BUG_ON failed: !__builtin_constant_p(_dest_len) || _dest_len == (size_t)-1   397 |  _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)       |                                      ^ /kernel/include/linux/compiler_types.h:378:4: note: in definition of macro ‘__compiletime_assert’   378 |    prefix ## suffix();    \       |    ^~~~~~ /kernel/include/linux/compiler_types.h:397:2: note: in expansion of macro ‘_compiletime_assert’   397 |  _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)       |  ^~~~~~~~~~~~~~~~~~~ /kernel/include/linux/build_bug.h:39:37: note: in expansion of macro ‘compiletime_assert’    39 | #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)       |                                     ^~~~~~~~~~~~~~~~~~ /kernel/include/linux/build_bug.h:50:2: note: in expansion of macro ‘BUILD_BUG_ON_MSG’    50 |  BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition)       |  ^~~~~~~~~~~~~~~~ /kernel/include/linux/string.h:302:2: note: in expansion of macro ‘BUILD_BUG_ON’   302 |  BUILD_BUG_ON(!__builtin_constant_p(_dest_len) ||  \       |  ^~~~~~~~~~~~ /kernel/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c:115:4: note: in expansion of macro ‘strtomem’   115 |    strtomem(pos, result[i]);       |    ^~~~~~~~ In the strtomem macro, __builtin_object_size is used to calculate the _dest_len. We tried to print the _dest_len directly, and the result was -1. How can we solve this? Regards Jijie Shao