Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp68194pxb; Mon, 13 Sep 2021 13:09:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzkPblTYp+fJ0rvgFjfgXU2CvbqKL35xsdKQwrRGJZQTnGFG3hjoPr8Eckp/E+UZ6pPMZ+D X-Received: by 2002:a05:6402:16d9:: with SMTP id r25mr14830254edx.80.1631563746438; Mon, 13 Sep 2021 13:09:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631563746; cv=none; d=google.com; s=arc-20160816; b=B2ixVp9FQVqBw0ZlTHfr7TR1Cu9FM0vF44IIbCkkAA8t/llY4e7FyzIDhvJwdabmCJ 6H/Sa98/UOAzNnEiyp1fquMynOL6XuSnhDslxKuz2VA3kD83DtFC8kjVNlJz1//SQ2cj PmZKJ2ORe8bBAeCID4MH8ynwMVVTG7i9/ou04SF85BGw5+xH1ZjI/IS0VCEDd+m1j0uz 9RBuL21sonHkVqGHohYKSpN3Z6EcKqxLSVPK83UNV123oSYyNakcLG/9YvpF4Wgnf2Zu qPEXGXU/NztjcgJBUMJdSyRBTKCd6h6gsDUuKi43gVMCG/Yf4vkhpq/Fhpp1CzT+GEp3 bCsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=qmLjCVlFZpaK3r52mQqtw8m9DqaffX/kXPwOw+RgCvU=; b=j2lhNQl2B/ZjLKw/BgyJCwPCC8Qd+08wucOuWhHhTVAVyKNg8TkxgWVgZg/1TPx7MQ 8tOX4WMABDhGMZa1FTbuh99DfaPEVa9rlzkpvsd6OoFIWv/Nn3r6s/4nzH8rrkH+ZxAW zLvggtxce7zynFC6HDykgXtIHp713ASpaTMlIYlrbU7Cgm/tKoIg0a3hGhlT5Y1ZhWoR exWovnWBGAF74KZs23CQnq+3E3YmcqLRcU1fDMWAtnCnUjraMFb7r7DixONGb/6Pn8Ho GqCKNKgYLY0t4a4Fl/6jY5uh0h7gxYFsI46dp6Er+k7yN1l1MGPUM2Ukr6jwL2vQ+FfB 67tA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cn22si7367574edb.314.2021.09.13.13.08.42; Mon, 13 Sep 2021 13:09:06 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236180AbhIMNsq (ORCPT + 99 others); Mon, 13 Sep 2021 09:48:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:46760 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241915AbhIMNoG (ORCPT ); Mon, 13 Sep 2021 09:44:06 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id AB37C61439; Mon, 13 Sep 2021 13:30:59 +0000 (UTC) Date: Mon, 13 Sep 2021 15:30:57 +0200 From: Christian Brauner To: Christoph Hellwig Cc: Greg Kroah-Hartman , "Rafael J. Wysocki" , Alexander Viro , Jens Axboe , Tejun Heo , linux-block@vger.kernel.org, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 07/13] sysfs: add ->seq_show support to sysfs_ops Message-ID: <20210913133057.jecjno7uswlvfdu2@wittgenstein> References: <20210913054121.616001-1-hch@lst.de> <20210913054121.616001-8-hch@lst.de> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20210913054121.616001-8-hch@lst.de> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Sep 13, 2021 at 07:41:15AM +0200, Christoph Hellwig wrote: > Allow attributes to directly use the seq_file method instead of > carving out a buffer that can easily lead to buffer overflows. > > Signed-off-by: Christoph Hellwig > --- Acked-by: Christian Brauner > fs/sysfs/file.c | 19 ++++++++++++++----- > include/linux/sysfs.h | 9 +++++++-- > 2 files changed, 21 insertions(+), 7 deletions(-) > > diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c > index 42dcf96881b68..12e0bfe40a2b4 100644 > --- a/fs/sysfs/file.c > +++ b/fs/sysfs/file.c > @@ -45,6 +45,9 @@ static int sysfs_kf_seq_show(struct seq_file *sf, void *v) > ssize_t count; > char *buf; > > + if (ops->seq_show) > + return ops->seq_show(kobj, of->kn->priv, sf); > + > if (WARN_ON_ONCE(!ops->show)) > return -EINVAL; > > @@ -268,6 +271,10 @@ int sysfs_add_file_mode_ns(struct kernfs_node *parent, > return -EINVAL; > > if (mode & SYSFS_PREALLOC) { > + if (WARN(sysfs_ops->seq_show, KERN_ERR > + "seq_show not supported on prealloc file: %s\n", > + kobject_name(kobj))) > + return -EINVAL; > if (sysfs_ops->show && sysfs_ops->store) > ops = &sysfs_prealloc_kfops_rw; > else if (sysfs_ops->show) > @@ -275,12 +282,14 @@ int sysfs_add_file_mode_ns(struct kernfs_node *parent, > else if (sysfs_ops->store) > ops = &sysfs_prealloc_kfops_wo; > } else { > - if (sysfs_ops->show && sysfs_ops->store) > - ops = &sysfs_file_kfops_rw; > - else if (sysfs_ops->show) > - ops = &sysfs_file_kfops_ro; > - else if (sysfs_ops->store) > + if (sysfs_ops->seq_show || sysfs_ops->show) { > + if (sysfs_ops->store) > + ops = &sysfs_file_kfops_rw; > + else > + ops = &sysfs_file_kfops_ro; > + } else if (sysfs_ops->store) { > ops = &sysfs_file_kfops_wo; > + } > } > > if (!ops) > diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h > index e3f1e8ac1f85b..e1ab4da716730 100644 > --- a/include/linux/sysfs.h > +++ b/include/linux/sysfs.h > @@ -236,8 +236,13 @@ struct bin_attribute bin_attr_##_name = __BIN_ATTR_WO(_name, _size) > struct bin_attribute bin_attr_##_name = __BIN_ATTR_RW(_name, _size) > > struct sysfs_ops { > - ssize_t (*show)(struct kobject *, struct attribute *, char *); > - ssize_t (*store)(struct kobject *, struct attribute *, const char *, size_t); > + int (*seq_show)(struct kobject *kobj, struct attribute *attr, > + struct seq_file *sf); > + ssize_t (*store)(struct kobject *kobj, struct attribute *attr, > + const char *buf, size_t size); > + > + /* deprecated except for preallocated attributes: */ > + ssize_t (*show)(struct kobject *kob, struct attribute *attr, char *buf); > }; > > #ifdef CONFIG_SYSFS > -- > 2.30.2 >