Skip to content

Commit 9687fd9

Browse files
dengraftorvalds
authored andcommitted
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>
1 parent d97b07c commit 9687fd9

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

‎init/initramfs.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,15 +369,17 @@ static int __init do_name(void)
369369
static int __init do_copy(void)
370370
{
371371
if (count >= body_len) {
372-
xwrite(wfd, victim, body_len);
372+
if (xwrite(wfd, victim, body_len) != body_len)
373+
error("write error");
373374
sys_close(wfd);
374375
do_utime(vcollected, mtime);
375376
kfree(vcollected);
376377
eat(body_len);
377378
state = SkipIt;
378379
return 0;
379380
} else {
380-
xwrite(wfd, victim, count);
381+
if (xwrite(wfd, victim, count) != count)
382+
error("write error");
381383
body_len -= count;
382384
eat(count);
383385
return 1;

0 commit comments

Comments
 (0)