lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240605192934.742369-3-martin.oliveira@eideticom.com>
Date: Wed,  5 Jun 2024 13:29:30 -0600
From: Martin Oliveira <martin.oliveira@...eticom.com>
To: linux-rdma@...r.kernel.org,
	linux-kernel@...r.kernel.org,
	linux-pci@...r.kernel.org,
	linux-mm@...ck.org
Cc: Jason Gunthorpe <jgg@...pe.ca>,
	Leon Romanovsky <leon@...nel.org>,
	Bjorn Helgaas <bhelgaas@...gle.com>,
	Logan Gunthorpe <logang@...tatee.com>,
	Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
	Tejun Heo <tj@...nel.org>,
	"Rafael J. Wysocki" <rafael@...nel.org>,
	Andrew Morton <akpm@...ux-foundation.org>,
	Mike Marciniszyn <mike.marciniszyn@...el.com>,
	Michael Guralnik <michaelgur@...dia.com>,
	Martin Oliveira <martin.oliveira@...eticom.com>,
	Dan Williams <dan.j.williams@...el.com>,
	Ard Biesheuvel <ardb@...nel.org>,
	Valentine Sinitsyn <valesini@...dex-team.ru>,
	Lukas Wunner <lukas@...ner.de>
Subject: [PATCH 2/6] sysfs: add mmap_allocates parameter to struct bin_attribute

Now that a struct kernfs_ops can have an "mmap_allocates" parameter to
avoid the page_mkwrite() operator, the struct bin_attribute needs a way
to choose the appropriate kernfs_ops.

Introduce a "mmap_allocates" boolean on struct bin_attribute to achieve
that.

Co-developed-by: Logan Gunthorpe <logang@...tatee.com>
Signed-off-by: Logan Gunthorpe <logang@...tatee.com>
Signed-off-by: Martin Oliveira <martin.oliveira@...eticom.com>
---
 fs/sysfs/file.c       | 25 +++++++++++++++++++------
 include/linux/sysfs.h |  1 +
 2 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
index d1995e2d6c94..77c21009ceee 100644
--- a/fs/sysfs/file.c
+++ b/fs/sysfs/file.c
@@ -264,6 +264,15 @@ static const struct kernfs_ops sysfs_bin_kfops_mmap = {
 	.llseek		= sysfs_kf_bin_llseek,
 };
 
+static const struct kernfs_ops sysfs_bin_kfops_mmap_allocates = {
+	.read		= sysfs_kf_bin_read,
+	.write		= sysfs_kf_bin_write,
+	.mmap		= sysfs_kf_bin_mmap,
+	.open		= sysfs_kf_bin_open,
+	.llseek		= sysfs_kf_bin_llseek,
+	.mmap_allocates = true,
+};
+
 int sysfs_add_file_mode_ns(struct kernfs_node *parent,
 		const struct attribute *attr, umode_t mode, kuid_t uid,
 		kgid_t gid, const void *ns)
@@ -323,16 +332,20 @@ int sysfs_add_bin_file_mode_ns(struct kernfs_node *parent,
 	const struct kernfs_ops *ops;
 	struct kernfs_node *kn;
 
-	if (battr->mmap)
-		ops = &sysfs_bin_kfops_mmap;
-	else if (battr->read && battr->write)
+	if (battr->mmap) {
+		if (battr->mmap_allocates)
+			ops = &sysfs_bin_kfops_mmap_allocates;
+		else
+			ops = &sysfs_bin_kfops_mmap;
+	} else if (battr->read && battr->write) {
 		ops = &sysfs_bin_kfops_rw;
-	else if (battr->read)
+	} else if (battr->read) {
 		ops = &sysfs_bin_kfops_ro;
-	else if (battr->write)
+	} else if (battr->write) {
 		ops = &sysfs_bin_kfops_wo;
-	else
+	} else {
 		ops = &sysfs_file_kfops_empty;
+	}
 
 #ifdef CONFIG_DEBUG_LOCK_ALLOC
 	if (!attr->ignore_lockdep)
diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
index a7d725fbf739..190b4b9355df 100644
--- a/include/linux/sysfs.h
+++ b/include/linux/sysfs.h
@@ -294,6 +294,7 @@ struct bin_attribute {
 	struct attribute	attr;
 	size_t			size;
 	void			*private;
+	bool			mmap_allocates;
 	struct address_space *(*f_mapping)(void);
 	ssize_t (*read)(struct file *, struct kobject *, struct bin_attribute *,
 			char *, loff_t, size_t);
-- 
2.34.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ