Received: by 2002:a05:6a10:6006:0:0:0:0 with SMTP id w6csp576483pxa; Thu, 27 Aug 2020 09:52:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxU7fDM0vzCk9AaZHcxxbI6w5xkhijiJ5CjXDDoFnFmR9UQD79V4M1G2wKKuunna8BFS8vR X-Received: by 2002:a17:906:4305:: with SMTP id j5mr4743855ejm.102.1598547137199; Thu, 27 Aug 2020 09:52:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598547137; cv=none; d=google.com; s=arc-20160816; b=Gxiin9Vwl16/hQXT4g6FHZhoP46aCdtzfOihA59BI5UcoEc/q1yS1NlV0+IBxJZes6 fo7uML65ZA1JhnbJKgxD0/5jk9xgP/1HVMnH79or1/GS+GgDPlGOk1XJT47kDgcOs4gi 31AfsOYuXyk9vcpIEB7fKAtuzqpbjilS8JF9DE/TIEfeCoVzPQSZ/6qheojvQ+s85pRA HZtV2iu3muM4LbmfrJj2yJGMjjjqaXz/g5AfZpxIIC7UcJfi2uqNdxowmn4JxdUeaVtk /o3FfTSlc8de48NzQH+VL6K2YlpHEbiAGYCevgH7hQ6l1mQik8GYdeHfV554VqHBwUjs e9nA== 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=WiGBqbvIsFO7z3w2LMazIC2FdnllWalUyM7tW1jEsT8=; b=aCFS2bzjLmFAQRxBqQAG8QjsHDuj5TLc7lKnfhADRCMq82knsWV4cekg+i77QF6YsX m2+gAt0OW3mFuZI9lb052V6G9XsfeYcmU3g05IZ/aNWXERPShYIpW9zgGxO+fAuyJ3F/ QhY9VbkJPfDzM5C6e6citimDGjLW+x9sh+5UIPKWpvAgRibZC264LsXDie/C14wgMDyr zNT4XSYhElnePq0+nOdJC20ocqdoYZ7wOPJqlZS9XGRXyht0LoSUAoXlc6vw6NsVsXLi noCnUodVWhbMiBYO687isMK+D8VU17jPp6/GKdO8my4Q1XUPbkIuVlYbWfe88/a59ksp dd+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=PfLeP1nV; 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=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a1si1886443edn.356.2020.08.27.09.51.54; Thu, 27 Aug 2020 09:52:17 -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=@chromium.org header.s=google header.b=PfLeP1nV; 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=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727850AbgH0QtO (ORCPT + 99 others); Thu, 27 Aug 2020 12:49:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51830 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727064AbgH0QtI (ORCPT ); Thu, 27 Aug 2020 12:49:08 -0400 Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C17EC06121B for ; Thu, 27 Aug 2020 09:49:07 -0700 (PDT) Received: by mail-pg1-x544.google.com with SMTP id p37so3779784pgl.3 for ; Thu, 27 Aug 2020 09:49:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=WiGBqbvIsFO7z3w2LMazIC2FdnllWalUyM7tW1jEsT8=; b=PfLeP1nV8B3U6EqkOgNzN84iR7UUy8/qiTcl/n3tYajHLnYHYm389y0pz4BY9Of1PY JgbSGcf1d7WEcDLjR1sQPrpu42wCr6/27pbNXF5vziV/LDpvB3m0qY5a0GAkUWJWVU8A EVZ6HlhvzrsITdJad7o0fkqp6zaLStbRbS/0o= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=WiGBqbvIsFO7z3w2LMazIC2FdnllWalUyM7tW1jEsT8=; b=TfeyvzfHb7e38ZlPDhrIQZYaX48vWqBgRywxSm6LBe0VPpgyol3asSQTelgTKT8kEL XyJCduOxCXb9EJOYD8uQ6NgU4Ws7nRJ6MhWA2v8XOcoMkNK5yCXk91anQXdLE9ibtGYK V4We++Jc8gLZbNYuxgpvUcK88tjJGuSi/aPoYUKJ32I0vElc4ZHGMvOlNcTrikGin11+ sKSJ+bWKYp3BBzWi6tXG22hULAn8fGBWaMiQOkTG/IdCeitX9bdUmUcrIuyG/TliPzL/ 3dAIotII5roOmgn7SQKQSoznD6FIIAd8jr36Sd99yukW/YkZt3AuFINH6r3Z6ec56fJn EASw== X-Gm-Message-State: AOAM533LC1vYtTZtU20QxY16RvTza1xpQNMYPvpjj1/3bQ2TbwAppqup KZPOXRwltAZsiaM+TNgLFMmfNg== X-Received: by 2002:a62:1803:: with SMTP id 3mr17714286pfy.198.1598546946678; Thu, 27 Aug 2020 09:49:06 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id m3sm2665362pjn.28.2020.08.27.09.49.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Aug 2020 09:49:05 -0700 (PDT) Date: Thu, 27 Aug 2020 09:49:04 -0700 From: Kees Cook To: Greg Kroah-Hartman 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: <202008270936.6FF344336@keescook> References: <20200824222322.22962-1-alex.dewar90@gmail.com> <3e882693bb344424af37d4d35f3db605@AcuMS.aculab.com> <20200825082406.GB1335351@kroah.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200825082406.GB1335351@kroah.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 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. > 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. -Kees [1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=11990a5bd7e558e9203c1070fc52fb6f0488e75b -- Kees Cook