From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751946AbdHBXom (ORCPT ); Wed, 2 Aug 2017 19:44:42 -0400 Received: from LGEAMRELO13.lge.com ([156.147.23.53]:54513 "EHLO lgeamrelo13.lge.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751161AbdHBXok (ORCPT ); Wed, 2 Aug 2017 19:44:40 -0400 X-Original-SENDERIP: 156.147.1.126 X-Original-MAILFROM: minchan@kernel.org X-Original-SENDERIP: 10.177.220.163 X-Original-MAILFROM: minchan@kernel.org Date: Thu, 3 Aug 2017 08:44:37 +0900 From: Minchan Kim To: Doug Anderson Cc: Matthias Kaehlcke , Nitin Gupta , Sergey Senozhatsky , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH] zram: Fix buffer size passed to strlcpy() Message-ID: <20170802234437.GD32020@bbox> References: <20170728171243.23374-1-mka@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Doug, On Wed, Aug 02, 2017 at 03:54:32PM -0700, Doug Anderson wrote: > Hi, > > On Fri, Jul 28, 2017 at 10:12 AM, Matthias Kaehlcke wrote: > > comp_algorithm_store() passes the size of the source buffer to strlcpy() > > instead of the destination buffer size, fix this. > > This was introduced in commit 415403be37e2 ("zram: use crypto api to > check alg availability"), but probably don't need a "Fixes" since > there's not really a bug (see below) > > > Signed-off-by: Matthias Kaehlcke > > --- > > drivers/block/zram/zram_drv.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c > > index 856d5dc02451..7d2ddffad361 100644 > > --- a/drivers/block/zram/zram_drv.c > > +++ b/drivers/block/zram/zram_drv.c > > @@ -327,7 +327,7 @@ static ssize_t comp_algorithm_store(struct device *dev, > > return -EBUSY; > > } > > > > - strlcpy(zram->compressor, compressor, sizeof(compressor)); > > + strlcpy(zram->compressor, compressor, sizeof(zram->compressor)); > > As far as I can tell the two sizes are identical. In struct zram: > > char compressor[CRYPTO_MAX_ALG_NAME]; > > Locally here: > > char compressor[CRYPTO_MAX_ALG_NAME]; > > ...so there is no bug per say unless there's a hidden "#undef". > ...but your change does make it a little clearer, plus if someone ever > changed one of these arrays it would be safer. Thus: > > Reviewed-by: Douglas Anderson > > > I suppose another option would be to define the local array based on > the size of the structure. AKA locally in the function: > > char compressor[ARRAY_SIZE(zram->compressor)]; > > ...if you did that you could replace the strlcpy() below with a simple > strcpy() since you'd be guaranteed that there's be enough space. > ...but I'm probably overthinking it too much. ;-P First of all, Thanks for the patch, Matthias. You are correct and you patch doesn't have any problem. However, I think Doug's suggestion looks better. Could you mind resending? Thanks.