Received: by 2002:a05:6a10:6006:0:0:0:0 with SMTP id w6csp1700142pxa; Fri, 28 Aug 2020 23:25:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxY+AsxEp9u19+PK+6SIOjqsGQgR7DvCtE72kq3VhXTwRWA6wD5FEOAnr1DSSUvvRzfm+cP X-Received: by 2002:a17:906:f28b:: with SMTP id gu11mr2183920ejb.407.1598682353286; Fri, 28 Aug 2020 23:25:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598682353; cv=none; d=google.com; s=arc-20160816; b=WhV8TTLtPgJDuLszqURrqapfKfVrw7/hXE+2rc8RAPv3KKfN5eDTKh525EFy5FLsWh aodbqh+fWKoYKtoui8xuMq8aV633gEXT9BOOQOi6L3gUkyDIJynNiA1VFOAu0dPMNzRp tI6tHD6ZtxCwJXxIlIHgqb4BmqWZrOHZoc5QfAGcxqysZTYKka60I+I+UFdqnkamYEf4 nazpq+B6KXBy42vYm5cJGSwteSF7OLZzVJoJLPj33MStLM+l2x5s5NfiHtdGUD1IdkNR OGPacoG7/IWUCnNXctKzzV6Z4Xl21y1dH+NVgulNnFXc+I3KOnYYfrMDdGOtJL4dI+2B YxwQ== 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=vxGbYKa8gdOD3qRxbcU9pASBmB2OCkKyP6wN2a4bELk=; b=FsBb7D0ybN+hBameRGppso5FKdr+Xyv49PRIesV1YhjJ5xUBBdASyQZK4iK3q1YX3V IDHSf07h4UktRx0zD3yrOUqvKbzjQgM6cR9gYL1n0SpNg5uox0FWEgtb4QeunLdXJB33 /csU1Syl1t2/pSaeSW6XKWJ7vnVAmz2s59S4AH/1mVKP3gI3QYCvE0eU2cuRSJIoxjW+ 1i/G1qFGRcktgojw4NXeLVndyhuKl3YsOUpSKmUV9Zuqd9OIK7w2SqkxxMYSxe+imxuy Rk3ij3bEvUba9DW/qsqEjWJF8sNhGvsQ8CVOORLeBmkNfxopfVdL78ZL+E7Z2U0Rho0l rJYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ddnS9IL6; 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 dn23si949971edb.206.2020.08.28.23.25.15; Fri, 28 Aug 2020 23:25:53 -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=ddnS9IL6; 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 S1726020AbgH2GW6 (ORCPT + 99 others); Sat, 29 Aug 2020 02:22:58 -0400 Received: from mail.kernel.org ([198.145.29.99]:55710 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725886AbgH2GW5 (ORCPT ); Sat, 29 Aug 2020 02:22:57 -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 BDAC020936; Sat, 29 Aug 2020 06:22:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1598682177; bh=RTA0q4bRMzKQsANHsZ7dyfTLiK9cKvaBNIooZBkpUFc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=ddnS9IL6jqajQ43UItWlH5QVfTc64BnWlPCjw7uuPDngAgJASNwyk2p6hJgpviFYX j+CDxctZXt8pCoSARnlNPHwpci48u/9Ah7ezdgWWElXxkBdOpNhCpOQwda07nXg3Td cfcCYEeF4npNiEGPtq82cwspVWZNveIhCf6dycyc= Date: Sat, 29 Aug 2020 08:22:54 +0200 From: Greg Kroah-Hartman To: Joe Perches Cc: "Rafael J. Wysocki" , Kees Cook , "Gustavo A . R . Silva" , Denis Efremov , Julia Lawall , Alex Dewar , linux-kernel@vger.kernel.org Subject: Re: [PATCH] sysfs: Add sysfs_emit to replace sprintf to PAGE_SIZE buffers. Message-ID: <20200829062254.GA79296@kroah.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Aug 28, 2020 at 03:52:13PM -0700, Joe Perches wrote: > sprintf does not know the PAGE_SIZE maximum of the temporary buffer > used for outputting sysfs content requests and it's possible to > overrun the buffer length. > > Add a generic sysfs_emit mechanism that knows that the size of the > temporary buffer and ensures that no overrun is done. > > Signed-off-by: Joe Perches > --- > fs/sysfs/file.c | 30 ++++++++++++++++++++++++++++++ > include/linux/sysfs.h | 8 ++++++++ > 2 files changed, 38 insertions(+) > > diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c > index eb6897ab78e7..06a13bbd7080 100644 > --- a/fs/sysfs/file.c > +++ b/fs/sysfs/file.c > @@ -707,3 +707,33 @@ int sysfs_change_owner(struct kobject *kobj, kuid_t kuid, kgid_t kgid) > return 0; > } > EXPORT_SYMBOL_GPL(sysfs_change_owner); > + > +/** > + * sysfs_emit - scnprintf equivalent, aware of PAGE_SIZE buffer. > + * @buf: start of PAGE_SIZE buffer. > + * @pos: current position in buffer > + * (pos - buf) must always be < PAGE_SIZE sysfs files are always supposed to be "one value per file", so why would you ever need a 'pos' variable to show the location in the buffer? This would encourage people to do things they shouldn't be doing, and it makes the people who are doing things properly, have to constantly see 'pos' as something that maybe they should be using? I think if you tried to convert a subsystem to use this (try USB as an example), you would see why that parameter isn't needed. thanks, greg k-h