Commit 9687fd9101afaa1c4b1de7ffd2f9d7e53f45b29f

Authored by David Engraf
Committed by Linus Torvalds
1 parent d97b07c54f

initramfs: add write error checks

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>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 1 changed file with 4 additions and 2 deletions Side-by-side Diff

... ... @@ -369,7 +369,8 @@
369 369 static int __init do_copy(void)
370 370 {
371 371 if (count >= body_len) {
372   - xwrite(wfd, victim, body_len);
  372 + if (xwrite(wfd, victim, body_len) != body_len)
  373 + error("write error");
373 374 sys_close(wfd);
374 375 do_utime(vcollected, mtime);
375 376 kfree(vcollected);
... ... @@ -377,7 +378,8 @@
377 378 state = SkipIt;
378 379 return 0;
379 380 } else {
380   - xwrite(wfd, victim, count);
  381 + if (xwrite(wfd, victim, count) != count)
  382 + error("write error");
381 383 body_len -= count;
382 384 eat(count);
383 385 return 1;