From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6A3E3EE49BF for ; Wed, 6 Sep 2023 02:05:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236728AbjIFCFJ (ORCPT ); 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 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, >