coredump: let dump_emit() bail out on short writes
authorJann Horn <jannh@google.com>
Fri, 16 Oct 2020 03:12:43 +0000 (20:12 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 16 Oct 2020 18:11:21 +0000 (11:11 -0700)
dump_emit() has a retry loop, but there seems to be no way for that retry
logic to actually be used; and it was also buggy, writing the same data
repeatedly after a short write.

Let's just bail out on a short write.

Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Jann Horn <jannh@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: "Eric W . Biederman" <ebiederm@xmission.com>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Hugh Dickins <hughd@google.com>
Link: http://lkml.kernel.org/r/20200827114932.3572699-3-jannh@google.com
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
fs/coredump.c

index 76e7c10..5e24c06 100644 (file)
@@ -840,17 +840,17 @@ int dump_emit(struct coredump_params *cprm, const void *addr, int nr)
        ssize_t n;
        if (cprm->written + nr > cprm->limit)
                return 0;
-       while (nr) {
-               if (dump_interrupted())
-                       return 0;
-               n = __kernel_write(file, addr, nr, &pos);
-               if (n <= 0)
-                       return 0;
-               file->f_pos = pos;
-               cprm->written += n;
-               cprm->pos += n;
-               nr -= n;
-       }
+
+
+       if (dump_interrupted())
+               return 0;
+       n = __kernel_write(file, addr, nr, &pos);
+       if (n != nr)
+               return 0;
+       file->f_pos = pos;
+       cprm->written += n;
+       cprm->pos += n;
+
        return 1;
 }
 EXPORT_SYMBOL(dump_emit);