Skip to content

Commit a4f586a

Browse files
committed
Merge tag 'efi-fixes-for-v6.14-3' of git://git.kernel.org/pub/scm/linux/kernel/git/efi/efi
Pull EFI fixes from Ard Biesheuvel: "Here's a final batch of EFI fixes for v6.14. The efivarfs ones are fixes for changes that were made this cycle. James's fix is somewhat of a band-aid, but it was blessed by the VFS folks, who are working with James to come up with something better for the next cycle. - Avoid physical address 0x0 for random page allocations - Add correct lockdep annotation when traversing efivarfs on resume - Avoid NULL mount in kernel_file_open() when traversing efivarfs on resume" * tag 'efi-fixes-for-v6.14-3' of git://git.kernel.org/pub/scm/linux/kernel/git/efi/efi: efivarfs: fix NULL dereference on resume efivarfs: use I_MUTEX_CHILD nested lock to traverse variables on resume efi/libstub: Avoid physical address 0x0 when doing random allocation
2 parents a7f2e10 + 11092db commit a4f586a

File tree

2 files changed

+53
-3
lines changed

2 files changed

+53
-3
lines changed

drivers/firmware/efi/libstub/randomalloc.c

+4
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ efi_status_t efi_random_alloc(unsigned long size,
7575
if (align < EFI_ALLOC_ALIGN)
7676
align = EFI_ALLOC_ALIGN;
7777

78+
/* Avoid address 0x0, as it can be mistaken for NULL */
79+
if (alloc_min == 0)
80+
alloc_min = align;
81+
7882
size = round_up(size, EFI_ALLOC_ALIGN);
7983

8084
/* count the suitable slots in each memory map entry */

fs/efivarfs/super.c

+49-3
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ static bool efivarfs_actor(struct dir_context *ctx, const char *name, int len,
421421
if (err)
422422
size = 0;
423423

424-
inode_lock(inode);
424+
inode_lock_nested(inode, I_MUTEX_CHILD);
425425
i_size_write(inode, size);
426426
inode_unlock(inode);
427427

@@ -474,19 +474,33 @@ static int efivarfs_check_missing(efi_char16_t *name16, efi_guid_t vendor,
474474
return err;
475475
}
476476

477+
static void efivarfs_deactivate_super_work(struct work_struct *work)
478+
{
479+
struct super_block *s = container_of(work, struct super_block,
480+
destroy_work);
481+
/*
482+
* note: here s->destroy_work is free for reuse (which
483+
* will happen in deactivate_super)
484+
*/
485+
deactivate_super(s);
486+
}
487+
488+
static struct file_system_type efivarfs_type;
489+
477490
static int efivarfs_pm_notify(struct notifier_block *nb, unsigned long action,
478491
void *ptr)
479492
{
480493
struct efivarfs_fs_info *sfi = container_of(nb, struct efivarfs_fs_info,
481494
pm_nb);
482-
struct path path = { .mnt = NULL, .dentry = sfi->sb->s_root, };
495+
struct path path;
483496
struct efivarfs_ctx ectx = {
484497
.ctx = {
485498
.actor = efivarfs_actor,
486499
},
487500
.sb = sfi->sb,
488501
};
489502
struct file *file;
503+
struct super_block *s = sfi->sb;
490504
static bool rescan_done = true;
491505

492506
if (action == PM_HIBERNATION_PREPARE) {
@@ -499,11 +513,43 @@ static int efivarfs_pm_notify(struct notifier_block *nb, unsigned long action,
499513
if (rescan_done)
500514
return NOTIFY_DONE;
501515

516+
/* ensure single superblock is alive and pin it */
517+
if (!atomic_inc_not_zero(&s->s_active))
518+
return NOTIFY_DONE;
519+
502520
pr_info("efivarfs: resyncing variable state\n");
503521

504-
/* O_NOATIME is required to prevent oops on NULL mnt */
522+
path.dentry = sfi->sb->s_root;
523+
524+
/*
525+
* do not add SB_KERNMOUNT which a single superblock could
526+
* expose to userspace and which also causes MNT_INTERNAL, see
527+
* below
528+
*/
529+
path.mnt = vfs_kern_mount(&efivarfs_type, 0,
530+
efivarfs_type.name, NULL);
531+
if (IS_ERR(path.mnt)) {
532+
pr_err("efivarfs: internal mount failed\n");
533+
/*
534+
* We may be the last pinner of the superblock but
535+
* calling efivarfs_kill_sb from within the notifier
536+
* here would deadlock trying to unregister it
537+
*/
538+
INIT_WORK(&s->destroy_work, efivarfs_deactivate_super_work);
539+
schedule_work(&s->destroy_work);
540+
return PTR_ERR(path.mnt);
541+
}
542+
543+
/* path.mnt now has pin on superblock, so this must be above one */
544+
atomic_dec(&s->s_active);
545+
505546
file = kernel_file_open(&path, O_RDONLY | O_DIRECTORY | O_NOATIME,
506547
current_cred());
548+
/*
549+
* safe even if last put because no MNT_INTERNAL means this
550+
* will do delayed deactivate_super and not deadlock
551+
*/
552+
mntput(path.mnt);
507553
if (IS_ERR(file))
508554
return NOTIFY_DONE;
509555

0 commit comments

Comments
 (0)