Skip to contentSkip to conversation

efivarfs: Replace invalid slashes with exclamation marks in dentries.

PATCH Applied Michael Schaller 3 participants 6 messages Sep 25, 2020 – Sep 30, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 efivarfs: Replace invalid slashes with exclamation marks in dentries.

Without this patch efivarfs_alloc_dentry creates dentries with slashes in their name if the respective EFI variable has slashes in its name. This in turn causes EIO on getdents64, which prevents a complete directory listing of /sys/firmware/efi/efivars/.

This patch replaces the invalid shlashes with exclamation marks like kobject_set_name_vargs does for /sys/firmware/efi/vars/ to have consistently named dentries under /sys/firmware/efi/vars/ and /sys/firmware/efi/efivars/.

---
 fs/efivarfs/super.c | 3 +++
 1 file changed, 3 insertions(+)
fs/efivarfs/super.c +3 -0
index 28bb5689333a..15880a68faad 100644
@@ -141,6 +141,9 @@ static int efivarfs_callback(efi_char16_t *name16, efi_guid_t vendor,
 
 	name[len + EFI_VARIABLE_GUID_LEN+1] = '\0';
 
+	/* replace invalid slashes like kobject_set_name_vargs does for /sys/firmware/efi/vars. */
+	strreplace(name, '/', '!');
+
 	inode = efivarfs_get_inode(sb, d_inode(root), S_IFREG | 0644, 0,
 				   is_removable);
 	if (!inode)
Signature · 1 line
2.28.0.681.g6f77f65b4e-goog
maintainer
#1 lore raw
Quoted 11 lines · Michael Schaller

Without this patch efivarfs_alloc_dentry creates dentries with slashes in their name if the respective EFI variable has slashes in its name. This in turn causes EIO on getdents64, which prevents a complete directory listing of /sys/firmware/efi/efivars/.

This patch replaces the invalid shlashes with exclamation marks like kobject_set_name_vargs does for /sys/firmware/efi/vars/ to have consistently named dentries under /sys/firmware/efi/vars/ and /sys/firmware/efi/efivars/.

Thanks

Quoted 1 line

I will drop this - in general, it is assumed that you test your own patches before sending them to the list, so this is implicit. Also, tested-by's given on the list tend to carry more weight than ones that are givenin private and added to the patch by the authors themselves.

Quoted 21 lines
---
 fs/efivarfs/super.c | 3 +++
 1 file changed, 3 insertions(+)
fs/efivarfs/super.c +3 -1
index 28bb5689333a..15880a68faad 100644
@@ -141,6 +141,9 @@ static int efivarfs_callback(efi_char16_t *name16, efi_guid_t vendor,
 
        name[len + EFI_VARIABLE_GUID_LEN+1] = '\0';
 
+       /* replace invalid slashes like kobject_set_name_vargs does for /sys/firmware/efi/vars. */
+       strreplace(name, '/', '!');
+
        inode = efivarfs_get_inode(sb, d_inode(root), S_IFREG | 0644, 0,
                                   is_removable);
        if (!inode)
--

2.28.0.681.g6f77f65b4e-goog

#2 lore raw
Quoted 14 lines · Ard Biesheuvel
Quoted 11 lines · Michael Schaller

Without this patch efivarfs_alloc_dentry creates dentries with slashes in their name if the respective EFI variable has slashes in its name. This in turn causes EIO on getdents64, which prevents a complete directory listing of /sys/firmware/efi/efivars/.

This patch replaces the invalid shlashes with exclamation marks like kobject_set_name_vargs does for /sys/firmware/efi/vars/ to have consistently named dentries under /sys/firmware/efi/vars/ and /sys/firmware/efi/efivars/.

Quoted 9 lines

Thanks

Quoted 1 line

I will drop this - in general, it is assumed that you test your own patches before sending them to the list, so this is implicit. Also, tested-by's given on the list tend to carry more weight than ones that are givenin private and added to the patch by the authors themselves.

Makes sense. Is anything else needed from my side?

Quoted 22 lines
Quoted 22 lines
---
 fs/efivarfs/super.c | 3 +++
 1 file changed, 3 insertions(+)
fs/efivarfs/super.c +3 -1
index 28bb5689333a..15880a68faad 100644
@@ -141,6 +141,9 @@ static int efivarfs_callback(efi_char16_t *name16, efi_guid_t vendor,
 
        name[len + EFI_VARIABLE_GUID_LEN+1] = '\0';
 
+       /* replace invalid slashes like kobject_set_name_vargs does for /sys/firmware/efi/vars. */
+       strreplace(name, '/', '!');
+
        inode = efivarfs_get_inode(sb, d_inode(root), S_IFREG | 0644, 0,
                                   is_removable);
        if (!inode)
--

2.28.0.681.g6f77f65b4e-goog

maintainer
#3 lore raw
Quoted 18 lines · Michael Schaller
Quoted 16 lines · Ard Biesheuvel
Quoted 11 lines · Michael Schaller

Without this patch efivarfs_alloc_dentry creates dentries with slashes in their name if the respective EFI variable has slashes in its name. This in turn causes EIO on getdents64, which prevents a complete directory listing of /sys/firmware/efi/efivars/.

This patch replaces the invalid shlashes with exclamation marks like kobject_set_name_vargs does for /sys/firmware/efi/vars/ to have consistently named dentries under /sys/firmware/efi/vars/ and /sys/firmware/efi/efivars/.

Thanks

Quoted 8 lines
Quoted 7 lines
Quoted 1 line

I will drop this - in general, it is assumed that you test your own patches before sending them to the list, so this is implicit. Also, tested-by's given on the list tend to carry more weight than ones that are givenin private and added to the patch by the authors themselves.

Makes sense. Is anything else needed from my side?

No, all good. I'll pick this up as a fix.

#4 lore raw
Quoted 22 lines · Ard Biesheuvel
Quoted 20 lines · Michael Schaller
Quoted 18 lines · Ard Biesheuvel
Quoted 11 lines · Michael Schaller

Without this patch efivarfs_alloc_dentry creates dentries with slashes in their name if the respective EFI variable has slashes in its name. This in turn causes EIO on getdents64, which prevents a complete directory listing of /sys/firmware/efi/efivars/.

This patch replaces the invalid shlashes with exclamation marks like kobject_set_name_vargs does for /sys/firmware/efi/vars/ to have consistently named dentries under /sys/firmware/efi/vars/ and /sys/firmware/efi/efivars/.

Thanks

Quoted 1 line
Quoted 8 lines
Quoted 6 lines
Quoted 5 lines

I will drop this - in general, it is assumed that you test your own patches before sending them to the list, so this is implicit. Also, tested-by's given on the list tend to carry more weight than ones that are givenin private and added to the patch by the authors themselves.

Makes sense. Is anything else needed from my side?

No, all good. I'll pick this up as a fix.

Awesome. Would it make sense to consider this for stable kernels as well? We've found this in the wild on Lenovo ThinkStation P520 machines as they write EFI variables like this one:
05/15/2019-13:37:56-SysEvtLog:36-193545dc-3550-4d14-bdba-b7d426c6b019

#5 lore raw
In reply to Michael Schaller
The following commit has been merged into the efi/urgent branch of tip:

The following commit has been merged into the efi/urgent branch of tip:

Commit-ID:     336af6a4686d885a067ecea8c3c3dd129ba4fc75
Gitweb:        https://git.kernel.org/tip/336af6a4686d885a067ecea8c3c3dd129ba4fc75
Author:        Michael Schaller <[email protected]>
AuthorDate:    Fri, 25 Sep 2020 09:45:02 +02:00
Committer:     Ard Biesheuvel <[email protected]>
CommitterDate: Fri, 25 Sep 2020 23:29:04 +02:00

efivarfs: Replace invalid slashes with exclamation marks in dentries.

Without this patch efivarfs_alloc_dentry creates dentries with slashes in their name if the respective EFI variable has slashes in its name. This in turn causes EIO on getdents64, which prevents a complete directory listing of /sys/firmware/efi/efivars/.

This patch replaces the invalid shlashes with exclamation marks like kobject_set_name_vargs does for /sys/firmware/efi/vars/ to have consistently named dentries under /sys/firmware/efi/vars/ and /sys/firmware/efi/efivars/.

---
 fs/efivarfs/super.c | 3 +++
 1 file changed, 3 insertions(+)
fs/efivarfs/super.c +3 -0
index 28bb568..15880a6 100644
@@ -141,6 +141,9 @@ static int efivarfs_callback(efi_char16_t *name16, efi_guid_t vendor,
 
 	name[len + EFI_VARIABLE_GUID_LEN+1] = '\0';
 
+	/* replace invalid slashes like kobject_set_name_vargs does for /sys/firmware/efi/vars. */
+	strreplace(name, '/', '!');
+
 	inode = efivarfs_get_inode(sb, d_inode(root), S_IFREG | 0644, 0,
 				   is_removable);
 	if (!inode)