Linux-Fsdevel Archive on lore.kernel.org
help / color / mirror / Atom feed
* fixes for: decruft the early init / initrd / initramfs code v2
@ 2020-07-27 16:07 Christoph Hellwig
2020-07-27 16:07 ` [PATCH 1/3] initramfs: remove clean_rootfs Christoph Hellwig
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Christoph Hellwig @ 2020-07-27 16:07 UTC (permalink / raw)
To: linux-kernel; +Cc: Al Viro, Linus Torvalds, linux-fsdevel
Hi all,
this series fixes up a few issues found in my
git://git.infradead.org/users/hch/misc.git init-user-pointers
tree. The patches are relative to it.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/3] initramfs: remove clean_rootfs
2020-07-27 16:07 fixes for: decruft the early init / initrd / initramfs code v2 Christoph Hellwig
@ 2020-07-27 16:07 ` Christoph Hellwig
2020-07-27 16:07 ` [PATCH 2/3] initramfs: pass a non-f_pos offset to xwrite Christoph Hellwig
2020-07-27 16:07 ` [PATCH 3/3] initd: pass a non-f_pos offset to kernel_read/kernel_write Christoph Hellwig
2 siblings, 0 replies; 4+ messages in thread
From: Christoph Hellwig @ 2020-07-27 16:07 UTC (permalink / raw)
To: linux-kernel; +Cc: Al Viro, Linus Torvalds, linux-fsdevel, Marek Szyprowski
There is no point in trying to clean up after unpacking the initramfs
failed, as it should never get past the magic number check. In addition
d_genocide is actually the wrong thing to do here, it should have been
simple_recursive_remove().
Fixes: 38d014f6d446 ("initramfs: simplify clean_rootfs")
Reported-by: Marek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
init/initramfs.c | 11 -----------
1 file changed, 11 deletions(-)
diff --git a/init/initramfs.c b/init/initramfs.c
index 3823d15e5d2619..50ec7e3c5389aa 100644
--- a/init/initramfs.c
+++ b/init/initramfs.c
@@ -576,16 +576,6 @@ static inline bool kexec_free_initrd(void)
#endif /* CONFIG_KEXEC_CORE */
#ifdef CONFIG_BLK_DEV_RAM
-static void __init clean_rootfs(void)
-{
- struct path path;
-
- if (kern_path("/", 0, &path))
- return;
- d_genocide(path.dentry);
- path_put(&path);
-}
-
static void __init populate_initrd_image(char *err)
{
ssize_t written;
@@ -625,7 +615,6 @@ static int __init populate_rootfs(void)
err = unpack_to_rootfs((char *)initrd_start, initrd_end - initrd_start);
if (err) {
#ifdef CONFIG_BLK_DEV_RAM
- clean_rootfs();
populate_initrd_image(err);
#else
printk(KERN_EMERG "Initramfs unpacking failed: %s\n", err);
--
2.27.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 2/3] initramfs: pass a non-f_pos offset to xwrite
2020-07-27 16:07 fixes for: decruft the early init / initrd / initramfs code v2 Christoph Hellwig
2020-07-27 16:07 ` [PATCH 1/3] initramfs: remove clean_rootfs Christoph Hellwig
@ 2020-07-27 16:07 ` Christoph Hellwig
2020-07-27 16:07 ` [PATCH 3/3] initd: pass a non-f_pos offset to kernel_read/kernel_write Christoph Hellwig
2 siblings, 0 replies; 4+ messages in thread
From: Christoph Hellwig @ 2020-07-27 16:07 UTC (permalink / raw)
To: linux-kernel; +Cc: Al Viro, Linus Torvalds, linux-fsdevel
Pass a offset with the same scope as the file instead of ->f_pos.
Fixes: b63c1cd1c339 ("initramfs: switch initramfs unpacking to struct file based APIs")
Reported-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
init/initramfs.c | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/init/initramfs.c b/init/initramfs.c
index 50ec7e3c5389aa..584bc8fe88e77c 100644
--- a/init/initramfs.c
+++ b/init/initramfs.c
@@ -13,13 +13,14 @@
#include <linux/memblock.h>
#include <linux/namei.h>
-static ssize_t __init xwrite(struct file *file, const char *p, size_t count)
+static ssize_t __init xwrite(struct file *file, const char *p, size_t count,
+ loff_t *pos)
{
ssize_t out = 0;
/* sys_write only can write MAX_RW_COUNT aka 2G-4K bytes at most */
while (count) {
- ssize_t rv = kernel_write(file, p, count, &file->f_pos);
+ ssize_t rv = kernel_write(file, p, count, pos);
if (rv < 0) {
if (rv == -EINTR || rv == -EAGAIN)
@@ -317,6 +318,7 @@ static int __init maybe_link(void)
}
static __initdata struct file *wfile;
+static __initdata loff_t wfile_pos;
static int __init do_name(void)
{
@@ -336,6 +338,7 @@ static int __init do_name(void)
wfile = filp_open(collected, openflags, mode);
if (IS_ERR(wfile))
return 0;
+ wfile_pos = 0;
vfs_fchown(wfile, uid, gid);
vfs_fchmod(wfile, mode);
@@ -365,7 +368,7 @@ static int __init do_copy(void)
if (byte_count >= body_len) {
struct timespec64 t[2] = { };
- if (xwrite(wfile, victim, body_len) != body_len)
+ if (xwrite(wfile, victim, body_len, &wfile_pos) != body_len)
error("write error");
t[0].tv_sec = mtime;
@@ -377,7 +380,7 @@ static int __init do_copy(void)
state = SkipIt;
return 0;
} else {
- if (xwrite(wfile, victim, byte_count) != byte_count)
+ if (xwrite(wfile, victim, byte_count, &wfile_pos) != byte_count)
error("write error");
body_len -= byte_count;
eat(byte_count);
@@ -580,6 +583,7 @@ static void __init populate_initrd_image(char *err)
{
ssize_t written;
struct file *file;
+ loff_t pos = 0;
unpack_to_rootfs(__initramfs_start, __initramfs_size);
@@ -589,7 +593,8 @@ static void __init populate_initrd_image(char *err)
if (IS_ERR(file))
return;
- written = xwrite(file, (char *)initrd_start, initrd_end - initrd_start);
+ written = xwrite(file, (char *)initrd_start, initrd_end - initrd_start,
+ &pos);
if (written != initrd_end - initrd_start)
pr_err("/initrd.image: incomplete write (%zd != %ld)\n",
written, initrd_end - initrd_start);
--
2.27.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 3/3] initd: pass a non-f_pos offset to kernel_read/kernel_write
2020-07-27 16:07 fixes for: decruft the early init / initrd / initramfs code v2 Christoph Hellwig
2020-07-27 16:07 ` [PATCH 1/3] initramfs: remove clean_rootfs Christoph Hellwig
2020-07-27 16:07 ` [PATCH 2/3] initramfs: pass a non-f_pos offset to xwrite Christoph Hellwig
@ 2020-07-27 16:07 ` Christoph Hellwig
2 siblings, 0 replies; 4+ messages in thread
From: Christoph Hellwig @ 2020-07-27 16:07 UTC (permalink / raw)
To: linux-kernel; +Cc: Al Viro, Linus Torvalds, linux-fsdevel
Pass an explicit offset instead of ->f_pos, and to make that easier use
file scope file structs and offsets everywhere except for
identify_ramdisk_image instead of the current strange mix. This also
fixes the fact that identify_ramdisk_image fails to reset the file
position to the rd_image_start parameter instead of the default 0.
Fixes: 18468d879596 ("initrd: switch initrd loading to struct file based APIs")
Reported-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
init/do_mounts_rd.c | 29 +++++++++++++----------------
1 file changed, 13 insertions(+), 16 deletions(-)
diff --git a/init/do_mounts_rd.c b/init/do_mounts_rd.c
index 8307fdb5d136b8..d4255c10432a8b 100644
--- a/init/do_mounts_rd.c
+++ b/init/do_mounts_rd.c
@@ -14,6 +14,8 @@
#include <linux/decompress/generic.h>
+static struct file *in_file, *out_file;
+static loff_t in_pos, out_pos;
static int __init prompt_ramdisk(char *str)
{
@@ -31,8 +33,7 @@ static int __init ramdisk_start_setup(char *str)
}
__setup("ramdisk_start=", ramdisk_start_setup);
-static int __init crd_load(struct file *in_file, struct file *out_file,
- decompress_fn deco);
+static int __init crd_load(decompress_fn deco);
/*
* This routine tries to find a RAM disk image to load, and returns the
@@ -54,7 +55,7 @@ static int __init crd_load(struct file *in_file, struct file *out_file,
* lz4
*/
static int __init
-identify_ramdisk_image(struct file *file, int start_block,
+identify_ramdisk_image(struct file *file, loff_t pos,
decompress_fn *decompressor)
{
const int size = 512;
@@ -66,7 +67,7 @@ identify_ramdisk_image(struct file *file, int start_block,
unsigned char *buf;
const char *compress_name;
unsigned long n;
- loff_t pos;
+ int start_block = rd_image_start;
buf = kmalloc(size, GFP_KERNEL);
if (!buf)
@@ -185,7 +186,6 @@ static unsigned long nr_blocks(struct file *file)
int __init rd_load_image(char *from)
{
int res = 0;
- struct file *in_file, *out_file;
unsigned long rd_blocks, devblocks;
int nblocks, i;
char *buf = NULL;
@@ -203,12 +203,13 @@ int __init rd_load_image(char *from)
if (IS_ERR(in_file))
goto noclose_input;
- nblocks = identify_ramdisk_image(in_file, rd_image_start, &decompressor);
+ in_pos = rd_image_start * BLOCK_SIZE;
+ nblocks = identify_ramdisk_image(in_file, in_pos, &decompressor);
if (nblocks < 0)
goto done;
if (nblocks == 0) {
- if (crd_load(in_file, out_file, decompressor) == 0)
+ if (crd_load(decompressor) == 0)
goto successful_load;
goto done;
}
@@ -252,8 +253,8 @@ int __init rd_load_image(char *from)
fput(in_file);
break;
}
- kernel_read(in_file, buf, BLOCK_SIZE, &in_file->f_pos);
- kernel_write(out_file, buf, BLOCK_SIZE, &out_file->f_pos);
+ kernel_read(in_file, buf, BLOCK_SIZE, &in_pos);
+ kernel_write(out_file, buf, BLOCK_SIZE, &out_pos);
#if !defined(CONFIG_S390)
if (!(i % 16)) {
pr_cont("%c\b", rotator[rotate & 0x3]);
@@ -284,11 +285,10 @@ int __init rd_load_disk(int n)
static int exit_code;
static int decompress_error;
-static struct file *crd_infile, *crd_outfile;
static long __init compr_fill(void *buf, unsigned long len)
{
- long r = kernel_read(crd_infile, buf, len, &crd_infile->f_pos);
+ long r = kernel_read(in_file, buf, len, &in_pos);
if (r < 0)
printk(KERN_ERR "RAMDISK: error while reading compressed data");
else if (r == 0)
@@ -298,7 +298,7 @@ static long __init compr_fill(void *buf, unsigned long len)
static long __init compr_flush(void *window, unsigned long outcnt)
{
- long written = kernel_write(crd_outfile, window, outcnt, &crd_outfile->f_pos);
+ long written = kernel_write(out_file, window, outcnt, &out_pos);
if (written != outcnt) {
if (decompress_error == 0)
printk(KERN_ERR
@@ -317,12 +317,9 @@ static void __init error(char *x)
decompress_error = 1;
}
-static int __init crd_load(struct file *in_file, struct file *out_file,
- decompress_fn deco)
+static int __init crd_load(decompress_fn deco)
{
int result;
- crd_infile = in_file;
- crd_outfile = out_file;
if (!deco) {
pr_emerg("Invalid ramdisk decompression routine. "
--
2.27.0
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-07-27 16:08 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-27 16:07 fixes for: decruft the early init / initrd / initramfs code v2 Christoph Hellwig
2020-07-27 16:07 ` [PATCH 1/3] initramfs: remove clean_rootfs Christoph Hellwig
2020-07-27 16:07 ` [PATCH 2/3] initramfs: pass a non-f_pos offset to xwrite Christoph Hellwig
2020-07-27 16:07 ` [PATCH 3/3] initd: pass a non-f_pos offset to kernel_read/kernel_write Christoph Hellwig
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).