Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1986455pxa; Mon, 24 Aug 2020 01:30:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyhR67YNF274Aw6oJU7rQu0rwnXo9M0EbKuKmh4qqpO3sdTcOTVXsjfyUDI83UtFk5BK0fH X-Received: by 2002:a50:ee92:: with SMTP id f18mr4346216edr.80.1598257819094; Mon, 24 Aug 2020 01:30:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598257819; cv=none; d=google.com; s=arc-20160816; b=qXY9uTjQgfjtQLLpwsa120ZaoaDD5YaVEe1vGLO8loqR5pliiWM2pXU2QFOs13lEIv dGrm/0GTqjWmz+9u5vF6r/53cC7ytUTSX5wpbjXzrqQ8bsDifpReXHH7Pvc/ZlxFa9RR Nfy2K4qI3lobc5j90op0jS2pFTWlTxqVIT8l+vpIRYJ9MuQ0pfk91CEXU3ioSMsKTS4T 8dQ2V9HXMPK5zYwmAh3YOKeEOuCykEBfUCtwnEt94dgzD/EgM6fYMsng6ImhdjV91EhK AlQBzxXWygpIpLnBV7HF3N/4jEVO1E98Xm04RRp/WmicUcGnxB6tT3J0IHccMC7/cutn vLdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :content-language:accept-language:in-reply-to:references:message-id :date:thread-index:thread-topic:subject:cc:to:from; bh=v52pPnQLaz+kn99mAl0OPKDWyg8qPIubfkiVhLlVOn8=; b=WmOFFCaPEaOoiNWLd2rnyAoXCQI4Oj0bHHxU4QiBvUltOagrZn5eJFiyuCiUbB9srK kPoqiRt4fFCP/ceggpPEQb7OriwAVm8jwP420UTNbJTuRbKxGLcA1sTcTrZAg4SVu/wg NQdHgJJMb3XDfrEp+KfiBWLKKvmEW8PxI+5kH0HqwHaZwkjtsZ3rLelPGhRHwGg1syDk 3BcUMEBUkS8OK5ZMeBcXUN8h1lN1KoF/J9pn2yuNYx8thSDCVnplIZ/23mpkbZdmrVbn EN65/RqsvQezhFv74L7uplcc3X08DJcfwZYEdjy6MlfAl78L5nuWl9dB1cOQ0yJ7efkF m0bQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bc19si6173547edb.237.2020.08.24.01.29.44; Mon, 24 Aug 2020 01:30:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726104AbgHXI3m convert rfc822-to-8bit (ORCPT + 99 others); Mon, 24 Aug 2020 04:29:42 -0400 Received: from eu-smtp-delivery-151.mimecast.com ([207.82.80.151]:38798 "EHLO eu-smtp-delivery-151.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726037AbgHXI3k (ORCPT ); Mon, 24 Aug 2020 04:29:40 -0400 Received: from AcuMS.aculab.com (156.67.243.126 [156.67.243.126]) (Using TLS) by relay.mimecast.com with ESMTP id uk-mta-138-5TvUt1XsPpyGpCaE1czwzg-1; Mon, 24 Aug 2020 09:29:37 +0100 X-MC-Unique: 5TvUt1XsPpyGpCaE1czwzg-1 Received: from AcuMS.Aculab.com (fd9f:af1c:a25b:0:43c:695e:880f:8750) by AcuMS.aculab.com (fd9f:af1c:a25b:0:43c:695e:880f:8750) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Mon, 24 Aug 2020 09:29:36 +0100 Received: from AcuMS.Aculab.com ([fe80::43c:695e:880f:8750]) by AcuMS.aculab.com ([fe80::43c:695e:880f:8750%12]) with mapi id 15.00.1347.000; Mon, 24 Aug 2020 09:29:36 +0100 From: David Laight To: 'Yang Shen' , "herbert@gondor.apana.org.au" , "davem@davemloft.net" CC: "linux-kernel@vger.kernel.org" , "linux-crypto@vger.kernel.org" , "xuzaibo@huawei.com" , "wangzhou1@hisilicon.com" Subject: RE: [PATCH RESEND 04/10] crypto: hisilicon/zip - replace 'sprintf' with 'scnprintf' Thread-Topic: [PATCH RESEND 04/10] crypto: hisilicon/zip - replace 'sprintf' with 'scnprintf' Thread-Index: AQHWecS3Jx83/+rMLUuKUpSHllsCl6lG7Xzg Date: Mon, 24 Aug 2020 08:29:36 +0000 Message-ID: References: <1598238709-58699-1-git-send-email-shenyang39@huawei.com> <1598238709-58699-5-git-send-email-shenyang39@huawei.com> In-Reply-To: <1598238709-58699-5-git-send-email-shenyang39@huawei.com> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=C51A453 smtp.mailfrom=david.laight@aculab.com X-Mimecast-Spam-Score: 0.002 X-Mimecast-Originator: aculab.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org From: Yang Shen > Sent: 24 August 2020 04:12 > > Replace 'sprintf' with 'scnprintf' to avoid overrun. > > Signed-off-by: Yang Shen > Reviewed-by: Zhou Wang > --- > drivers/crypto/hisilicon/zip/zip_main.c | 11 +++++++---- > 1 file changed, 7 insertions(+), 4 deletions(-) > > diff --git a/drivers/crypto/hisilicon/zip/zip_main.c b/drivers/crypto/hisilicon/zip/zip_main.c > index df1a16f..1883d1b 100644 > --- a/drivers/crypto/hisilicon/zip/zip_main.c > +++ b/drivers/crypto/hisilicon/zip/zip_main.c > @@ -428,7 +428,7 @@ static ssize_t hisi_zip_ctrl_debug_read(struct file *filp, char __user *buf, > return -EINVAL; > } > spin_unlock_irq(&file->lock); > - ret = sprintf(tbuf, "%u\n", val); > + ret = scnprintf(tbuf, HZIP_BUF_SIZE, "%u\n", val); Should that be sizeof (tbuf). > return simple_read_from_buffer(buf, count, pos, tbuf, ret); > } > > @@ -514,13 +514,16 @@ static int hisi_zip_core_debug_init(struct hisi_qm *qm) > struct debugfs_regset32 *regset; > struct dentry *tmp_d; > char buf[HZIP_BUF_SIZE]; > - int i; > + int i, ret; > > for (i = 0; i < HZIP_CORE_NUM; i++) { > if (i < HZIP_COMP_CORE_NUM) > - sprintf(buf, "comp_core%d", i); > + ret = scnprintf(buf, HZIP_BUF_SIZE, "comp_core%d", i); > else > - sprintf(buf, "decomp_core%d", i - HZIP_COMP_CORE_NUM); > + ret = scnprintf(buf, HZIP_BUF_SIZE, "decomp_core%d", > + i - HZIP_COMP_CORE_NUM); > + if (!ret) > + return -ENOMEM; and that is just so wrong - did you even try to test the 'buffer too small' code path? David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)