Skip to contentSkip to conversation

coredumps truncated after "new helper: dump_align()"

REGRESSION Peter Wu 3 participants 7 messages Nov 15, 2013 – Nov 17, 2013 VFS

lore
Share & tools
lore

Peter Wu

author
#0 lore raw

Hi Al,

Somewhere in the merge window of 3.13, coredumps appear truncated. Instead of 319488 bytes, I get 868 bytes (tested with x86_64 only).

The latest Linus' master (v3.12-9579-g049ffa8) is still affected. Bisection leads to:

commit 22a8cb8248ba5d340307ba72432253b1dbdb5cf7

Author: Al Viro <[email protected]>
Date:   Tue Oct 8 11:05:01 2013 -0400

new helper: dump_align()

dump_skip to given alignment...

:040000 040000 880920de653955485453c8cc11045bb09e2934f7 f8b348d32b59ae7a16cbc3eb2a6319f4df0210eb M      arch
:040000 040000 eaeffe2378806e95d23b3f3a9dc0fa8f078d6052 88866abde93296a05b4adda869280bc05403936f M      fs
:040000 040000 218263e01dd7473998c54a5a68ed5ae072854d24 ff531dce919862b662fef19a9a049f0de3db38ce M      include

I first noticed this bug on my laptop (v3.12-7033-g42a2d92) and reproduced this bug in a QEMU virtual machine too. If you want, I can also provide the git bisect script that starts QEMU and tests the serial output. That allows a kernel to be verified in two seconds (minus build times).

Regards,
Peter

maintainer
#1 lore raw
Quoted 8 lines · Peter Wu

Hi Al,

Somewhere in the merge window of 3.13, coredumps appear truncated. Instead of 319488 bytes, I get 868 bytes (tested with x86_64 only).

The latest Linus' master (v3.12-9579-g049ffa8) is still affected. Bisection leads to:

Quoted 7 lines

commit 22a8cb8248ba5d340307ba72432253b1dbdb5cf7

Author: Al Viro <[email protected]>
Date:   Tue Oct 8 11:05:01 2013 -0400

new helper: dump_align()

dump_skip to given alignment...

Argh... Really dumb braino when getting rid of long long division in dump_align(). Please, see if this gets rid of the entire problem on your setup - it definitely fixes a bug in there and it seems to restore the normal behaviour on the reproducer I've got here, but...

I'm going to send that to Linus, along with another coredump fix (dump_emit() ought to use __kernel_write() instead of vfs_write()) shortly anyway, but if you spot anything still broken...

fs/coredump.c +2 -2
index 62406b6..a2856f7 100644
@@ -733,7 +733,7 @@ int dump_align(struct coredump_params *cprm, int align)
 {
 	unsigned mod = cprm->written & (align - 1);
 	if (align & (align - 1))
-		return -EINVAL;
-	return mod ? dump_skip(cprm, align - mod) : 0;
+		return 0;
+	return mod ? dump_skip(cprm, align - mod) : 1;
 }
 EXPORT_SYMBOL(dump_align);
#2 lore raw
Quoted 8 lines · Al Viro
Quoted 7 lines · Peter Wu

Somewhere in the merge window of 3.13, coredumps appear truncated. Instead of 319488 bytes, I get 868 bytes (tested with x86_64 only).

The latest Linus' master (v3.12-9579-g049ffa8) is still affected. Bisection leads to:

commit 22a8cb8248ba5d340307ba72432253b1dbdb5cf7

trivia:

fs/coredump.c

Quoted 1 line
fs/coredump.c +0 -0

[]

fs/coredump.c int dump_align(struct coredump_params *cprm, int align) · line 739

Quoted 10 lines
fs/coredump.c +2 -2
@@ -733,7 +733,7 @@ int dump_align(struct coredump_params *cprm, int align)
 {
 	unsigned mod = cprm->written & (align - 1);
 	if (align & (align - 1))
-		return -EINVAL;
-	return mod ? dump_skip(cprm, align - mod) : 0;
+		return 0;
+	return mod ? dump_skip(cprm, align - mod) : 1;
 }
 EXPORT_SYMBOL(dump_align);

extern int dump_skip(struct coredump_params *cprm, size_t nr); extern int dump_emit(struct coredump_params *cprm, const void *addr, int nr); extern int dump_align(struct coredump_params *cprm, int align);

Perhaps all of these should return bool not int.
Is there a reason these should be EXPORT_SYMBOL?

author
#3 lore raw
In reply to Al Viro
Quoted 31 lines · On Friday 15 November 2013 20:38:38 Al Viro wrote:
Quoted 8 lines · Peter Wu

Hi Al,

Somewhere in the merge window of 3.13, coredumps appear truncated. Instead of 319488 bytes, I get 868 bytes (tested with x86_64 only).

The latest Linus' master (v3.12-9579-g049ffa8) is still affected. Bisection leads to:

Quoted 7 lines

commit 22a8cb8248ba5d340307ba72432253b1dbdb5cf7

Author: Al Viro <[email protected]>
Date:   Tue Oct 8 11:05:01 2013 -0400

new helper: dump_align()

dump_skip to given alignment...

Argh... Really dumb braino when getting rid of long long division in dump_align(). Please, see if this gets rid of the entire problem on your setup - it definitely fixes a bug in there and it seems to restore the normal behaviour on the reproducer I've got here, but...

I'm going to send that to Linus, along with another coredump fix (dump_emit() ought to use __kernel_write() instead of vfs_write()) shortly anyway, but if you spot anything still broken...

fs/coredump.c +0 -0
index 62406b6..a2856f7 100644

fs/coredump.c int dump_align(struct coredump_params *cprm, int align) · line 739

Quoted 9 lines
fs/coredump.c +2 -2
@@ -733,7 +733,7 @@ int dump_align(struct coredump_params *cprm, int align)
 {
 	unsigned mod = cprm->written & (align - 1);
 	if (align & (align - 1))
-		return -EINVAL;
-	return mod ? dump_skip(cprm, align - mod) : 0;
+		return 0;
+	return mod ? dump_skip(cprm, align - mod) : 1;
 }
 EXPORT_SYMBOL(dump_align);

Unfortunately, this patch still does not fix the issue. I rm'd the output directory just to be sure, but the bug is still there. What does this commit do anyway? The commit message is quite vague.

Please find the files to reproduce the bug in the tarball. Edit bisecter.sh to change the paths to the initrd, object output directory and serial output ("dmesg") as needed.

The initrd should contain:
/init
/bin/busybox (statically linked)
/bin/segfault (also statically linked, source included)

initrd containing these three files can be generated with:
find | cpio --owner=root:root -H newc -o > initrd

The .config file (named qemucore.config) which I use for reproduction is also included. The resulting segfault program is 742752 bytes (stripped).

maintainer
#4 lore raw
Quoted 3 lines · Peter Wu

Unfortunately, this patch still does not fix the issue. I rm'd the output directory just to be sure, but the bug is still there. What does this commit do anyway? The commit message is quite vague.

Introduces a helper that used to be open-coded in a bunch of places - pads the coredump to given alignment. And switches those places to that new helper...

FWIW, I haven't tried that on your config yet, but here (with the patch in my previous mail) I'm seeing a sane-looking coredump - -rw------- 1 root root 315392 Nov 15 17:48 core
Different userland, presumably, since that static binary is 684349 bytes long.

I'll try to reproduce with your config...

maintainer
#5 lore raw
Quoted 10 lines · Al Viro
Quoted 3 lines · Peter Wu

Unfortunately, this patch still does not fix the issue. I rm'd the output directory just to be sure, but the bug is still there. What does this commit do anyway? The commit message is quite vague.

Introduces a helper that used to be open-coded in a bunch of places - pads the coredump to given alignment. And switches those places to that new helper...

Quoted 7 lines

FWIW, I haven't tried that on your config yet, but here (with the patch in my previous mail) I'm seeing a sane-looking coredump - -rw------- 1 root root 315392 Nov 15 17:48 core
Different userland, presumably, since that static binary is 684349 bytes long.

I'll try to reproduce with your config...

... and on your config I'm seeing
Inited
Segmentation fault (core dumped)

[    0.123351] Core size: 315392

in the log. Same size, same apparently sane coredump. Can you check what you get on mainline + diff below (combination of dump_align() and locking fix)?

fs/coredump.c +3 -3
index 62406b6..bc3fbcd 100644
@@ -695,7 +695,7 @@ int dump_emit(struct coredump_params *cprm, const void *addr, int nr)
 	while (nr) {
 		if (dump_interrupted())
 			return 0;
-		n = vfs_write(file, addr, nr, &pos);
+		n = __kernel_write(file, addr, nr, &pos);
 		if (n <= 0)
 			return 0;
 		file->f_pos = pos;
@@ -733,7 +733,7 @@ int dump_align(struct coredump_params *cprm, int align)
 {
 	unsigned mod = cprm->written & (align - 1);
 	if (align & (align - 1))
-		return -EINVAL;
-	return mod ? dump_skip(cprm, align - mod) : 0;
+		return 0;
+	return mod ? dump_skip(cprm, align - mod) : 1;
 }
 EXPORT_SYMBOL(dump_align);
author
#6 lore raw
Quoted 27 lines · On Sunday 17 November 2013 06:19:07 Al Viro wrote:
Quoted 24 lines · Al Viro
Quoted 4 lines · Peter Wu

Unfortunately, this patch still does not fix the issue. I rm'd the output
directory just to be sure, but the bug is still there. What does this commit do anyway? The commit message is quite vague.

Introduces a helper that used to be open-coded in a bunch of places - pads the coredump to given alignment. And switches those places to that new helper...

FWIW, I haven't tried that on your config yet, but here (with the patch in my previous mail) I'm seeing a sane-looking coredump - -rw------- 1 root root 315392 Nov 15 17:48 core
Different userland, presumably, since that static binary is 684349 bytes long.

Quoted 1 line

I'll try to reproduce with your config...

Quoted 7 lines

... and on your config I'm seeing
Inited
Segmentation fault (core dumped)

[    0.123351] Core size: 315392

in the log. Same size, same apparently sane coredump. Can you check what you get on mainline + diff below (combination of dump_align() and locking fix)?

Hmm, I cannot reproduce the bug with the two-liner patch you provided before. I must have made a mistake with the previous test as the environment is still the same.

The bug is fixed with both your two-liner patch and the __kernel_write one. In addition, the __kernel_write patch removes the lockdep warning reported by Dave Jones[1].

Thanks,
Peter

[1]: http://lkml.org/lkml/2013/11/13/450