Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp1207572rdb; Mon, 19 Feb 2024 07:36:34 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVztYTI3K5MiLSFuL8nOPvrk4F24Xew45FRgTp877DtAv0U+RxxzGepjyc1+nbsgRrT9NZzwyrSKXlgvaFVCEnHZ+tpTlWa2ymQrIZslg== X-Google-Smtp-Source: AGHT+IHYncHeDscU7beeE3YDdPTH5Lz27avwSIYsqP4z6kOi63/VYk35Xfy+j+pdv75jvahOShYB X-Received: by 2002:a05:6358:18c:b0:17a:ec74:b574 with SMTP id d12-20020a056358018c00b0017aec74b574mr18754861rwa.10.1708356993931; Mon, 19 Feb 2024 07:36:33 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708356993; cv=pass; d=google.com; s=arc-20160816; b=dn6E1jhJQfa1QuXkNIdxiiPeJxPqE7mpZ3lROyNdxOJIdbjLwr+e60zHZaZnyxn2tr 3FM/m2oqZsK1SClF7gXMvwVqhmDJ1yUQzL1yXxrWIWXD7fGEqrLoLxqs2QU8xJXzg+BT OgYa8ic4NEpr9mJUr8M91w5SIw+tLaoCAOTBBqB9dqQi8sqmZvDiv9T31WyF3flCMfFM g1Ctslm3IQ/JHEEHcKITnke8pNLNcJvL4kK/Pt03O0AqKbRoVzXVHUEHf43xpnXRHd2p yRo31WoBKr4M1MzxVyfeZjms3a0VpaO6N2qPemOq0BqxYSvPMMWFMOEOhJDyv8VWgaB8 HZhA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date:dkim-signature; bh=9+Hku8Dr3CX4rGbt5Z3twUyPwp/CbF2l21hxtKKl7l4=; fh=vcAKQtDpS4XaYbVSxdm3FhXFhcvYl5SRFl0yB+wmjoo=; b=Te7w3Upm6jXW6+qskLjnTh9EnBNwvcxBonkce8xEEhOQKdC9DAcsOEIpsJDIoXQlZs Y4cIU9zjr1qsD7tiC6dRulLJqRX9HPySRRvXIERa9CSCyOacG0pW65kBErdFNqBsJXb0 kWLGHNUrSMHi3wNcBFEcHl/StsibvwLJfVNOmCmZS2Oa9YgfbUac7zoq7DNGvvMQnmCF CQBvTLTz9QXM8/qoyHrssH/RB9CAa7kw8EKzRyxRT+GsGVkzXG5daq2Q6gdntlnWlH/s fTtdUBzP6ymUwsXobfGZNnO2P5pqu2+Ieq0nW0xVSpxsyofM32l6ixihgJB5AY1zBnrZ w7uw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="Fv4XKd/N"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-71580-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71580-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id a185-20020a6390c2000000b005cddfe0c82bsi4587642pge.211.2024.02.19.07.36.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 07:36:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-71580-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="Fv4XKd/N"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-71580-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71580-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 11915B242FD for ; Mon, 19 Feb 2024 15:23:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9206438DCA; Mon, 19 Feb 2024 15:23:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Fv4XKd/N" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B601B39ACA; Mon, 19 Feb 2024 15:23:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708356197; cv=none; b=rN4lSlIhrfgTbkUKJyQs3aWMFGbG1pECQIDWltpCl+ezaBL/4XB/0m/t2yXEZkrHFc4fSargee/9rOP3gh084gqAehh2ox9iQUynMjbK7ZLlWb3K/kodqN2fourLsPw5Y43ZIqoxhUHEeHzAQYAUUEFu6S5awKHz+uTkkY5oyzk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708356197; c=relaxed/simple; bh=JNh62JRLg8fbXzqeXktZKO30ccvU8cSYgOtKGgR1GTg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=K6fWAmfkONwe2/97girT5mw6lTIU5tpSUo8pY4Y/JHLl7y7sh7eg85l/FWeuGL0t30UXMPl+vOaZ8nVo/zlzm9guI3j2SJ6SBOmPLBdQ1hMvwYmycC4Fhr+mdsReiXmdbvpY3oCZz/HXp6BudFGlwf5Db0y/qTFvvzhQ7n3B1gk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Fv4XKd/N; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 40BA2C433F1; Mon, 19 Feb 2024 15:23:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708356197; bh=JNh62JRLg8fbXzqeXktZKO30ccvU8cSYgOtKGgR1GTg=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Fv4XKd/NcPTVC5J1o8uIejsGeuMK+AyXccbshb2aTjyePC+0FWS5Qcwqp4vAP1QUx 2nKuNKJpTVpH++Wqac85mgKTfi/fPHdWv9/++BrZBgcFBPV2wWSFwc68PQ9UUO1Ry5 mqxrHfZQeHQ5EHwWCQNsNbxID5Pl+XU0apdX2vC2JeE4gB0QUtLcn49hppT1T5q1VJ YgSYprKkqYqv4gM7UJWGj9UBgxteJpOUimticMPQWxotvy5+G2DMUAvgpfe5tae0se i/kW9Ay5ItYlRWG/A3iDm6QOtPUddT6YtL5dNY+1DrldDLYCy2oBsLnPwybO3t+UzE gOLpoKSaEqF5w== Date: Mon, 19 Feb 2024 15:23:12 +0000 From: Lee Jones To: James Bottomley Cc: Geert Uytterhoeven , linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, Finn Thain , Michael Schmitz , "Martin K. Petersen" , drew@colorado.edu, Tnx to , linux-scsi@vger.kernel.org Subject: Re: [PATCH 03/10] scsi: NCR5380: Replace snprintf() with the safer scnprintf() variant Message-ID: <20240219152312.GD10170@google.com> References: <20240208084512.3803250-1-lee@kernel.org> <20240208084512.3803250-4-lee@kernel.org> <20240208102939.GF689448@google.com> <98bdd564c6bf1894717d060f3187c779e969fc5f.camel@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <98bdd564c6bf1894717d060f3187c779e969fc5f.camel@linux.ibm.com> On Sat, 10 Feb 2024, James Bottomley wrote: > On Thu, 2024-02-08 at 10:29 +0000, Lee Jones wrote: > > On Thu, 08 Feb 2024, Geert Uytterhoeven wrote: > > > > > Hi Lee, > > > > > > Thanks for your patch! > > > > > > On Thu, Feb 8, 2024 at 9:48 AM Lee Jones wrote: > > > > There is a general misunderstanding amongst engineers that > > > > {v}snprintf() > > > > returns the length of the data *actually* encoded into the > > > > destination > > > > array.  However, as per the C99 standard {v}snprintf() really > > > > returns > > > > the length of the data that *would have been* written if there > > > > were > > > > enough space for it.  This misunderstanding has led to buffer- > > > > overruns > > > > in the past.  It's generally considered safer to use the > > > > {v}scnprintf() > > > > variants in their place (or even sprintf() in simple cases).  So > > > > let's > > > > do that. > > > > > > Confused... The return value is not used at all? > > > > Future proofing.  The idea of the effort is to rid the use entirely. > > > >  - Usage is inside a sysfs handler passing PAGE_SIZE as the size > >    - s/snprintf/sysfs_emit/ > >  - Usage is inside a sysfs handler passing a bespoke value as the > > size > >    - s/snprintf/scnprintf/ > >  - Return value used, but does *not* care about overflow > >    - s/snprintf/scnprintf/ > >  - Return value used, caller *does* care about overflow > >    - s/snprintf/seq_buf/ > >  - Return value not used > >    - s/snprintf/scnprintf/ > > > > This is the final case. > > To re-ask Geert's question: the last case can't ever lead to a bug or > problem, what value does churning the kernel to change it provide? As > Finn said, if we want to deprecate it as a future pattern, put it in > checkpatch. Adding this to checkpatch is a good idea. What if we also take Kees's suggestion and hit all of these found in SCSI in one patch to keep the churn down to a minimum? -- Lee Jones [李琼斯]