Skip to content

Commit

Permalink
initramfs: add write error checks
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
dengraf authored and torvalds committed Aug 8, 2014
1 parent d97b07c commit 9687fd9
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions init/initramfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -369,15 +369,17 @@ static int __init do_name(void)
static int __init do_copy(void)
{
if (count >= body_len) {
xwrite(wfd, victim, body_len);
if (xwrite(wfd, victim, body_len) != body_len)
error("write error");
sys_close(wfd);
do_utime(vcollected, mtime);
kfree(vcollected);
eat(body_len);
state = SkipIt;
return 0;
} else {
xwrite(wfd, victim, count);
if (xwrite(wfd, victim, count) != count)
error("write error");
body_len -= count;
eat(count);
return 1;
Expand Down

0 comments on commit 9687fd9

Please sign in to comment.