mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-08-28 16:54:57 -04:00
initramfs: use scoped_with_init_fs() for rootfs unpacking
Extract the initramfs unpacking code into a separate unpack_initramfs() function and wrap its invocation from do_populate_rootfs() with scoped_with_init_fs(). This ensures all file operations during initramfs unpacking (including filp_open() calls in do_name() and populate_initrd_image()) happen in init's filesystem context. Note that security_initramfs_populated() needs the scope as well since it does use current->fs to derive the initramfs superblock. do_populate_rootfs() ← async_schedule_domain() ← kworker (async workqueue) May also run synchronously from PID 1 in case async workqueue is considered full. Overriding in that case is fine as well. Link: https://patch.msgid.link/20260601-work-kthread-nullfs-v4-17-77ee053060e0@kernel.org Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#include <linux/fcntl.h>
|
||||
#include <linux/file.h>
|
||||
#include <linux/fs.h>
|
||||
#include <linux/fs_struct.h>
|
||||
#include <linux/hex.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/init_syscalls.h>
|
||||
@@ -716,7 +717,7 @@ static void __init populate_initrd_image(char *err)
|
||||
}
|
||||
#endif /* CONFIG_BLK_DEV_RAM */
|
||||
|
||||
static void __init do_populate_rootfs(void *unused, async_cookie_t cookie)
|
||||
static void __init unpack_initramfs(async_cookie_t cookie)
|
||||
{
|
||||
/* Load the built in initramfs */
|
||||
char *err = unpack_to_rootfs(__initramfs_start, __initramfs_size);
|
||||
@@ -724,7 +725,7 @@ static void __init do_populate_rootfs(void *unused, async_cookie_t cookie)
|
||||
panic_show_mem("%s", err); /* Failed to decompress INTERNAL initramfs */
|
||||
|
||||
if (!initrd_start || IS_ENABLED(CONFIG_INITRAMFS_FORCE))
|
||||
goto done;
|
||||
return;
|
||||
|
||||
if (IS_ENABLED(CONFIG_BLK_DEV_RAM))
|
||||
printk(KERN_INFO "Trying to unpack rootfs image as initramfs...\n");
|
||||
@@ -739,9 +740,14 @@ static void __init do_populate_rootfs(void *unused, async_cookie_t cookie)
|
||||
printk(KERN_EMERG "Initramfs unpacking failed: %s\n", err);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
done:
|
||||
security_initramfs_populated();
|
||||
static void __init do_populate_rootfs(void *unused, async_cookie_t cookie)
|
||||
{
|
||||
scoped_with_init_fs() {
|
||||
unpack_initramfs(cookie);
|
||||
security_initramfs_populated();
|
||||
}
|
||||
|
||||
/*
|
||||
* If the initrd region is overlapped with crashkernel reserved region,
|
||||
|
||||
Reference in New Issue
Block a user