mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/2] devcoredump: Constify 'struct bin_attribute'
@ 2025-01-14 21:44 Thomas Weißschuh
  2025-01-14 21:44 ` [PATCH 1/2] devcoredump: Define 'struct bin_attribute' through macro Thomas Weißschuh
  2025-01-14 21:44 ` [PATCH 2/2] devcoredump: Constify 'struct bin_attribute' Thomas Weißschuh
  0 siblings, 2 replies; 3+ messages in thread
From: Thomas Weißschuh @ 2025-01-14 21:44 UTC (permalink / raw)
  To: Johannes Berg, Greg Kroah-Hartman, Rafael J. Wysocki
  Cc: linux-kernel, Thomas Weißschuh

The sysfs core now allows instances of 'struct bin_attribute' to be
moved into read-only memory. Make use of that to protect them against
accidental or malicious modifications.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
Thomas Weißschuh (2):
      devcoredump: Define 'struct bin_attribute' through macro
      devcoredump: Constify 'struct bin_attribute'

 drivers/base/devcoredump.c | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)
---
base-commit: 7f5b6a8ec18e3add4c74682f60b90c31bdf849f2
change-id: 20250114-sysfs-const-bin_attr-devcoredump-050ce1805209

Best regards,
-- 
Thomas Weißschuh <linux@weissschuh.net>


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] devcoredump: Define 'struct bin_attribute' through macro
  2025-01-14 21:44 [PATCH 0/2] devcoredump: Constify 'struct bin_attribute' Thomas Weißschuh
@ 2025-01-14 21:44 ` Thomas Weißschuh
  2025-01-14 21:44 ` [PATCH 2/2] devcoredump: Constify 'struct bin_attribute' Thomas Weißschuh
  1 sibling, 0 replies; 3+ messages in thread
From: Thomas Weißschuh @ 2025-01-14 21:44 UTC (permalink / raw)
  To: Johannes Berg, Greg Kroah-Hartman, Rafael J. Wysocki
  Cc: linux-kernel, Thomas Weißschuh

The macro saves some lines of code and simplifies the constification of
the attribute.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
 drivers/base/devcoredump.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/base/devcoredump.c b/drivers/base/devcoredump.c
index c795edad1b969bc212dda5bd37578cb83118e850..13b3614c9ac911e704d3485b4f0370ce3b0afff6 100644
--- a/drivers/base/devcoredump.c
+++ b/drivers/base/devcoredump.c
@@ -132,12 +132,8 @@ static ssize_t devcd_data_write(struct file *filp, struct kobject *kobj,
 	return count;
 }
 
-static struct bin_attribute devcd_attr_data = {
-	.attr = { .name = "data", .mode = S_IRUSR | S_IWUSR, },
-	.size = 0,
-	.read = devcd_data_read,
-	.write = devcd_data_write,
-};
+static struct bin_attribute devcd_attr_data =
+	__BIN_ATTR(data, 0600, devcd_data_read, devcd_data_write, 0);
 
 static struct bin_attribute *devcd_dev_bin_attrs[] = {
 	&devcd_attr_data, NULL,

-- 
2.48.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 2/2] devcoredump: Constify 'struct bin_attribute'
  2025-01-14 21:44 [PATCH 0/2] devcoredump: Constify 'struct bin_attribute' Thomas Weißschuh
  2025-01-14 21:44 ` [PATCH 1/2] devcoredump: Define 'struct bin_attribute' through macro Thomas Weißschuh
@ 2025-01-14 21:44 ` Thomas Weißschuh
  1 sibling, 0 replies; 3+ messages in thread
From: Thomas Weißschuh @ 2025-01-14 21:44 UTC (permalink / raw)
  To: Johannes Berg, Greg Kroah-Hartman, Rafael J. Wysocki
  Cc: linux-kernel, Thomas Weißschuh

The sysfs core now allows instances of 'struct bin_attribute' to be
moved into read-only memory. Make use of that to protect them against
accidental or malicious modifications.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
 drivers/base/devcoredump.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/base/devcoredump.c b/drivers/base/devcoredump.c
index 13b3614c9ac911e704d3485b4f0370ce3b0afff6..031b0d2ec924184f3b868fbaa3790b7f98bc9e2c 100644
--- a/drivers/base/devcoredump.c
+++ b/drivers/base/devcoredump.c
@@ -106,7 +106,7 @@ static void devcd_del(struct work_struct *wk)
 }
 
 static ssize_t devcd_data_read(struct file *filp, struct kobject *kobj,
-			       struct bin_attribute *bin_attr,
+			       const struct bin_attribute *bin_attr,
 			       char *buffer, loff_t offset, size_t count)
 {
 	struct device *dev = kobj_to_dev(kobj);
@@ -116,7 +116,7 @@ static ssize_t devcd_data_read(struct file *filp, struct kobject *kobj,
 }
 
 static ssize_t devcd_data_write(struct file *filp, struct kobject *kobj,
-				struct bin_attribute *bin_attr,
+				const struct bin_attribute *bin_attr,
 				char *buffer, loff_t offset, size_t count)
 {
 	struct device *dev = kobj_to_dev(kobj);
@@ -132,15 +132,15 @@ static ssize_t devcd_data_write(struct file *filp, struct kobject *kobj,
 	return count;
 }
 
-static struct bin_attribute devcd_attr_data =
+static const struct bin_attribute devcd_attr_data =
 	__BIN_ATTR(data, 0600, devcd_data_read, devcd_data_write, 0);
 
-static struct bin_attribute *devcd_dev_bin_attrs[] = {
+static const struct bin_attribute *const devcd_dev_bin_attrs[] = {
 	&devcd_attr_data, NULL,
 };
 
 static const struct attribute_group devcd_dev_group = {
-	.bin_attrs = devcd_dev_bin_attrs,
+	.bin_attrs_new = devcd_dev_bin_attrs,
 };
 
 static const struct attribute_group *devcd_dev_groups[] = {

-- 
2.48.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-01-14 21:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-01-14 21:44 [PATCH 0/2] devcoredump: Constify 'struct bin_attribute' Thomas Weißschuh
2025-01-14 21:44 ` [PATCH 1/2] devcoredump: Define 'struct bin_attribute' through macro Thomas Weißschuh
2025-01-14 21:44 ` [PATCH 2/2] devcoredump: Constify 'struct bin_attribute' Thomas Weißschuh

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®