Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4893201rdb; Tue, 12 Dec 2023 12:14:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IFITN0FA7x2fGhSCOYGay6FH35igTwA8Vf73LC+CQbSILJkP+2i5heIJnmjiFPilkxbekYG X-Received: by 2002:a17:902:ab09:b0:1d0:6ffd:f21f with SMTP id ik9-20020a170902ab0900b001d06ffdf21fmr3150339plb.117.1702412069103; Tue, 12 Dec 2023 12:14:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702412069; cv=none; d=google.com; s=arc-20160816; b=w+Hxpp7GYoxscLsGn3bdsrrsN/fLB2xJ83Qj1I+Em0I5bVMAG3oKzRicV9GJ6RI4ih qb/Ah9K7SNVQu79UFoV/B5NHSo0VMyWVIkuLgz4ox2g8O+QU6qX7NZFQeFmCoHVzAuX/ L05y9k5uSQe6o6/4Wwf3RPvleOPVm+9WpxBax0ajRDKcbfYTHXeSExsnGHIKrm5ofrj/ B7mFI3ricGxdF0m4DyqXq/DFfm8f8wXtu8VDYDv0CbBZwJ/ApE+DA/pWvDi4o8LfGgTT 6vIHaGx928BBMn0fMxqu9SRiDZearjUZHnpB7gLidu1c/Gns7IaHLubUVI0u4nN9l1Fc sj1w== 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 :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=KymjChpn+W/EoA8lrLNNU5MTNVyrEAJwx7+J+qgDA8M=; fh=pd4dcCROVxg/38uIEF4qJQXW5PKYANvk6Ozo/7MfzR4=; b=UHcn8hgUThXb24Ib6ttw18jQj5HXp5BD6JxEFjipPnn57/ee4/+I581SVCk67YF/fl ieeLj+FDRjfmDajtgJ6sdtz5K73SQzgN0joa4dNJxNfURu0rQAZ3oVcia79WXgjPZwiX CyH3yMThq65kirLGe6BG/d2EiD9X3hwgjQiqBuKfBx77dtKceaZnP3TeZgeLSvSURKD4 koXAg/eiJXxOHGsxAMnoctDYJloWENDGY9+pRfZ13ImGuMBfaAGEq+wJ3p2EoUZPnsrs 3N7T9ChLj+LDA4ux9/eYB+CGeLo1oYBY/ocw1I3E5aNfp1DRy7VqsmmRAv0PElRIsU6A rHkw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=acm.org Return-Path: Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id l12-20020a170903120c00b001d06d47c3c8si8450878plh.299.2023.12.12.12.14.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 12:14:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=acm.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 996F880B02A1; Tue, 12 Dec 2023 12:14:26 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230191AbjLLUOM (ORCPT + 99 others); Tue, 12 Dec 2023 15:14:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45482 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229975AbjLLUOK (ORCPT ); Tue, 12 Dec 2023 15:14:10 -0500 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 42175A5; Tue, 12 Dec 2023 12:14:17 -0800 (PST) Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-1d0c4d84bf6so36733335ad.1; Tue, 12 Dec 2023 12:14:17 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702412057; x=1703016857; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=KymjChpn+W/EoA8lrLNNU5MTNVyrEAJwx7+J+qgDA8M=; b=KACuKOnSaYhkzlR9k/uaILju7elcvZsg9f9ijYCbyMP+2EnaX406f18tKL7eQmve0G rfh7tZlbxUm4bhKfAFlahEcD/TjHWoJuMk0qo3Lv9oIO6kkjs/xuANd0P8XgpBiM6Hik kOkF+s0DA1ILw3lhAz+eyVmEzJJXWK8on4eL7eFluKNTe1Q78MiSiQi6AyMaXBWEaqiL cA5ZBqXK0sTsUnhZ8fY4x5bTdrX18NIIxxExPzhionS8MBtlexhh5oL+TXY4HoRDSHx6 QYLnuYVgu0jMyjX+JLvtCj5vd2ZDIPYEr7HeqhcqzvnkUIS/UVth+7lX0AQamEnewisW M6+g== X-Gm-Message-State: AOJu0YzKyZWC2SPaAlI7CbpQ3HO6vJyhxfUcU0eNjC+EqPLd4/le1Dl3 yTGaFmjLp4C2UFyxGtIyiNDHUwer4pE= X-Received: by 2002:a17:902:d2cf:b0:1d0:c986:8aae with SMTP id n15-20020a170902d2cf00b001d0c9868aaemr4231815plc.97.1702412056545; Tue, 12 Dec 2023 12:14:16 -0800 (PST) Received: from ?IPV6:2620:0:1000:5e10:c59a:35c6:9a2a:969f? ([2620:0:1000:5e10:c59a:35c6:9a2a:969f]) by smtp.gmail.com with ESMTPSA id k10-20020a170902694a00b001cca8a01e68sm8970483plt.278.2023.12.12.12.14.15 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 12 Dec 2023 12:14:16 -0800 (PST) Message-ID: Date: Tue, 12 Dec 2023 12:14:14 -0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 1/2] scsi: myrb: Fix a potential string truncation in rebuild_show() Content-Language: en-US To: Christophe JAILLET , 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> From: Bart Van Assche In-Reply-To: <2d3096dd4b1b6e758287e4062e3147c57c007eaa.1702411083.git.christophe.jaillet@wanadoo.fr> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=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 morse.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 (morse.vger.email [0.0.0.0]); Tue, 12 Dec 2023 12:14:26 -0800 (PST) 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, ...). Thanks, Bart.