Received: by 2002:a05:7412:f584:b0:e2:908c:2ebd with SMTP id eh4csp2321671rdb; Wed, 6 Sep 2023 00:39:54 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGoPLaz0+hRxk1EI3mYKLrZkJPTZGtDhcXr6JCR3qxBL1AEUXXvIcvhfqkMtrUyq/M9dA7z X-Received: by 2002:a17:906:518b:b0:9a3:b0c9:81fe with SMTP id y11-20020a170906518b00b009a3b0c981femr1221142ejk.57.1693985994129; Wed, 06 Sep 2023 00:39:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693985994; cv=none; d=google.com; s=arc-20160816; b=cW/7dZ9quh3GGHJSLTwFA5AfkKCaMD2pppVgUF6oarGx13Li1NW8/Nqnb4RKsQ4V2G hM43tJbM2Thhse0Sny1KPc+Z528xczf6jqbsLevjZybW/3VBReKUEWVnoZ96IuX/wLkJ PQp8eLCGTNNZ2khaFai0I/5GLh7NdwWWmpG/zW7hTeXfO1D967/Mp9XU4xKzk/6QYzBB uFO354Q342cLNocLMJMfWrq7jcasI1MCVOIOwFNTm09372mrupwsyOXu9m/NiTCMGFfc bM/ieK6Zw7q44R3JpbW5ispzFpFDtWcAt+4EXnpYI/d0k++w4L9zA5O0s/1eEToyBwyz 7ZRA== 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 :mime-version:user-agent:date:message-id:from:references:cc:to :subject; bh=AY/A2x4DMKANtB4rnowfxznJXoDV92cduYHmIYClDP8=; fh=NYYv8rcIc3PAkFkN9Lj/cvFcoErAPNQtyxr08nB7nLQ=; b=OXj+Ak/yMPLEN9YsOStfpjaPo2g8zEvblm3bL23eEx5yJ6MoB+50C9tfTX5ZGCmBND SbHdBNQSg5gOFodhmTi1tuJoEVKryOWjU+tSdquz2jngZBCF8a17taOeTC1gop2xrOjq t+bIk2qu7ZChWl2vHJd2oW/rQaKUIU5faiO5ydCtoP3AXvKwKjBILi2opMX8aKu0boMc j22sdFxeXEsPvcsqilcivFwlwqDqo3HmyO0Vqd2oRLBGH3duNemZ8clbFkOe/NcdE9Jw rUFMnrGbBMn4xGlGQNdHpB9VLfu6D81bG+2b5XNpCMqgezXlv/lLO2pV8JgjPpB+I5n7 7TAA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-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 a6-20020a170906244600b009a1c2fcdce9si8636089ejb.104.2023.09.06.00.39.24; Wed, 06 Sep 2023 00:39:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-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-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-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 S236728AbjIFCFJ (ORCPT + 92 others); Tue, 5 Sep 2023 22:05:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58042 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229575AbjIFCFJ (ORCPT ); Tue, 5 Sep 2023 22:05:09 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 447BC1A7; Tue, 5 Sep 2023 19:05:02 -0700 (PDT) Received: from kwepemm600005.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4RgQbz2ZR6zVkdx; Wed, 6 Sep 2023 10:02:07 +0800 (CST) Received: from [10.67.121.110] (10.67.121.110) by kwepemm600005.china.huawei.com (7.193.23.191) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Wed, 6 Sep 2023 10:04:43 +0800 Subject: Re: [PATCH] crypto: hisilicon/hpre - Fix a erroneous check after snprintf() To: Herbert Xu , Marion & Christophe JAILLET CC: "David S. Miller" , Zaibo Xu , , , References: <73534cb1713f58228d54ea53a8a137f4ef939bad.1693858632.git.christophe.jaillet@wanadoo.fr> <00bdcfec-6cc1-e521-ceaa-d16d6341ca16@wanadoo.fr> From: liulongfang Message-ID: Date: Wed, 6 Sep 2023 10:04:42 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="gbk" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.67.121.110] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemm600005.china.huawei.com (7.193.23.191) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00,NICE_REPLY_A, 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-crypto@vger.kernel.org On 2023/9/5 16:17, Herbert Xu wrote: > On Tue, Sep 05, 2023 at 07:27:47AM +0200, Marion & Christophe JAILLET wrote: >> >> Some debugfs dir of file way be left around. Is it what your are talking >> about? > > Yes all allocated resources should be freed on the error path. > >>> The other snprintf in the same file also looks suspect. >> >> It looks correct to me. >> >> And HPRE_DBGFS_VAL_MAX_LEN being 20, it doesn't really matter. The string >> can't be truncated with just a "%u\n". > > Well if you're going to go with that line of reasoning then this > case ("cluster%d") can't overflow either, no? > First, I checked the calling code of the snprintf function in all driver files in the hisilicon directory. Only here is the processing of return value judgment. This treatment is indeed problematic and needs to be modified. Then, I don't quite agree with your modification plan. The modification of this solution is not complete. As Herbert said, ("cluster%d") may still have overflow problems. In the end, my proposed modification scheme is this: ... int ret; u8 i; for (i = 0; i < clusters_num; i++) { snprintf(buf, HPRE_DBGFS_VAL_MAX_LEN, "cluster%u", i); tmp_d = debugfs_create_dir(buf, qm->debug.debug_root); ... } ... Thanks, Longfang. > Cheers, >