Received: by 2002:a05:6a10:6006:0:0:0:0 with SMTP id w6csp610491pxa; Thu, 27 Aug 2020 10:45:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwJCAKAfBcwUgJRPIb4N2+1+WOkDhPUNKwfWdG6K4tzKx7eejG0d9esfnuRn/z/Y+DRxf7y X-Received: by 2002:a50:e809:: with SMTP id e9mr21364995edn.133.1598550359543; Thu, 27 Aug 2020 10:45:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598550359; cv=none; d=google.com; s=arc-20160816; b=fJY2WZVKICHAjEXB61YAb7vHOtJFb6zDYs8Z50v3ZpUq8/N7Pln7OfMAYw09XaJQD+ 5bNWAjWk4yFPUvh2oBKzTyCgCx7VyuzsTyd8gmk0R96bbGq1CISGbqmxPPI5mXOlXtCN 9hG9KyU5G6OmKVsmK7vUhJcYn1Y7wEi8V+LMZPLdTT4om2d3KTGh3NJJLsTa4ECsrRhC JsCmxpa/RfQMH8spgyc9u8piU8i9lAcscb0HmNEQ47wFQHz0qOQqkN+lDEPUjxO7mdjk yVcs/7QB3g7aLThDQwXZ9MRmlBjSdCTvRh8ZNmn6j+5t0cyGR1DIal4KYhCSaJ29+bAs /QsA== 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=i/1US/7nhCGJ5D5+QDR14stP/Mrv96s6Sx0hn7+4FNo=; b=Xy1INscNU+J//RbV7r+MwkNxdPqsWlvupg0MvnBWeKTMCb0zzERrXtMxGwn6uhyw4K vNGECJTtUz3+faeIC4xFFndCGonnIXzXoVIcfMCJ3R2S/bv+CiZB4LNWjCUf4FuK+ZgL 962cQ2vAs7IvN2RvwxVu5+m8ke/8O+YbauBESKmQKk6/MbV6WW+Uw7a4/1bGmgxkbUbq MBWeqHVaa3v/gDKpspvzuABMXJ3uNKosP+EbizyUkLpx68ZzY09Pa0Sx0yCuxAWh2etf pXzbMrjF5bkjLforK2OpKcrmYpMtzqQUpERIvRmgDCSBjW70bANKRazxgTvc9YKtDyoI 717Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=M7CAwUNK; 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 m64si2029851ede.91.2020.08.27.10.45.36; Thu, 27 Aug 2020 10:45:59 -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=M7CAwUNK; 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 S1726839AbgH0Roz (ORCPT + 99 others); Thu, 27 Aug 2020 13:44:55 -0400 Received: from mail.kernel.org ([198.145.29.99]:37978 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726153AbgH0Roy (ORCPT ); Thu, 27 Aug 2020 13:44:54 -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 362BB2087E; Thu, 27 Aug 2020 17:44:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1598550293; bh=hpmMkq3GeyF+UpchiZzraWqNMWLExGpqIZ25LroJiyU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=M7CAwUNKs6TIYurhYZqJ1Jwrl1o+PIGfpyinvrl8/ij0BPtWw4uMmiWGhuM3og/Qc KgLQkJZm8pFtAwJ+2xllelQk3t2RVW7KO4IOJtT31nSt/QE/UggXAPpVMBvnzziMNQ TKH84t7MY+6sXF/dMEhXfRxFK91/URzVN8/nykTo= Date: Thu, 27 Aug 2020 19:45:06 +0200 From: Greg Kroah-Hartman To: Kees Cook Cc: David Laight , '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: <20200827174506.GA705950@kroah.com> References: <20200824222322.22962-1-alex.dewar90@gmail.com> <3e882693bb344424af37d4d35f3db605@AcuMS.aculab.com> <20200825082406.GB1335351@kroah.com> <202008270936.6FF344336@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <202008270936.6FF344336@keescook> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Aug 27, 2020 at 09:49:04AM -0700, Kees Cook wrote: > On Tue, Aug 25, 2020 at 10:24:06AM +0200, Greg Kroah-Hartman wrote: > > 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. > > It really should, though. I _just_ got burned by this due to having > a binattr sysfs reachable through splice[1]. Most sysfs things aren't > binattr, but I've always considered this to be a weird fragility in the > sysfs implementation. binattr attributes do have the buffer size passed to it, for that very reason :) > > 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. > > Later in this thread there's a suggestion to alter the API to avoid > individual calls to sprintf(), which seems like a reasonable first step. I always review any patches submitted, so if someone feels like tackling this, wonderful! thanks, greg k-h