Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2748305pxa; Tue, 25 Aug 2020 02:02:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzm7l+sjMZHc7TPWkWE13iLRrxGeKj7EW3AYIqtIA6WK36uqc5SN24grgGyBBk4RVKTfpkJ X-Received: by 2002:a17:906:bcf4:: with SMTP id op20mr9875876ejb.277.1598346164826; Tue, 25 Aug 2020 02:02:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598346164; cv=none; d=google.com; s=arc-20160816; b=iK5bCScx8Ho5HCUHMdJIJzpJDmSv/mcAWRNEMZKpZSzaV15jPkh2KCEkLkuojSUQgq cIGozWrq05/gL7siZnPUGn8TJA/7WUwMogbzHU52MK8Wm8hKcyAseJ06NIxegUCMsoiK idg7gbT+mriEZSs9m+uDK5JJTu4rtsGXX6yQ0ETMpyB30lobX/Z2ejKB+Su7KFcgq9Ff Ls6KnxpoqJtJ0m+x4JhKcJaNpPF68GlRzqW0GpefHIbRq52rBr5aeh1sg34Pqy1Qm316 CEGD4guUfoMor8j2e8mg5A7jSx5aV8luBIUPEe3A6P4B8KcDAwtGalWcOmkTJb8RhUqq mykg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=6hOnLogkR/73y4fIp720QlC3ZTbHOKcuXTawHeO6yOg=; b=wkLjVz6+4DTnfXZBHRq/gWDiLqC5SNLdaBMe2we2T/3oh9al4cdrglpWvvKtR7yuQC UHWIa7Q1Ef/FBVA7a9ZWlnf8YaSi8Zbe8veAmMRUPNvf9xrUXlpB5ey8cPaLFWyfNbeu O327h7RZz8QeOaoeUgC77l3vCmQGmG9wwwBv+TSpwD8ALBscq7FusxhG1f1yIwnmiSSV ie0oOqaesgJyh5EQAb82WOUQzCS2CZd7vwplhPCFoCqAOy8hQxKGqlHuM9k+L+J5Fj5s xOSHbt35avYtOR+Qn44AhEVcyANmryHCrGRtk9hlJxPi+sPhCcuFaYma4w2393jiADpD zgBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=PSSTiJO2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bt23si2850563edb.85.2020.08.25.02.02.21; Tue, 25 Aug 2020 02:02:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=PSSTiJO2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728957AbgHYIXu (ORCPT + 99 others); Tue, 25 Aug 2020 04:23:50 -0400 Received: from mail.kernel.org ([198.145.29.99]:39958 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725924AbgHYIXu (ORCPT ); Tue, 25 Aug 2020 04:23:50 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0ADE920639; Tue, 25 Aug 2020 08:23:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1598343829; bh=7VMz50D7ZZ0WPmUQJONRcdBdlICzRU9qCkM2phdMJdQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=PSSTiJO2m8BnQId0wTCEmWanF6KF5g8CXBUKfMDAyFPgW8Gn0fGvbJydaPaOxmT2U R4lnDuXr76vs8Jgpw3T1G91qDVSlto0v9UyW4jMjVnpBxnC3tprU0tMtveud3c9r9g mIzR0ED9ZZzDlfGaQR6zM139eUEBazVDckWoqkVE= Date: Tue, 25 Aug 2020 10:24:06 +0200 From: Greg Kroah-Hartman To: David Laight Cc: 'Alex Dewar' , "Gustavo A. R. Silva" , "accessrunner-general@lists.sourceforge.net" , "linux-usb@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH] usb: atm: don't use snprintf() for sysfs attrs Message-ID: <20200825082406.GB1335351@kroah.com> References: <20200824222322.22962-1-alex.dewar90@gmail.com> <3e882693bb344424af37d4d35f3db605@AcuMS.aculab.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3e882693bb344424af37d4d35f3db605@AcuMS.aculab.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Aug 25, 2020 at 08:12:05AM +0000, David Laight wrote: > From: Alex Dewar > > Sent: 24 August 2020 23:23 > > kernel/cpu.c: don't use snprintf() for sysfs attrs > > > > As per the documentation (Documentation/filesystems/sysfs.rst), > > snprintf() should not be used for formatting values returned by sysfs. > > > > In all of these cases, sprintf() suffices as we know that the formatted > > strings will be less than PAGE_SIZE in length. > > Hmmmm.... > I much prefer to see bounded string ops. > sysfs really ought to be passing through the buffer length. No. > The buffer size should probably be SYSFS_BUF_LEN not PAGE_SIZE > (even it happens to typically be the same). Nope. > If PAGE_SIZE is big (or small) passing a 4k buffer may be > more appropriate than a PAGE_SIZE one. Nope, sysfs is supposed to be "one value per file", and the buffer size was specifically not passed in because you should _NEVER_ need to care about it because all you are doing is printing out a single value. If you really want to print more than just a single value, you should not use sysfs. So this is designed this way on purpose, you shouldn't have to worry about any of this, and that way, you don't have to "program defensively", it all just works in a simple manner. thanks, greg k-h