nvmem: core: Set no-read-write provider to avoid userspace read/write
Subsystems (2)
PATCH v2 1/1 nvmem: core: Set no-read-write provider to avoid userspace read/write
Current nvmem framework allows user space to read all register space populated by nvmem binary file, In case we don't want to expose value of registers to userspace and only want kernel space to read cell value from nvmem_cell_read_u32.
To protect the same, Add no-read-write property to prevent read from userspace.
---
v2: Fix build error
v1: Fix no_read_write update condition
drivers/nvmem/core.c +12 -0
@@ -27,6 +27,7 @@ struct nvmem_device {struct kref refcnt;size_t size;bool read_only; +bool no_read_write;int flags;enum nvmem_type type;struct bin_attribute eeprom;
@@ -120,6 +121,10 @@ static ssize_t bin_attr_nvmem_read(struct file *filp, struct kobject *kobj, dev = container_of(kobj, struct device, kobj); nvmem =to_nvmem_device (dev); +/* if no-read-write, then stop from reading */ +if (nvmem->no_read_write) +return -EPERM ; +/* Stop the user from reading */ if (pos >= nvmem->size)return 0 ;
@@ -154,6 +159,10 @@ static ssize_t bin_attr_nvmem_write(struct file *filp, struct kobject *kobj, dev = container_of(kobj, struct device, kobj); nvmem =to_nvmem_device (dev); +/* if no-read-write, then stop from writing */ +if (nvmem->no_read_write) +return -EPERM ; +/* Stop the user from writing */ if (pos >= nvmem->size)return -EFBIG ;
@@ -651,6 +660,9 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) nvmem->read_only =device_property_present (config->dev,"read-only" ) || config->read_only || !nvmem->reg_write; + nvmem->no_read_write =device_property_present (config->dev, +"no-read-write" ); +if (config->root_only) nvmem->dev.groups = nvmem->read_only ? nvmem_ro_root_dev_groups :
Signature · 2 lines
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
Quoted 8 lines · Gaurav Kohli
Current nvmem framework allows user space to read all register space populated by nvmem binary file, In case we don't want to expose value of registers to userspace and only want kernel space to read cell value from
nvmem_cell_read_u32.To protect the same, Add no-read-write property to prevent read from userspace.
Can you explain the real need of this?
Is there any issue you are noticing while reading nvmem content from userspace?
I don't think this is the right way to do this, its misleading in many ways. Also this should not be a part of DT binding.
If we decide that we need this feature, then better way to do this using a new Kernel config.
thanks,
srini
Quoted 8 lines · Srinivas Kandagatla
Quoted 5 lines · Gaurav Kohli
Current nvmem framework allows user space to read all register space populated by nvmem binary file, In case we don't want to expose value of registers to userspace and only want kernel space to read cell value from
nvmem_cell_read_u32.
Quoted 7 lines
Quoted 3 lines
To protect the same, Add no-read-write property to prevent read from userspace.
Can you explain the real need of this?
Is there any issue you are noticing while reading nvmem content from userspace?
Hi Srinivas,
No, We are not observing any issue, nvmem is dumping the data properly.
But there are certain register, which we don't want to expose to user space and want kernel space can only read via nvmem_cell_read.
In existing design, even if we read cell from kernel space, nvmem binary files is still populated to user space unconditionally.
Regards
Gaurav
Quoted 6 lines
I don't think this is the right way to do this, its misleading in many ways. Also this should not be a part of DT binding.
If we decide that we need this feature, then better way to do this using a new Kernel config.
thanks,
srini
-- Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
Quoted 17 lines · Gaurav Kohli
Quoted 8 lines · Srinivas Kandagatla
Quoted 5 lines · Gaurav Kohli
Current nvmem framework allows user space to read all register space populated by nvmem binary file, In case we don't want to expose value of registers to userspace and only want kernel space to read cell value from
nvmem_cell_read_u32.Quoted 7 lines
Quoted 3 lines
To protect the same, Add no-read-write property to prevent read from userspace.
Can you explain the real need of this?
Is there any issue you are noticing while reading nvmem content from userspace?
Quoted 6 lines
Hi Srinivas,
No, We are not observing any issue, nvmem is dumping the data properly.
But there are certain register, which we don't want to expose to user space and want kernel space can only read via
nvmem_cell_read.
Am guessing these are some kind of keys or something that you do not want user to see.
Is root only option not helping you in this case?
We could go down the route of adding new config option something like CONFIG_NVMEM_NO_SYSFS_ENTRY to prevent adding nvmem entry in userspace.
Let me know if you are happy to create a patch for this change?
Thanks,
srini
Quoted 6 lines
In existing design, even if we read cell from kernel space, nvmem binary files is still populated to user space unconditionally.
Regards
Gaurav
Quoted 20 lines · Srinivas Kandagatla
Quoted 17 lines · Gaurav Kohli
Quoted 15 lines · Srinivas Kandagatla
Quoted 8 lines · Gaurav Kohli
Current nvmem framework allows user space to read all register space populated by nvmem binary file, In case we don't want to expose value of registers to userspace and only want kernel space to read cell value from
nvmem_cell_read_u32.To protect the same, Add no-read-write property to prevent read from userspace.
Can you explain the real need of this?
Is there any issue you are noticing while reading nvmem content from userspace?
Quoted 8 lines
Quoted 6 lines
Hi Srinivas,
No, We are not observing any issue, nvmem is dumping the data properly.
But there are certain register, which we don't want to expose to user space and want kernel space can only read via
nvmem_cell_read.Am guessing these are some kind of keys or something that you do not want user to see.
Hi Srinivas,
Thanks.
Yes exactly, there are certain keys or even certain bit that we don't want to expose to user.
Quoted 1 line
Is root only option not helping you in this case?
Yes we want to protect at root level as well, i mean it is better if we can avoid exposing to userspace at all.
Quoted 4 lines
We could go down the route of adding new config option something like
CONFIG_NVMEM_NO_SYSFS_ENTRYto prevent adding nvmem entry in userspace.Let me know if you are happy to create a patch for this change?
I am happy with either way config option or dt binding(seems easy), please let me know we will post new patch for the same.
In config option, do i have to remove all binary creation code of nvmem , correct? or simply put a check like dt binding option
so user cannot read it.
Thanks
Gaurav
Quoted 10 lines
Thanks,
sriniQuoted 6 lines
In existing design, even if we read cell from kernel space, nvmem binary files is still populated to user space unconditionally.
Regards
Gaurav
Signature · 3 lines
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
Quoted 5 lines · Gaurav Kohli
Quoted 2 lines · Srinivas Kandagatla
Am guessing these are some kind of keys or something that you do not want user to see.
Quoted 7 lines
Yes exactly, there are certain keys or even certain bit that we don't want to expose to user.
Quoted 1 line
Is root only option not helping you in this case?
Yes we want to protect at root level as well, I mean it is better if we can avoid exposing to userspace at all.
NB: root has access to /dev/mem and /dev/kmem (and probably other ways into the kernel)
Quoted 7 lines
Quoted 4 lines
We could go down the route of adding new config option something like
CONFIG_NVMEM_NO_SYSFS_ENTRYto prevent adding nvmem entry in userspace.Let me know if you are happy to create a patch for this change?
I am happy with either way, config option or DT binding (seems easy), please let me know we will post new patch for the same.
Device tree nodes are supposed to be hardware descriptions. Obviously, implementing security policies such as "hide this information from user-space" is not a good fit for a DT node.
The qcom kernel is full of "config knobs" in DT nodes. It would be good if you could spread the word, and slowly turn things around :-)
Regards.
Quoted 3 lines · Gaurav Kohli
Quoted 2 lines
Is root only option not helping you in this case?
Yes we want to protect at root level as well, i mean it is better if we can avoid exposing to userspace at all.
Can you try below patch!
Quoted 6 lines
Quoted 4 lines
We could go down the route of adding new config option something like
CONFIG_NVMEM_NO_SYSFS_ENTRYto prevent adding nvmem entry in userspace.Let me know if you are happy to create a patch for this change?
I am happy with either way config option or dt binding(seems easy), please let me know we will post new patch for the same.
DT way is totally NAK.
--------------------------->cut<-----------------------------------
From: Srinivas Kandagatla <[email protected]>
Date: Wed, 20 Mar 2019 16:15:21 +0000
Subject: [PATCH] nvmem: core: add support to NVMEM_NO_SYSFS_ENTRY
Some users might not want to expose nvmem entry to sysfs and only intend to use kernel interface so add such provision.
--- Documentation/ABI/stable/sysfs-bus-nvmem | 2 ++ drivers/nvmem/Kconfig | 5 +++++ drivers/nvmem/core.c | 11 ++++++----- 3 files changed, 13 insertions(+), 5 deletions(-)
Documentation/ABI/stable/sysfs-bus-nvmem +2 -0
@@ -6,6 +6,8 @@ Description: This file allows user to read/write the raw NVMEM contents. Permissions for write to this file depends on the nvmem provider configuration. + Note: This file is not present if CONFIG_NVMEM_NO_SYSFS_ENTRY + is enabled ex: hexdump /sys/bus/nvmem/devices/qfprom0/nvmem
drivers/nvmem/Kconfig +5 -0
@@ -192,4 +192,9 @@ config SC27XX_EFUSE This driver can also be built as a module. If so, the module will be called nvmem-sc27xx-efuse. +config NVMEM_NO_SYSFS_ENTRY + bool "No nvmem sysfs entry" + + help + Say Yes if you do not want to add nvmem entry to sysfs. endif
drivers/nvmem/core.c +6 -5
@@ -216,7 +216,7 @@ static const struct attribute_group nvmem_bin_rw_group = { .attrs = nvmem_attrs, }; -static const struct attribute_group *nvmem_rw_dev_groups[] = { +static const __maybe_unused struct attribute_group *nvmem_rw_dev_groups[] = { &nvmem_bin_rw_group,NULL , };
@@ -240,7 +240,7 @@ static const struct attribute_group nvmem_bin_ro_group = { .attrs = nvmem_attrs, }; -static const struct attribute_group *nvmem_ro_dev_groups[] = { +static const __maybe_unused struct attribute_group *nvmem_ro_dev_groups[] = { &nvmem_bin_ro_group,NULL , };
@@ -265,7 +265,7 @@ static const struct attribute_group nvmem_bin_rw_root_group = { .attrs = nvmem_attrs, }; -static const struct attribute_group *nvmem_rw_root_dev_groups[] = { +static const __maybe_unused struct attribute_group *nvmem_rw_root_dev_groups[] = { &nvmem_bin_rw_root_group,NULL , };
@@ -289,7 +289,7 @@ static const struct attribute_group nvmem_bin_ro_root_group = { .attrs = nvmem_attrs, }; -static const struct attribute_group *nvmem_ro_root_dev_groups[] = { +static const __maybe_unused struct attribute_group *nvmem_ro_root_dev_groups[] = { &nvmem_bin_ro_root_group,NULL , };
@@ -688,6 +688,7 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) nvmem->read_only =device_property_present (config->dev,"read-only" ) | config->read_only; +#if !defined(CONFIG_NVMEM_NO_SYSFS_ENTRY )if (config->root_only) nvmem->dev.groups = nvmem->read_only ? nvmem_ro_root_dev_groups :
@@ -696,7 +697,7 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) nvmem->dev.groups = nvmem->read_only ? nvmem_ro_dev_groups : nvmem_rw_dev_groups; - +#endif device_initialize (&nvmem->dev);dev_dbg (&nvmem->dev,"Registering nvmem device %s\n" , config->name);
Signature · 3 lines
2.21.0 --------------------------->cut<-----------------------------------
Hi Srinivas,
Thanks for the patch, Something like this only i have tested in the morning, instead of unused, i have put dev group inside config as well.
We will test the exact patch and update the same.
Regards
Gaurav
Quoted 127 lines · Srinivas Kandagatla
Quoted 3 lines · Gaurav Kohli
Quoted 2 lines
Is root only option not helping you in this case?
Yes we want to protect at root level as well, i mean it is better if we can avoid exposing to userspace at all.
Can you try below patch!
Quoted 6 lines
Quoted 4 lines
We could go down the route of adding new config option something like
CONFIG_NVMEM_NO_SYSFS_ENTRYto prevent adding nvmem entry in userspace.Let me know if you are happy to create a patch for this change?
I am happy with either way config option or dt binding(seems easy), please let me know we will post new patch for the same.
DT way is totally NAK.
--------------------------->cut<-----------------------------------
From: Srinivas Kandagatla <[email protected]>
Date: Wed, 20 Mar 2019 16:15:21 +0000
Subject: [PATCH] nvmem: core: add support toNVMEM_NO_SYSFS_ENTRYSome users might not want to expose nvmem entry to sysfs and only intend to use kernel interface so add such provision.
Signed-off-by Srinivas Kandagatla <[email protected]>---
Documentation/ABI/stable/sysfs-bus-nvmem | 2 ++ drivers/nvmem/Kconfig | 5 +++++ drivers/nvmem/core.c | 11 ++++++-----3 files changed, 13 insertions(+), 5 deletions(-)Documentation/ABI/stable/sysfs-bus-nvmem +0
-0@@ -6,6 +6,8 @@ Description:This file allows user to read/write the raw NVMEM contents. Permissions for write to this file depends on the nvmem provider configuration.
+ Note: This file is not present ifCONFIG_NVMEM_NO_SYSFS_ENTRY+ is enabledex:
hexdump/sys/bus/nvmem/devices/qfprom0/nvmemdrivers/nvmem/Kconfig +0
-0@@ -192,4 +192,9 @@ config SC27XX_EFUSEThis driver can also be built as a module. If so, the module will be called nvmem-sc27xx-efuse.
drivers/nvmem/Kconfig +5
-0+config NVMEM_NO_SYSFS_ENTRY + bool "No nvmem sysfs entry" + + help + Say Yes if you do not want to add nvmem entry to sysfs.endif
drivers/nvmem/core.c +1
-1@@ -216,7 +216,7 @@ static const struct attribute_group nvmem_bin_rw_group = { .attrs = nvmem_attrs, }; -static const struct attribute_group *nvmem_rw_dev_groups[] = { +static const __maybe_unused struct attribute_group *nvmem_rw_dev_groups[] = { &nvmem_bin_rw_group,NULL,
};drivers/nvmem/core.c +1
-1@@ -240,7 +240,7 @@ static const struct attribute_group nvmem_bin_ro_group = { .attrs = nvmem_attrs, }; -static const struct attribute_group *nvmem_ro_dev_groups[] = { +static const __maybe_unused struct attribute_group *nvmem_ro_dev_groups[] = { &nvmem_bin_ro_group,NULL,
};drivers/nvmem/core.c +1
-1@@ -265,7 +265,7 @@ static const struct attribute_group nvmem_bin_rw_root_group = { .attrs = nvmem_attrs, }; -static const struct attribute_group *nvmem_rw_root_dev_groups[] = { +static const __maybe_unused struct attribute_group *nvmem_rw_root_dev_groups[] = { &nvmem_bin_rw_root_group,NULL,
};drivers/nvmem/core.c +1
-1@@ -289,7 +289,7 @@ static const struct attribute_group nvmem_bin_ro_root_group = { .attrs = nvmem_attrs, }; -static const struct attribute_group *nvmem_ro_root_dev_groups[] = { +static const __maybe_unused struct attribute_group *nvmem_ro_root_dev_groups[] = { &nvmem_bin_ro_root_group,NULL,
};drivers/nvmem/core.c +0
-0@@ -688,6 +688,7 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
nvmem->read_only=device_property_present(config->dev, "read-only")|config->read_only;+#if !defined(CONFIG_NVMEM_NO_SYSFS_ENTRY)
if (config->root_only)
nvmem->dev.groups=nvmem->read_only?
nvmem_ro_root_dev_groups:drivers/nvmem/core.c +0
-0@@ -696,7 +697,7 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
nvmem->dev.groups=nvmem->read_only?
nvmem_ro_dev_groups:
nvmem_rw_dev_groups;drivers/nvmem/core.c +1
-1- +#endif
device_initialize(&nvmem->dev);
dev_dbg(&nvmem->dev, "Registering nvmem device %s\n", config->name);
Signature · 3 lines
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
Quoted 4 lines · Gaurav Kohli
Hi Srinivas,
Thanks for the patch, Something like this only i have tested in the morning, instead of unused, i have put dev group inside config as well.
Quoted 15 lines
We will test the exact patch and update the same.
Regards
Gaurav
Quoted 8 lines · Srinivas Kandagatla
Quoted 3 lines · Gaurav Kohli
Quoted 2 lines
Is root only option not helping you in this case?
Yes we want to protect at root level as well, i mean it is better if we can avoid exposing to userspace at all.
Can you try below patch!
Hi Srinivas,
Thanks for the patch.
I have checked the patch and also tested the same , and it is working as expected(no creation of nvmem sysfs)
Applied with some conflict on line 41.
Regards
Gaurav
Quoted 120 lines
Quoted 119 lines
Quoted 6 lines
Quoted 4 lines
We could go down the route of adding new config option something like
CONFIG_NVMEM_NO_SYSFS_ENTRYto prevent adding nvmem entry in userspace.Let me know if you are happy to create a patch for this change?
I am happy with either way config option or dt binding(seems easy), please let me know we will post new patch for the same.
DT way is totally NAK.
--------------------------->cut<-----------------------------------
From: Srinivas Kandagatla <[email protected]>
Date: Wed, 20 Mar 2019 16:15:21 +0000
Subject: [PATCH] nvmem: core: add support toNVMEM_NO_SYSFS_ENTRYSome users might not want to expose nvmem entry to sysfs and only intend to use kernel interface so add such provision.
Signed-off-by Srinivas Kandagatla <[email protected]>---
Documentation/ABI/stable/sysfs-bus-nvmem | 2 ++ drivers/nvmem/Kconfig | 5 +++++ drivers/nvmem/core.c | 11 ++++++-----3 files changed, 13 insertions(+), 5 deletions(-)Documentation/ABI/stable/sysfs-bus-nvmem +0
-0@@ -6,6 +6,8 @@ Description:This file allows user to read/write the raw NVMEM contents. Permissions for write to this file depends on the nvmem provider configuration.
+ Note: This file is not present ifCONFIG_NVMEM_NO_SYSFS_ENTRY+ is enabledex:
hexdump/sys/bus/nvmem/devices/qfprom0/nvmemdrivers/nvmem/Kconfig +0
-0@@ -192,4 +192,9 @@ config SC27XX_EFUSEThis driver can also be built as a module. If so, the module will be called nvmem-sc27xx-efuse.
drivers/nvmem/Kconfig +5
-0+config NVMEM_NO_SYSFS_ENTRY + bool "No nvmem sysfs entry" + + help + Say Yes if you do not want to add nvmem entry to sysfs.endif
drivers/nvmem/core.c +1
-1@@ -216,7 +216,7 @@ static const struct attribute_group nvmem_bin_rw_group = { .attrs = nvmem_attrs, }; -static const struct attribute_group *nvmem_rw_dev_groups[] = { +static const __maybe_unused struct attribute_group *nvmem_rw_dev_groups[] = { &nvmem_bin_rw_group,NULL,
};drivers/nvmem/core.c +1
-1@@ -240,7 +240,7 @@ static const struct attribute_group nvmem_bin_ro_group = { .attrs = nvmem_attrs, }; -static const struct attribute_group *nvmem_ro_dev_groups[] = { +static const __maybe_unused struct attribute_group *nvmem_ro_dev_groups[] = { &nvmem_bin_ro_group,NULL,
};drivers/nvmem/core.c +1
-1@@ -265,7 +265,7 @@ static const struct attribute_group nvmem_bin_rw_root_group = { .attrs = nvmem_attrs, }; -static const struct attribute_group *nvmem_rw_root_dev_groups[] = { +static const __maybe_unused struct attribute_group *nvmem_rw_root_dev_groups[] = { &nvmem_bin_rw_root_group,NULL,
};drivers/nvmem/core.c +1
-1@@ -289,7 +289,7 @@ static const struct attribute_group nvmem_bin_ro_root_group = { .attrs = nvmem_attrs, }; -static const struct attribute_group *nvmem_ro_root_dev_groups[] = { +static const __maybe_unused struct attribute_group *nvmem_ro_root_dev_groups[] = { &nvmem_bin_ro_root_group,NULL,
};drivers/nvmem/core.c +0
-0@@ -688,6 +688,7 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
nvmem->read_only=device_property_present(config->dev, "read-only")|config->read_only;+#if !defined(CONFIG_NVMEM_NO_SYSFS_ENTRY)
if (config->root_only)
nvmem->dev.groups=nvmem->read_only?
nvmem_ro_root_dev_groups:drivers/nvmem/core.c +0
-0@@ -696,7 +697,7 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
nvmem->dev.groups=nvmem->read_only?
nvmem_ro_dev_groups:
nvmem_rw_dev_groups;drivers/nvmem/core.c +1
-1- +#endif
device_initialize(&nvmem->dev);
dev_dbg(&nvmem->dev, "Registering nvmem device %s\n", config->name);
Signature · 3 lines
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
Hi Srinivas,
Thanks for the patch, Can you please merge , So will cherry pick the same.
Regards
Gaurav
Quoted 157 lines · Gaurav Kohli
Quoted 4 lines · Gaurav Kohli
Hi Srinivas,
Thanks for the patch, Something like this only i have tested in the morning, instead of unused, i have put dev group inside config as well.
Quoted 15 lines
We will test the exact patch and update the same.
Regards
Gaurav
Quoted 8 lines · Srinivas Kandagatla
Quoted 3 lines · Gaurav Kohli
Quoted 2 lines
Is root only option not helping you in this case?
Yes we want to protect at root level as well, i mean it is better if we can avoid exposing to userspace at all.
Can you try below patch!
Hi Srinivas,
Thanks for the patch.
I have checked the patch and also tested the same , and it is working as expected(no creation of nvmem sysfs)
Applied with some conflict on line 41.
Reviewed-by Gaurav Kohli <[email protected]>Tested-by Gaurav Kohli <[email protected]>Regards
Gaurav
Quoted 120 lines
Quoted 119 lines
Quoted 6 lines
Quoted 4 lines
We could go down the route of adding new config option something like
CONFIG_NVMEM_NO_SYSFS_ENTRYto prevent adding nvmem entry in userspace.Let me know if you are happy to create a patch for this change?
I am happy with either way config option or dt binding(seems easy), please let me know we will post new patch for the same.
DT way is totally NAK.
--------------------------->cut<-----------------------------------
From: Srinivas Kandagatla <[email protected]>
Date: Wed, 20 Mar 2019 16:15:21 +0000
Subject: [PATCH] nvmem: core: add support toNVMEM_NO_SYSFS_ENTRYSome users might not want to expose nvmem entry to sysfs and only intend to use kernel interface so add such provision.
Signed-off-by Srinivas Kandagatla <[email protected]>---
Documentation/ABI/stable/sysfs-bus-nvmem | 2 ++ drivers/nvmem/Kconfig | 5 +++++ drivers/nvmem/core.c | 11 ++++++-----3 files changed, 13 insertions(+), 5 deletions(-)Documentation/ABI/stable/sysfs-bus-nvmem +0
-0@@ -6,6 +6,8 @@ Description:This file allows user to read/write the raw NVMEM contents. Permissions for write to this file depends on the nvmem provider configuration.
+ Note: This file is not present ifCONFIG_NVMEM_NO_SYSFS_ENTRY+ is enabledex:
hexdump/sys/bus/nvmem/devices/qfprom0/nvmemdrivers/nvmem/Kconfig +0
-0@@ -192,4 +192,9 @@ config SC27XX_EFUSEThis driver can also be built as a module. If so, the module will be called nvmem-sc27xx-efuse.
drivers/nvmem/Kconfig +5
-0+config NVMEM_NO_SYSFS_ENTRY + bool "No nvmem sysfs entry" + + help + Say Yes if you do not want to add nvmem entry to sysfs.endif
drivers/nvmem/core.c +1
-1@@ -216,7 +216,7 @@ static const struct attribute_group nvmem_bin_rw_group = { .attrs = nvmem_attrs, }; -static const struct attribute_group *nvmem_rw_dev_groups[] = { +static const __maybe_unused struct attribute_group *nvmem_rw_dev_groups[] = { &nvmem_bin_rw_group,NULL,
};drivers/nvmem/core.c +1
-1@@ -240,7 +240,7 @@ static const struct attribute_group nvmem_bin_ro_group = { .attrs = nvmem_attrs, }; -static const struct attribute_group *nvmem_ro_dev_groups[] = { +static const __maybe_unused struct attribute_group *nvmem_ro_dev_groups[] = { &nvmem_bin_ro_group,NULL,
};drivers/nvmem/core.c +1
-1@@ -265,7 +265,7 @@ static const struct attribute_group nvmem_bin_rw_root_group = { .attrs = nvmem_attrs, }; -static const struct attribute_group *nvmem_rw_root_dev_groups[] = { +static const __maybe_unused struct attribute_group *nvmem_rw_root_dev_groups[] = { &nvmem_bin_rw_root_group,NULL,
};drivers/nvmem/core.c +1
-1@@ -289,7 +289,7 @@ static const struct attribute_group nvmem_bin_ro_root_group = { .attrs = nvmem_attrs, }; -static const struct attribute_group *nvmem_ro_root_dev_groups[] = { +static const __maybe_unused struct attribute_group *nvmem_ro_root_dev_groups[] = { &nvmem_bin_ro_root_group,NULL,
};drivers/nvmem/core.c +0
-0@@ -688,6 +688,7 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
nvmem->read_only=device_property_present(config->dev, "read-only")|config->read_only;+#if !defined(CONFIG_NVMEM_NO_SYSFS_ENTRY)
if (config->root_only)
nvmem->dev.groups=nvmem->read_only?
nvmem_ro_root_dev_groups:drivers/nvmem/core.c +0
-0@@ -696,7 +697,7 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
nvmem->dev.groups=nvmem->read_only?
nvmem_ro_dev_groups:
nvmem_rw_dev_groups;drivers/nvmem/core.c +1
-1- +#endif
device_initialize(&nvmem->dev);
dev_dbg(&nvmem->dev, "Registering nvmem device %s\n", config->name);
Signature · 3 lines
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
Quoted 56 lines · Srinivas Kandagatla
Quoted 4 lines · Gaurav Kohli
Quoted 2 lines
Is root only option not helping you in this case?
Yes we want to protect at root level as well, i mean it is better if we can avoid exposing to userspace at all.
Can you try below patch!
Quoted 9 lines
Quoted 6 lines
We could go down the route of adding new config option something like
CONFIG_NVMEM_NO_SYSFS_ENTRYto prevent adding nvmem entry in userspace.Let me know if you are happy to create a patch for this change?
I am happy with either way config option or dt binding(seems easy), please let me know we will post new patch for the same.
DT way is totally NAK.
--------------------------->cut<-----------------------------------
From: Srinivas Kandagatla <[email protected]>
Date: Wed, 20 Mar 2019 16:15:21 +0000
Subject: [PATCH] nvmem: core: add support toNVMEM_NO_SYSFS_ENTRYSome users might not want to expose nvmem entry to sysfs and only intend to use kernel interface so add such provision.
Signed-off-by Srinivas Kandagatla <[email protected]>--- Documentation/ABI/stable/sysfs-bus-nvmem | 2 ++ drivers/nvmem/Kconfig | 5 +++++ drivers/nvmem/core.c | 11 ++++++----- 3 files changed, 13 insertions(+), 5 deletions(-)Documentation/ABI/stable/sysfs-bus-nvmem +2
-0@@ -6,6 +6,8 @@ Description: This file allows user to read/write the raw NVMEM contents. Permissions for write to this file depends on the nvmem provider configuration. + Note: This file is not present if CONFIG_NVMEM_NO_SYSFS_ENTRY + is enabled ex: hexdump /sys/bus/nvmem/devices/qfprom0/nvmemdrivers/nvmem/Kconfig +0
-0
drivers/nvmem/Kconfig config SC27XX_EFUSE · line 200
Quoted 9 lines
drivers/nvmem/Kconfig +5
-0@@ -192,4 +192,9 @@ config SC27XX_EFUSE This driver can also be built as a module. If so, the module will be called nvmem-sc27xx-efuse. +config NVMEM_NO_SYSFS_ENTRY + bool "No nvmem sysfs entry" + + help + Say Yes if you do not want to add nvmem entry to sysfs. endif
Hello Srini,
doesn't it make sense to instead have a CONFIG_NVMEM_SYSFS, maked as default y, that way the default behavior will be the same, and people not wanting it can explicitly disable it.
This also aligns with how it's done in other drivers:
$ grep SYSFS .config # CONFIG_SYSFS_DEPRECATED is not set CONFIG_SYSFS_SYSCALL=y # CONFIG_DMI_SYSFS is not set # CONFIG_FW_CFG_SYSFS is not set # CONFIG_ISCSI_BOOT_SYSFS is not set # CONFIG_GPIO_SYSFS is not set # CONFIG_WATCHDOG_SYSFS is not set CONFIG_EDAC_LEGACY_SYSFS=y CONFIG_RTC_INTF_SYSFS=y CONFIG_CROS_EC_SYSFS=m # CONFIG_IIO_SYSFS_TRIGGER is not set CONFIG_PWM_SYSFS=y CONFIG_SYSFS=y
Kind regards,
Niklas
Quoted 71 lines
drivers/nvmem/core.c +1
-1@@ -216,7 +216,7 @@ static const struct attribute_group nvmem_bin_rw_group = { .attrs = nvmem_attrs, }; -static const struct attribute_group *nvmem_rw_dev_groups[] = { +static const __maybe_unused struct attribute_group *nvmem_rw_dev_groups[] = { &nvmem_bin_rw_group,drivers/nvmem/core.c +1
-1NULL, };@@ -240,7 +240,7 @@ static const struct attribute_group nvmem_bin_ro_group = { .attrs = nvmem_attrs, }; -static const struct attribute_group *nvmem_ro_dev_groups[] = { +static const __maybe_unused struct attribute_group *nvmem_ro_dev_groups[] = { &nvmem_bin_ro_group,drivers/nvmem/core.c +1
-1NULL, };@@ -265,7 +265,7 @@ static const struct attribute_group nvmem_bin_rw_root_group = { .attrs = nvmem_attrs, }; -static const struct attribute_group *nvmem_rw_root_dev_groups[] = { +static const __maybe_unused struct attribute_group *nvmem_rw_root_dev_groups[] = { &nvmem_bin_rw_root_group,drivers/nvmem/core.c +1
-1NULL, };@@ -289,7 +289,7 @@ static const struct attribute_group nvmem_bin_ro_root_group = { .attrs = nvmem_attrs, }; -static const struct attribute_group *nvmem_ro_root_dev_groups[] = { +static const __maybe_unused struct attribute_group *nvmem_ro_root_dev_groups[] = { &nvmem_bin_ro_root_group,drivers/nvmem/core.c +1
-0NULL, };@@ -688,6 +688,7 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) nvmem->read_only = device_property_present(config->dev, "read-only") | config->read_only; +#if !defined(CONFIG_NVMEM_NO_SYSFS_ENTRY )if (config->root_only) nvmem->dev.groups = nvmem->read_only ?drivers/nvmem/core.c +1
-1nvmem_ro_root_dev_groups :@@ -696,7 +697,7 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) nvmem->dev.groups = nvmem->read_only ? nvmem_ro_dev_groups : nvmem_rw_dev_groups; - +#endif device_initialize (&nvmem->dev);
dev_dbg(&nvmem->dev, "Registering nvmem device %s\n", config->name);Signature · 3 lines
2.21.0 --------------------------->cut<-----------------------------------