Skip to content

Commit 2ab0837

Browse files
James Bottomleyardbiesheuvel
authored andcommitted
efivarfs: Fix error on non-existent file
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>
1 parent 0b2c29f commit 2ab0837

File tree

3 files changed

+1
-5
lines changed

3 files changed

+1
-5
lines changed

fs/efivarfs/inode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ struct inode *efivarfs_get_inode(struct super_block *sb,
5151
*
5252
* VariableName-12345678-1234-1234-1234-1234567891bc
5353
*/
54-
bool efivarfs_valid_name(const char *str, int len)
54+
static bool efivarfs_valid_name(const char *str, int len)
5555
{
5656
const char *s = str + len - EFI_VARIABLE_GUID_LEN;
5757

fs/efivarfs/internal.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ bool efivar_variable_is_removable(efi_guid_t vendor, const char *name,
6060

6161
extern const struct file_operations efivarfs_file_operations;
6262
extern const struct inode_operations efivarfs_dir_inode_operations;
63-
extern bool efivarfs_valid_name(const char *str, int len);
6463
extern struct inode *efivarfs_get_inode(struct super_block *sb,
6564
const struct inode *dir, int mode, dev_t dev,
6665
bool is_removable);

fs/efivarfs/super.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,6 @@ static int efivarfs_d_hash(const struct dentry *dentry, struct qstr *qstr)
144144
const unsigned char *s = qstr->name;
145145
unsigned int len = qstr->len;
146146

147-
if (!efivarfs_valid_name(s, len))
148-
return -EINVAL;
149-
150147
while (len-- > EFI_VARIABLE_GUID_LEN)
151148
hash = partial_name_hash(*s++, hash);
152149

0 commit comments

Comments
 (0)