Commit 6e3e37a5a7c91045497553bcbd6a5faea98b21b3

Authored by André Goddard Rosa
Committed by Linus Torvalds
1 parent 5cacdb4add

coredump: plug a memory leak situation on dump_seek()

After having started writing the coredump, if filesystem reports an error
anytime while writing part of the core file, we would leak a memory page
when bailing out.

Signed-off-by: André Goddard Rosa <andre.goddard@gmail.com>
Acked-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Roland McGrath <roland@redhat.com>
Cc: WANG Cong <amwang@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 1 changed file with 7 additions and 3 deletions Side-by-side Diff

include/linux/coredump.h
... ... @@ -16,6 +16,8 @@
16 16  
17 17 static inline int dump_seek(struct file *file, loff_t off)
18 18 {
  19 + int ret = 1;
  20 +
19 21 if (file->f_op->llseek && file->f_op->llseek != no_llseek) {
20 22 if (file->f_op->llseek(file, off, SEEK_CUR) < 0)
21 23 return 0;
22 24  
... ... @@ -29,13 +31,15 @@
29 31  
30 32 if (n > PAGE_SIZE)
31 33 n = PAGE_SIZE;
32   - if (!dump_write(file, buf, n))
33   - return 0;
  34 + if (!dump_write(file, buf, n)) {
  35 + ret = 0;
  36 + break;
  37 + }
34 38 off -= n;
35 39 }
36 40 free_page((unsigned long)buf);
37 41 }
38   - return 1;
  42 + return ret;
39 43 }
40 44  
41 45 #endif /* _LINUX_COREDUMP_H */