linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 00/10] sysfs: constify struct bin_attribute (Part 1)
@ 2024-11-03 17:03 Thomas Weißschuh
  2024-11-03 17:03 ` [PATCH v2 01/10] sysfs: explicitly pass size to sysfs_add_bin_file_mode_ns() Thomas Weißschuh
                   ` (11 more replies)
  0 siblings, 12 replies; 30+ messages in thread
From: Thomas Weißschuh @ 2024-11-03 17:03 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Rafael J. Wysocki, Bjorn Helgaas,
	Srinivas Kandagatla, Davidlohr Bueso, Jonathan Cameron,
	Dave Jiang, Alison Schofield, Vishal Verma, Ira Weiny,
	Alex Deucher, Christian König, Xinhui Pan, David Airlie,
	Simona Vetter, Dennis Dalessandro, Jason Gunthorpe,
	Leon Romanovsky, Tudor Ambarus, Pratyush Yadav, Michael Walle,
	Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	Naveen Krishna Chatradhi, Carlos Bilbao, Hans de Goede,
	Ilpo Järvinen, David E. Box, James E.J. Bottomley,
	Martin K. Petersen, Richard Henderson, Matt Turner,
	Frederic Barrat, Andrew Donnellan, Arnd Bergmann, Logan Gunthorpe,
	K. Y. Srinivasan, Haiyang Zhang, Wei Liu, Dexuan Cui
  Cc: Dan Williams, linux-kernel, linux-pci, linux-cxl, amd-gfx,
	dri-devel, linux-rdma, linux-mtd, platform-driver-x86, linux-scsi,
	linux-usb, linux-alpha, linuxppc-dev, linux-hyperv,
	Thomas Weißschuh

struct bin_attribute contains a bunch of pointer members, which when
overwritten by accident or malice can lead to system instability and
security problems.
Moving the definitions of struct bin_attribute to read-only memory
makes these modifications impossible.
The same change has been performed for many other structures in the
past. (struct class, struct ctl_table...)

For the structure definitions throughout the core to be moved to
read-only memory the following steps are necessary.

1) Change all callbacks invoked from the sysfs core to only pass const
   pointers
2) Adapt the sysfs core to only work in terms of const pointers
3) Adapt the sysfs core APIs to allow const pointers
4) Change all structure definitions through the core to const

This series provides the foundation for step 1) above.
It converts some callbacks in a single step to const and provides a
foundation for those callbacks where a single step is not possible.

Patches 1-5 change the bin_attribute callbacks of 'struct
attribute_group'. The remaining ones touch 'struct bin_attribute' itself.

The techniques employed by this series can later be reused for the
same change for other sysfs attributes.

This series is intended to be merged through the driver core tree.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
Changes in v2:
- Drop RFC state
- Refuse registration of attributes with both read/read_new or
  write/write_new
- Remove don't drop llseek() callback, as it is actually used.
  Instead also migrate it to "const".
- _Generic machinery: Simplify and make more robust against misuse
- Link to v1: https://lore.kernel.org/r/20241031-sysfs-const-bin_attr-v1-0-2281afa7f055@weissschuh.net

---
Thomas Weißschuh (10):
      sysfs: explicitly pass size to sysfs_add_bin_file_mode_ns()
      sysfs: introduce callback attribute_group::bin_size
      PCI/sysfs: Calculate bin_attribute size through bin_size()
      nvmem: core: calculate bin_attribute size through bin_size()
      sysfs: treewide: constify attribute callback of bin_is_visible()
      sysfs: treewide: constify attribute callback of bin_attribute::mmap()
      sysfs: treewide: constify attribute callback of bin_attribute::llseek()
      sysfs: implement all BIN_ATTR_* macros in terms of __BIN_ATTR()
      sysfs: bin_attribute: add const read/write callback variants
      driver core: Constify attribute arguments of binary attributes

 arch/alpha/kernel/pci-sysfs.c           |  6 +--
 drivers/base/node.c                     |  4 +-
 drivers/base/topology.c                 |  4 +-
 drivers/cxl/port.c                      |  2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c |  2 +-
 drivers/infiniband/hw/qib/qib_sysfs.c   |  2 +-
 drivers/misc/ocxl/sysfs.c               |  2 +-
 drivers/mtd/spi-nor/sysfs.c             |  2 +-
 drivers/nvmem/core.c                    | 16 ++++--
 drivers/pci/p2pdma.c                    |  2 +-
 drivers/pci/pci-sysfs.c                 | 42 ++++++++-------
 drivers/pci/vpd.c                       |  2 +-
 drivers/platform/x86/amd/hsmp.c         |  2 +-
 drivers/platform/x86/intel/pmt/class.c  |  2 +-
 drivers/platform/x86/intel/sdsi.c       |  2 +-
 drivers/scsi/scsi_sysfs.c               |  2 +-
 drivers/uio/uio_hv_generic.c            |  2 +-
 drivers/usb/core/sysfs.c                |  2 +-
 fs/sysfs/file.c                         | 30 +++++++----
 fs/sysfs/group.c                        |  5 +-
 fs/sysfs/sysfs.h                        |  2 +-
 include/linux/sysfs.h                   | 94 ++++++++++++++++++++-------------
 22 files changed, 138 insertions(+), 91 deletions(-)
---
base-commit: 3e5e6c9900c3d71895e8bdeacfb579462e98eba1
change-id: 20241028-sysfs-const-bin_attr-a00896481d0b

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



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

end of thread, other threads:[~2024-12-03 16:13 UTC | newest]

Thread overview: 30+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-03 17:03 [PATCH v2 00/10] sysfs: constify struct bin_attribute (Part 1) Thomas Weißschuh
2024-11-03 17:03 ` [PATCH v2 01/10] sysfs: explicitly pass size to sysfs_add_bin_file_mode_ns() Thomas Weißschuh
2024-11-03 17:03 ` [PATCH v2 02/10] sysfs: introduce callback attribute_group::bin_size Thomas Weißschuh
2024-11-05 16:12   ` Bjorn Helgaas
2024-11-06 19:27   ` Armin Wolf
2024-11-06 20:05   ` Krzysztof Wilczyński
2024-11-07  5:21     ` Greg Kroah-Hartman
2024-11-07 15:50       ` Krzysztof Wilczyński
2024-11-03 17:03 ` [PATCH v2 03/10] PCI/sysfs: Calculate bin_attribute size through bin_size() Thomas Weißschuh
2024-11-07 16:27   ` Bjorn Helgaas
2024-11-03 17:03 ` [PATCH v2 04/10] nvmem: core: calculate " Thomas Weißschuh
2024-11-08  9:58   ` Srinivas Kandagatla
2024-11-03 17:03 ` [PATCH v2 05/10] sysfs: treewide: constify attribute callback of bin_is_visible() Thomas Weißschuh
2024-11-04 13:25   ` Ilpo Järvinen
2024-11-04 13:52   ` Jason Gunthorpe
2024-11-04 14:56   ` Ira Weiny
2024-11-05  1:25   ` Martin K. Petersen
2024-11-05 15:26   ` Bjorn Helgaas
2024-11-07 17:20   ` Pratyush Yadav
2024-11-08  9:57   ` Srinivas Kandagatla
2024-11-03 17:03 ` [PATCH v2 06/10] sysfs: treewide: constify attribute callback of bin_attribute::mmap() Thomas Weißschuh
2024-11-04  1:24   ` Andrew Donnellan
2024-11-03 17:03 ` [PATCH v2 07/10] sysfs: treewide: constify attribute callback of bin_attribute::llseek() Thomas Weißschuh
2024-11-03 17:03 ` [PATCH v2 08/10] sysfs: implement all BIN_ATTR_* macros in terms of __BIN_ATTR() Thomas Weißschuh
2024-11-03 17:03 ` [PATCH v2 09/10] sysfs: bin_attribute: add const read/write callback variants Thomas Weißschuh
2024-12-03 16:06   ` James Bottomley
2024-12-03 16:11     ` Thomas Weißschuh
2024-11-03 17:03 ` [PATCH v2 10/10] driver core: Constify attribute arguments of binary attributes Thomas Weißschuh
2024-11-03 20:02 ` [PATCH v2 00/10] sysfs: constify struct bin_attribute (Part 1) Krzysztof Wilczyński
2024-11-05 16:15 ` Bjorn Helgaas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).