[PATCH] nvmem: core: limit cell sysfs permissions to main attribute ones

Thomas Weißschuh posted 1 patch 1 year, 7 months ago
drivers/nvmem/core.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] nvmem: core: limit cell sysfs permissions to main attribute ones
Posted by Thomas Weißschuh 1 year, 7 months ago
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>
---
This was also discussed as part of
"[PATCH] nvmem: core: add sysfs cell write support" [0].
But there haven't been updates to that patch and this is arguably a
standalone bugfix.

[0] https://lore.kernel.org/lkml/20240223154129.1902905-1-m.felsch@pengutronix.de/
---
 drivers/nvmem/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index e1ec3b7200d7..acfea1e56849 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -463,7 +463,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;

---
base-commit: 92e5605a199efbaee59fb19e15d6cc2103a04ec2
change-id: 20240619-nvmem-cell-sysfs-perm-156fde0d7460

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

Re: [PATCH] nvmem: core: limit cell sysfs permissions to main attribute ones
Posted by Srinivas Kandagatla 1 year, 7 months ago
On Wed, 19 Jun 2024 20:09:00 +0200, Thomas Weißschuh wrote:
> 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.
> 
> [...]

Applied, thanks!

[1/1] nvmem: core: limit cell sysfs permissions to main attribute ones
      commit: 4eeb1d829b54d16ee5bbe9188e6013d424c6e859

Best regards,
-- 
Srinivas Kandagatla <srinivas.kandagatla@linaro.org>

Re: [PATCH] nvmem: core: limit cell sysfs permissions to main attribute ones
Posted by Srinivas Kandagatla 1 year, 7 months ago

On 19/06/2024 19:09, Thomas Weißschuh wrote:
> 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>
> ---
> This was also discussed as part of
> "[PATCH] nvmem: core: add sysfs cell write support" [0].
> But there haven't been updates to that patch and this is arguably a
> standalone bugfix.
> 
> [0] https://lore.kernel.org/lkml/20240223154129.1902905-1-m.felsch@pengutronix.de/
> ---
>   drivers/nvmem/core.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
> index e1ec3b7200d7..acfea1e56849 100644
> --- a/drivers/nvmem/core.c
> +++ b/drivers/nvmem/core.c
> @@ -463,7 +463,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);
Why not just
attrs[i].attr.mode = nvmem_bin_attr_get_umode(nvmem);
?

--srini
>   		attrs[i].size = entry->bytes;
>   		attrs[i].read = &nvmem_cell_attr_read;
>   		attrs[i].private = entry;
> 
> ---
> base-commit: 92e5605a199efbaee59fb19e15d6cc2103a04ec2
> change-id: 20240619-nvmem-cell-sysfs-perm-156fde0d7460
> 
> Best regards,
Re: [PATCH] nvmem: core: limit cell sysfs permissions to main attribute ones
Posted by Thomas Weißschuh 1 year, 7 months ago
Jun 22, 2024 12:11:04 Srinivas Kandagatla <srinivas.kandagatla@linaro.org>:

>
>
> On 19/06/2024 19:09, Thomas Weißschuh wrote:
>> 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>
>> ---
>> This was also discussed as part of
>> "[PATCH] nvmem: core: add sysfs cell write support" [0].
>> But there haven't been updates to that patch and this is arguably a
>> standalone bugfix.
>> [0] https://lore.kernel.org/lkml/20240223154129.1902905-1-m.felsch@pengutronix.de/
>> ---
>>   drivers/nvmem/core.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>> diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
>> index e1ec3b7200d7..acfea1e56849 100644
>> --- a/drivers/nvmem/core.c
>> +++ b/drivers/nvmem/core.c
>> @@ -463,7 +463,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);
> Why not just
> attrs[i].attr.mode = nvmem_bin_attr_get_umode(nvmem);

Because nvmem_bin_attr_get_umode() will include write permissions
if the base nvmem device is writable.

But (for now) the cell sysfs attributes do not implement writes.


> ?
>
> --srini
>>         attrs[i].size = entry->bytes;
>>         attrs[i].read = &nvmem_cell_attr_read;
>>         attrs[i].private = entry;
>> ---
>> base-commit: 92e5605a199efbaee59fb19e15d6cc2103a04ec2
>> change-id: 20240619-nvmem-cell-sysfs-perm-156fde0d7460
>> Best regards,