]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
nvmem: core: limit cell sysfs permissions to main attribute ones
authorThomas Weißschuh <linux@weissschuh.net>
Fri, 28 Jun 2024 11:37:04 +0000 (12:37 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 3 Jul 2024 14:37:51 +0000 (16:37 +0200)
The cell sysfs attribute should not provide more access to the nvmem
data than the main attribute itself.
For example if nvme_config::root_only was set, the cell attribute
would still provide read access to everybody.

Mask out permissions not available on the main attribute.

Fixes: 0331c611949f ("nvmem: core: Expose cells through sysfs")
Cc: stable@vger.kernel.org
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Link: https://lore.kernel.org/r/20240628113704.13742-5-srinivas.kandagatla@linaro.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/nvmem/core.c

index 1285300ed239e9979e040f12835e5c9cc4052dbc..f8dd7eb40fbe1ddfcd76d287235d674e98543479 100644 (file)
@@ -462,7 +462,7 @@ static int nvmem_populate_sysfs_cells(struct nvmem_device *nvmem)
                                                    "%s@%x,%x", entry->name,
                                                    entry->offset,
                                                    entry->bit_offset);
-               attrs[i].attr.mode = 0444;
+               attrs[i].attr.mode = 0444 & nvmem_bin_attr_get_umode(nvmem);
                attrs[i].size = entry->bytes;
                attrs[i].read = &nvmem_cell_attr_read;
                attrs[i].private = entry;