]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
efivarfs: Fix error on non-existent file
authorJames Bottomley <James.Bottomley@HansenPartnership.com>
Sun, 8 Dec 2024 18:34:13 +0000 (13:34 -0500)
committerArd Biesheuvel <ardb@kernel.org>
Mon, 9 Dec 2024 09:00:04 +0000 (10:00 +0100)
When looking up a non-existent file, efivarfs returns -EINVAL if the
file does not conform to the NAME-GUID format and -ENOENT if it does.
This is caused by efivars_d_hash() returning -EINVAL if the name is not
formatted correctly.  This error is returned before simple_lookup()
returns a negative dentry, and is the error value that the user sees.

Fix by removing this check.  If the file does not exist, simple_lookup()
will return a negative dentry leading to -ENOENT and efivarfs_create()
already has a validity check before it creates an entry (and will
correctly return -EINVAL)

Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
Cc: <stable@vger.kernel.org>
[ardb: make efivarfs_valid_name() static]
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
fs/efivarfs/inode.c
fs/efivarfs/internal.h
fs/efivarfs/super.c

index 586446e02ef72d5d3aaf9d4f305fd774d1abcc34..ec23da8405ff8e1ffcfe1714a44f8119048f1f71 100644 (file)
@@ -51,7 +51,7 @@ struct inode *efivarfs_get_inode(struct super_block *sb,
  *
  *     VariableName-12345678-1234-1234-1234-1234567891bc
  */
-bool efivarfs_valid_name(const char *str, int len)
+static bool efivarfs_valid_name(const char *str, int len)
 {
        const char *s = str + len - EFI_VARIABLE_GUID_LEN;
 
index d71d2e08422f09250c282faeb4ab8e58b6abc401..74f0602a9e016c6dac6199b496219d8b98e54a64 100644 (file)
@@ -60,7 +60,6 @@ bool efivar_variable_is_removable(efi_guid_t vendor, const char *name,
 
 extern const struct file_operations efivarfs_file_operations;
 extern const struct inode_operations efivarfs_dir_inode_operations;
-extern bool efivarfs_valid_name(const char *str, int len);
 extern struct inode *efivarfs_get_inode(struct super_block *sb,
                        const struct inode *dir, int mode, dev_t dev,
                        bool is_removable);
index a929f1b613be841470727658bda630dc5e943e45..beba15673be8d351e2c77acfc6df472ea63ab351 100644 (file)
@@ -144,9 +144,6 @@ static int efivarfs_d_hash(const struct dentry *dentry, struct qstr *qstr)
        const unsigned char *s = qstr->name;
        unsigned int len = qstr->len;
 
-       if (!efivarfs_valid_name(s, len))
-               return -EINVAL;
-
        while (len-- > EFI_VARIABLE_GUID_LEN)
                hash = partial_name_hash(*s++, hash);