[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20190601132158.25821-11-sashal@kernel.org>
Date: Sat, 1 Jun 2019 09:19:47 -0400
From: Sasha Levin <sashal@...nel.org>
To: linux-kernel@...r.kernel.org, stable@...r.kernel.org
Cc: Christoph Hellwig <hch@....de>,
Steven Price <steven.price@....com>,
Mike Rapoport <rppt@...ux.ibm.com>,
Catalin Marinas <catalin.marinas@....com>,
Geert Uytterhoeven <geert@...ux-m68k.org>,
Alexander Viro <viro@...iv.linux.org.uk>,
Russell King <linux@...linux.org.uk>,
Will Deacon <will.deacon@....com>,
Guan Xuetao <gxt@....edu.cn>,
Andrew Morton <akpm@...ux-foundation.org>,
Linus Torvalds <torvalds@...ux-foundation.org>,
Sasha Levin <sashal@...nel.org>
Subject: [PATCH AUTOSEL 4.19 011/141] initramfs: free initrd memory if opening /initrd.image fails
From: Christoph Hellwig <hch@....de>
[ Upstream commit 54c7a8916a887f357088f99e9c3a7720cd57d2c8 ]
Patch series "initramfs tidyups".
I've spent some time chasing down behavior in initramfs and found
plenty of opportunity to improve the code. A first stab on that is
contained in this series.
This patch (of 7):
We free the initrd memory for all successful or error cases except for the
case where opening /initrd.image fails, which looks like an oversight.
Steven said:
: This also changes the behaviour when CONFIG_INITRAMFS_FORCE is enabled
: - specifically it means that the initrd is freed (previously it was
: ignored and never freed). But that seems like reasonable behaviour and
: the previous behaviour looks like another oversight.
Link: http://lkml.kernel.org/r/20190213174621.29297-3-hch@lst.de
Signed-off-by: Christoph Hellwig <hch@....de>
Reviewed-by: Steven Price <steven.price@....com>
Acked-by: Mike Rapoport <rppt@...ux.ibm.com>
Cc: Catalin Marinas <catalin.marinas@....com> [arm64]
Cc: Geert Uytterhoeven <geert@...ux-m68k.org> [m68k]
Cc: Alexander Viro <viro@...iv.linux.org.uk>
Cc: Russell King <linux@...linux.org.uk>
Cc: Will Deacon <will.deacon@....com>
Cc: Guan Xuetao <gxt@....edu.cn>
Signed-off-by: Andrew Morton <akpm@...ux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@...ux-foundation.org>
Signed-off-by: Sasha Levin <sashal@...nel.org>
---
init/initramfs.c | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
diff --git a/init/initramfs.c b/init/initramfs.c
index f6f4a1e4cd547..cd5fb00fcb549 100644
--- a/init/initramfs.c
+++ b/init/initramfs.c
@@ -612,13 +612,12 @@ static int __init populate_rootfs(void)
printk(KERN_INFO "Trying to unpack rootfs image as initramfs...\n");
err = unpack_to_rootfs((char *)initrd_start,
initrd_end - initrd_start);
- if (!err) {
- free_initrd();
+ if (!err)
goto done;
- } else {
- clean_rootfs();
- unpack_to_rootfs(__initramfs_start, __initramfs_size);
- }
+
+ clean_rootfs();
+ unpack_to_rootfs(__initramfs_start, __initramfs_size);
+
printk(KERN_INFO "rootfs image is not initramfs (%s)"
"; looks like an initrd\n", err);
fd = ksys_open("/initrd.image",
@@ -632,7 +631,6 @@ static int __init populate_rootfs(void)
written, initrd_end - initrd_start);
ksys_close(fd);
- free_initrd();
}
done:
/* empty statement */;
@@ -642,9 +640,9 @@ static int __init populate_rootfs(void)
initrd_end - initrd_start);
if (err)
printk(KERN_EMERG "Initramfs unpacking failed: %s\n", err);
- free_initrd();
#endif
}
+ free_initrd();
flush_delayed_fput();
/*
* Try loading default modules from initramfs. This gives
--
2.20.1
Powered by blists - more mailing lists