public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] add error checks to initramfs
@ 2014-07-18  8:59 David Engraf
  0 siblings, 0 replies; only message in thread
From: David Engraf @ 2014-07-18  8:59 UTC (permalink / raw)
  To: Andrew Morton, Daniel M. Weeks, Tetsuo Handa, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 299 bytes --]

On a system with low memory extracting the initramfs may fail. If this 
happens the user gets "Failed to execute /init" instead of an initramfs 
error.

Check return value of sys_write and call error() when the write was 
incomplete or failed.

Signed-off-by: David Engraf <david.engraf@sysgo.com>


[-- Attachment #2: initramfs_error_check.patch --]
[-- Type: text/x-diff, Size: 681 bytes --]

diff --git a/init/initramfs.c b/init/initramfs.c
index a8497fa..64013cc 100644
--- a/init/initramfs.c
+++ b/init/initramfs.c
@@ -346,7 +346,8 @@ static int __init do_name(void)
 static int __init do_copy(void)
 {
 	if (count >= body_len) {
-		sys_write(wfd, victim, body_len);
+		if (sys_write(wfd, victim, body_len) != body_len)
+			error("write error");
 		sys_close(wfd);
 		do_utime(vcollected, mtime);
 		kfree(vcollected);
@@ -354,7 +355,8 @@ static int __init do_copy(void)
 		state = SkipIt;
 		return 0;
 	} else {
-		sys_write(wfd, victim, count);
+		if (sys_write(wfd, victim, count) != count)
+			error("write error");
 		body_len -= count;
 		eat(count);
 		return 1;

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2014-07-18  9:07 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-07-18  8:59 [PATCH] add error checks to initramfs David Engraf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox