From: Al Viro Date: Tue, 14 May 2024 14:53:07 +0000 (-0600) Subject: efi_secret: clean securityfs use up X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a98ce0275b4b3fd5e0622da8aabbccc9a39670e0;p=thirdparty%2Fkernel%2Fstable.git efi_secret: clean securityfs use up securityfs_remove() does take care of entire subtree now; no need to mess with them individually. NB: ->i_op replacement in there is still buggy. One shouldn't ever modify ->i_op of live accessible inode. Signed-off-by: Al Viro --- diff --git a/drivers/virt/coco/efi_secret/efi_secret.c b/drivers/virt/coco/efi_secret/efi_secret.c index f2da4819ec3b7..5946c5abeae89 100644 --- a/drivers/virt/coco/efi_secret/efi_secret.c +++ b/drivers/virt/coco/efi_secret/efi_secret.c @@ -31,8 +31,6 @@ struct efi_secret { struct dentry *secrets_dir; - struct dentry *fs_dir; - struct dentry *fs_files[EFI_SECRET_NUM_FILES]; void __iomem *secret_data; u64 secret_data_len; }; @@ -119,10 +117,8 @@ static void wipe_memory(void *addr, size_t size) static int efi_secret_unlink(struct inode *dir, struct dentry *dentry) { - struct efi_secret *s = efi_secret_get(); struct inode *inode = d_inode(dentry); struct secret_entry *e = (struct secret_entry *)inode->i_private; - int i; if (e) { /* Zero out the secret data */ @@ -132,10 +128,6 @@ static int efi_secret_unlink(struct inode *dir, struct dentry *dentry) inode->i_private = NULL; - for (i = 0; i < EFI_SECRET_NUM_FILES; i++) - if (s->fs_files[i] == dentry) - s->fs_files[i] = NULL; - return simple_unlink(inode, dentry); } @@ -186,15 +178,6 @@ unmap: static void efi_secret_securityfs_teardown(struct platform_device *dev) { struct efi_secret *s = efi_secret_get(); - int i; - - for (i = (EFI_SECRET_NUM_FILES - 1); i >= 0; i--) { - securityfs_remove(s->fs_files[i]); - s->fs_files[i] = NULL; - } - - securityfs_remove(s->fs_dir); - s->fs_dir = NULL; securityfs_remove(s->secrets_dir); s->secrets_dir = NULL; @@ -209,7 +192,7 @@ static int efi_secret_securityfs_setup(struct platform_device *dev) unsigned char *ptr; struct secret_header *h; struct secret_entry *e; - struct dentry *dent; + struct dentry *dent, *dir; char guid_str[EFI_VARIABLE_GUID_LEN + 1]; ptr = (void __force *)s->secret_data; @@ -232,8 +215,6 @@ static int efi_secret_securityfs_setup(struct platform_device *dev) } s->secrets_dir = NULL; - s->fs_dir = NULL; - memset(s->fs_files, 0, sizeof(s->fs_files)); dent = securityfs_create_dir("secrets", NULL); if (IS_ERR(dent)) { @@ -243,14 +224,13 @@ static int efi_secret_securityfs_setup(struct platform_device *dev) } s->secrets_dir = dent; - dent = securityfs_create_dir("coco", s->secrets_dir); - if (IS_ERR(dent)) { + dir = securityfs_create_dir("coco", s->secrets_dir); + if (IS_ERR(dir)) { dev_err(&dev->dev, "Error creating coco securityfs directory entry err=%ld\n", - PTR_ERR(dent)); - return PTR_ERR(dent); + PTR_ERR(dir)); + return PTR_ERR(dir); } - d_inode(dent)->i_op = &efi_secret_dir_inode_operations; - s->fs_dir = dent; + d_inode(dir)->i_op = &efi_secret_dir_inode_operations; bytes_left = h->len - sizeof(*h); ptr += sizeof(*h); @@ -266,15 +246,14 @@ static int efi_secret_securityfs_setup(struct platform_device *dev) if (efi_guidcmp(e->guid, NULL_GUID)) { efi_guid_to_str(&e->guid, guid_str); - dent = securityfs_create_file(guid_str, 0440, s->fs_dir, (void *)e, + dent = securityfs_create_file(guid_str, 0440, dir, (void *)e, &efi_secret_bin_file_fops); if (IS_ERR(dent)) { dev_err(&dev->dev, "Error creating efi_secret securityfs entry\n"); ret = PTR_ERR(dent); goto err_cleanup; } - - s->fs_files[i++] = dent; + i++; } ptr += e->len; bytes_left -= e->len;