Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4897176rdb; Tue, 12 Dec 2023 12:21:15 -0800 (PST) X-Google-Smtp-Source: AGHT+IHleCx32WYHnqD8GnW2HS+g1tWNJZntRj0wdMAiw7yeeDyH3F4Xb7jid0D7y1wnfAWY6xKd X-Received: by 2002:a17:90b:350d:b0:286:75d2:7120 with SMTP id ls13-20020a17090b350d00b0028675d27120mr3249597pjb.44.1702412474970; Tue, 12 Dec 2023 12:21:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702412474; cv=none; d=google.com; s=arc-20160816; b=hp1wh8QBjDvEOYm/Brvc3kC4s/axRXpR9si7Ds5tk+198CFGj6DzLghig1WHSQBRVK pGdouvCz3F1epHdvR4T9fxGkkxE/55okiGJpVZzzuLKz5TnIWPuBfe8jlGeFWpda/Ek9 GxuGd9p4a9VIupUg6gp3iQuQ1mvyJY0JG/ZcdPLnX+2hvnDSCqMRuhvEKnT/Ni/Su3nX rZYDqBwJIlkGVDJPv1/jPDWwE5fp8RU5d8cfX+BqIvg+oQae2INyEJ2Z0rik9WsdDXDu fqH2FGqzbmcOrA115YrQdbJ2Roz1+RBcDcHLfk9Zcl6rvLKJ0FRvszutizGChpGX2YKj NU2w== 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 :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=pNHY33zAf7Z3DmgX24lQE73GMdfp/a1HUEW+16HBU1c=; fh=rxc2sb9RWPJeKuWJ4HcXOt1w9ilKB2RdX0DUUSQE5/4=; b=leGxNyZ8pKSaHJ5D6vHLQtKBeLrhzC6DPe+K2vedg/eSpylc/hiM7dvnsuvkQ9Y3cD xZz+dkDAXprf9y+fwrucjoV6rwlouUGXp8NLCInejX/dIAwJB5ryghPr31PSrlTh8x6p F6HzMcAp5yyzs/375mqer+XKp2HLflR1JVZwaqAhni3deW0A3h0rS17roVM7AcUJzwhZ rGonLWVD/GALU7W7oe9kArU1nSk6pRBB9nQJZ0Afk9gm4U3mdue4AcmaoZpwI7516D5U QsR4XcMBDc2jnuPvjLs7q5qJ7fjOM+SL+4du6LlDHeFGF3566MY/9G3C1zpyhaHJo/DP YGHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b="Ckt3fq/r"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=wanadoo.fr Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id mh7-20020a17090b4ac700b00286e8838b6fsi9794499pjb.119.2023.12.12.12.21.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 12:21:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b="Ckt3fq/r"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=wanadoo.fr Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 5A033802090E; Tue, 12 Dec 2023 12:21:11 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377300AbjLLUU4 (ORCPT + 99 others); Tue, 12 Dec 2023 15:20:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377223AbjLLUUy (ORCPT ); Tue, 12 Dec 2023 15:20:54 -0500 Received: from smtp.smtpout.orange.fr (smtp-13.smtpout.orange.fr [80.12.242.13]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0868EB7 for ; Tue, 12 Dec 2023 12:21:00 -0800 (PST) Received: from [192.168.1.18] ([92.140.202.140]) by smtp.orange.fr with ESMTPA id D9FRrnKnRNKQID9FRrw6kc; Tue, 12 Dec 2023 21:20:58 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1702412459; bh=pNHY33zAf7Z3DmgX24lQE73GMdfp/a1HUEW+16HBU1c=; h=Date:Subject:To:Cc:References:From:In-Reply-To; b=Ckt3fq/rBkfcujHT41TO6D5jD/Ky4GMIjnBO4BquSXf7sCud206bT8D0LisXM3mlQ lahNKe28W78HxNuK5Ds9gSA+tunp4kMt4j5T9+mf3mwhaKJLNF+5JQBXPJA5RgNBrg nvZVTqqshDNZ05BrLQ+7ieCJ5GHLBlL/WiByI94dIaQGSziubklOkaajcmX1S+cEOJ BnoV43Fs9Rp7oJSHvhQDbDHl+hrj/xunX2oVuBGd4RAVCGs/adUB/0bOgGcpVCDsoU +wsejwhMixn6HwhIIenymfA7RTvvajvjk28z/MsKpPf3VI84OsHq8iDgbJWk74fUvS P5RJcYEkuW36A== X-ME-Helo: [192.168.1.18] X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Tue, 12 Dec 2023 21:20:59 +0100 X-ME-IP: 92.140.202.140 Message-ID: <70b7e97b-2044-4515-aadc-87d202d32b93@wanadoo.fr> Date: Tue, 12 Dec 2023 21:20:57 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 1/2] scsi: myrb: Fix a potential string truncation in rebuild_show() To: Bart Van Assche , hare@kernel.org, jejb@linux.ibm.com, martin.petersen@oracle.com Cc: hare@suse.com, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org References: <2d3096dd4b1b6e758287e4062e3147c57c007eaa.1702411083.git.christophe.jaillet@wanadoo.fr> Content-Language: fr, en-US From: Christophe JAILLET In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Tue, 12 Dec 2023 12:21:11 -0800 (PST) Le 12/12/2023 à 21:14, Bart Van Assche a écrit : > On 12/12/23 10:09, Christophe JAILLET wrote: >> "physical device - not rebuilding\n" is 34 bytes long. When written in >> 'buf' with a limit of 32 bytes, it is truncated. >> >> When building with W=1, it leads to: >>     drivers/scsi/myrb.c: In function ‘rebuild_show’: >>     drivers/scsi/myrb.c:1906:24: error: ‘physical device - not >> rebuil...’ directive output truncated writing 33 bytes into a region >> of size 32 [-Werror=format-truncation=] >>      1906 |                 return snprintf(buf, 32, "physical device >> - not rebuilding\n"); >>           | >> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >>     drivers/scsi/myrb.c:1906:24: note: ‘snprintf’ output 34 bytes into >> a destination of size 32 >> >> Change the allowed size to 64 to fix the issue. >> >> Fixes: 081ff398c56c ("scsi: myrb: Add Mylex RAID controller (block >> interface)") >> Signed-off-by: Christophe JAILLET >> --- >>   drivers/scsi/myrb.c | 6 +++--- >>   1 file changed, 3 insertions(+), 3 deletions(-) >> >> diff --git a/drivers/scsi/myrb.c b/drivers/scsi/myrb.c >> index ca2e932dd9b7..ca2380d2d6d3 100644 >> --- a/drivers/scsi/myrb.c >> +++ b/drivers/scsi/myrb.c >> @@ -1903,15 +1903,15 @@ static ssize_t rebuild_show(struct device *dev, >>       unsigned char status; >>       if (sdev->channel < myrb_logical_channel(sdev->host)) >> -        return snprintf(buf, 32, "physical device - not rebuilding\n"); >> +        return snprintf(buf, 64, "physical device - not rebuilding\n"); >>       status = myrb_get_rbld_progress(cb, &rbld_buf); >>       if (rbld_buf.ldev_num != sdev->id || >>           status != MYRB_STATUS_SUCCESS) >> -        return snprintf(buf, 32, "not rebuilding\n"); >> +        return snprintf(buf, 64, "not rebuilding\n"); >> -    return snprintf(buf, 32, "rebuilding block %u of %u\n", >> +    return snprintf(buf, 64, "rebuilding block %u of %u\n", >>               rbld_buf.ldev_size - rbld_buf.blocks_left, >>               rbld_buf.ldev_size); >>   } > > Anyone who sees the resulting code without having seen the above patch will > wonder where the magic number '64' comes from. Please use sysfs_emit() > instead > of snprintf(buf, 64, ...). Ok. In this case, do you still prefer 2 patches (one to fix rebuild_show() and one for all the other _show function) or only 1 with everything in it? CJ > > Thanks, > > Bart. >