Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

usb: core: sysfs: Constify 'struct bin_attribute'

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>
Link: https://lore.kernel.org/r/20241222-sysfs-const-bin_attr-usb-v1-1-19a137c0f20a@weissschuh.net
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Thomas Weißschuh and committed by
Greg Kroah-Hartman
aa13b9d5 ca5d736b

+6 -6
+6 -6
drivers/usb/core/sysfs.c
··· 854 854 855 855 static ssize_t 856 856 descriptors_read(struct file *filp, struct kobject *kobj, 857 - struct bin_attribute *attr, 857 + const struct bin_attribute *attr, 858 858 char *buf, loff_t off, size_t count) 859 859 { 860 860 struct device *dev = kobj_to_dev(kobj); ··· 890 890 } 891 891 return count - nleft; 892 892 } 893 - static BIN_ATTR_RO(descriptors, 18 + 65535); /* dev descr + max-size raw descriptor */ 893 + static const BIN_ATTR_RO(descriptors, 18 + 65535); /* dev descr + max-size raw descriptor */ 894 894 895 895 static ssize_t 896 896 bos_descriptors_read(struct file *filp, struct kobject *kobj, 897 - struct bin_attribute *attr, 897 + const struct bin_attribute *attr, 898 898 char *buf, loff_t off, size_t count) 899 899 { 900 900 struct device *dev = kobj_to_dev(kobj); ··· 913 913 } 914 914 return n; 915 915 } 916 - static BIN_ATTR_RO(bos_descriptors, 65535); /* max-size BOS */ 916 + static const BIN_ATTR_RO(bos_descriptors, 65535); /* max-size BOS */ 917 917 918 918 /* When modifying this list, be sure to modify dev_bin_attrs_are_visible() 919 919 * accordingly. 920 920 */ 921 - static struct bin_attribute *dev_bin_attrs[] = { 921 + static const struct bin_attribute *const dev_bin_attrs[] = { 922 922 &bin_attr_descriptors, 923 923 &bin_attr_bos_descriptors, 924 924 NULL ··· 944 944 } 945 945 946 946 static const struct attribute_group dev_bin_attr_grp = { 947 - .bin_attrs = dev_bin_attrs, 947 + .bin_attrs_new = dev_bin_attrs, 948 948 .is_bin_visible = dev_bin_attrs_are_visible, 949 949 }; 950 950