Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 567048 - hardened-sources-4.2.6-r6 PAX: size overflow detected in function get_bits lib/decompress_bunzip2.c:143 cicus.147_113 max, count: 19, decl: inbufBits; num: 0; cont ext: bunzip_data;
Summary: hardened-sources-4.2.6-r6 PAX: size overflow detected in function get_bits li...
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Hardened (show other bugs)
Hardware: AMD64 Linux
: Normal normal (vote)
Assignee: The Gentoo Linux Hardened Team
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-11-28 22:09 UTC by Martin Filo
Modified: 2016-07-21 16:54 UTC (History)
4 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
.config (.config,91.82 KB, text/x-mpsub)
2015-11-29 16:17 UTC, Martin Filo
Details
decompress_bunzip.o (decompress_bunzip2.o,12.16 KB, application/x-object)
2015-11-29 16:18 UTC, Martin Filo
Details
result of EXTRA_CFLAGS="-fdump-tree-all -fdumo-ipa-all" make lib/decompress_bunzip2.o (decompress_bunzip2.o,12.16 KB, application/x-object)
2015-11-30 18:16 UTC, Martin Filo
Details
decompress_bunzip2.s (decompress_bunzip2.s,57.12 KB, text/x-asm)
2015-11-30 18:17 UTC, Martin Filo
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Filo 2015-11-28 22:09:10 UTC
This bug is new in 4.2.6-r6.
Version 4.2.6-r5 is not affected.

Decompress of initramfs crash with this error:
Unpacking initramfs...^M
PAX: size overflow detected in function get_bits lib/decompress_bunzip2.c:143 cicus.147_113 max, count: 19, decl: inbufBits; num: 0; cont
ext: bunzip_data;^M
CPU: 2 PID: 1 Comm: swapper/0 Not tainted 4.2.6-hardened-r6 #1^M
Hardware name: To be filled by O.E.M. To be filled by O.E.M./M5A99FX PRO R2.0, BIOS 2501 04/07/2014^M
 ffffffff8186d72b 62cd2da4758f95c8 0000000000000000 ffffffff8166059d^M
 ffffffff8186d722 ffffffff811756b5 ffff88084eff9d80 ffff88082a1b0000^M
 0000000000000000 ffffffff81c15418 0000000000000018 ffffffff81c4b476^M
Call Trace:^M
 [<ffffffff8166059d>] ? dump_stack+0x40/0x54^M
 [<ffffffff811756b5>] ? report_size_overflow+0x35/0x40^M
 [<ffffffff81c15418>] ? write_buffer+0x62/0x10e^M
 [<ffffffff81c4b476>] ? get_bits+0x283/0x417^M
 [<ffffffff81c154c4>] ? write_buffer+0x10e/0x10e^M
 [<ffffffff81c4b654>] ? get_next_block+0x4a/0xe2f^M
 [<ffffffff8113b3d7>] ? __pte_alloc_kernel+0x37/0xd0^M
 [<ffffffff8114e15e>] ? vmap_page_range_noflush+0x2be/0x370^M
 [<ffffffff8114e651>] ? map_vm_area+0x41/0x70^M
 [<ffffffff8114fa74>] ? __vmalloc_node_range+0x274/0x3b0^M
 [<ffffffff81c4c6e6>] ? bunzip2+0x289/0x784^M
 [<ffffffff81c154c4>] ? write_buffer+0x10e/0x10e^M
 [<ffffffff8114fe96>] ? vmalloc+0x56/0x60^M
 [<ffffffff81c154c4>] ? write_buffer+0x10e/0x10e^M
 [<ffffffff81c4c8fc>] ? bunzip2+0x49f/0x784^M
 [<ffffffff81c15f6b>] ? unpack_to_rootfs+0x228/0x466^M
 [<ffffffff81c15203>] ? md_run_setup+0xcb/0xcb^M
 [<ffffffff81c16856>] ? populate_rootfs+0xbe/0x159^M
 [<ffffffff81c16798>] ? do_header+0x2d5/0x2d5^M
 [<ffffffff810004a7>] ? do_one_initcall+0x87/0x190^M
 [<ffffffff81c13ab7>] ? kernel_init_freeable+0x173/0x267^M
 [<ffffffff8165a290>] ? rest_init+0x80/0x80^M
 [<ffffffff8165a299>] ? kernel_init+0x9/0xe0^M
 [<ffffffff81666b79>] ? ret_from_fork+0x39/0x60^M
 [<ffffffff8165a290>] ? rest_init+0x80/0x80^M
Kernel panic - not syncing: Attempted to kill init! exitcode=0x00000009^M
Comment 1 PaX Team 2015-11-28 22:44:35 UTC
could you print out the values of bd->inbufBits and bd->inbufPos before line 143 like this:

printk("PAX: bd->inbufBits:%x bd->inbufPos:%lx\n", bd->inbufBits, bd->inbufPos);
Comment 2 Martin Filo 2015-11-29 00:26:40 UTC
PAX: bd->inbufBits:0 bd->inbufPos:0
PAX: bd->inbufBits:42 bd->inbufPos:1
PAX: bd->inbufBits:425a bd->inbufPos:2
PAX: bd->inbufBits:425a68 bd->inbufPos:3
PAX: bd->inbufBits:425a6839 bd->inbufPos:4
Comment 3 PaX Team 2015-11-29 02:10:11 UTC
hmm, it looks like some code is trying to extract more than 32 bits but this function cannot return that many. can you also add bits_wanted and bd->inbufBitCount to the printk to see if that's really the case?
Comment 4 PaX Team 2015-11-29 12:14:25 UTC
here's a discussion thread on the btrfs list: http://marc.info/?t=144862133900003&r=1&w=2 , perhaps you can try the proposed patch too (though i'm not sure if it's the right fix as it merely avoids triggering the overflow but otherwise doesn't touch the merge logic).
Comment 5 Martin Filo 2015-11-29 12:19:20 UTC
I added 
printk("PAX: bd->inbufBits:%x bd->inbufPos:%lx bd->inbufBitCount%x\n", bd->inbufBits,bd->inbufPos,bd->inbufBitCount);

And there is result:

Unpacking initramfs...
PAX: bd->inbufBits:0 bd->inbufPos:0 bd->inbufBitCount0
PAX: bd->inbufBits:42 bd->inbufPos:1 bd->inbufBitCount8
PAX: bd->inbufBits:425a bd->inbufPos:2 bd->inbufBitCount10
PAX: bd->inbufBits:425a68 bd->inbufPos:3 bd->inbufBitCount0
PAX: bd->inbufBits:425a6839 bd->inbufPos:4 bd->inbufBitCount0
PAX: size overflow detected in function get_bits lib/decompress_bunzip2.c:144 ci
cus.151_117 max, count: 19, decl: inbufBits; num: 0; context: bunzip_data;
CPU: 0 PID: 1 Comm: swapper/0 Not tainted 4.2.6-hardened-r6 #3
Comment 6 PaX Team 2015-11-29 12:22:19 UTC
(In reply to PaX Team from comment #4)
> here's a discussion thread on the btrfs list:
> http://marc.info/?t=144862133900003&r=1&w=2 , perhaps you can try the
> proposed patch too (though i'm not sure if it's the right fix as it merely
> avoids triggering the overflow but otherwise doesn't touch the merge logic).

oops, wrong bug, ignore me ;).
Comment 7 PaX Team 2015-11-29 12:27:32 UTC
can you also print out bits_wanted?
Comment 8 Martin Filo 2015-11-29 14:40:10 UTC
Sorry, I missed bits_wanted.
There is output of printk("PAX: bd->inbufBits:%x bd->inbufPos:%lx bd->inbufBitCount%x, bits_wanted:%x\n", bd->inbufBits,bd->inbufPos,bd->inbufBitCount,bits_wanted);


Unpacking initramfs...
PAX: bd->inbufBits:0 bd->inbufPos:0 bd->inbufBitCount0, bits_wanted:20
PAX: bd->inbufBits:42 bd->inbufPos:1 bd->inbufBitCount8, bits_wanted:20
PAX: bd->inbufBits:425a bd->inbufPos:2 bd->inbufBitCount10, bits_wanted:20
PAX: bd->inbufBits:425a68 bd->inbufPos:3 bd->inbufBitCount0, bits_wanted:8
PAX: bd->inbufBits:425a6839 bd->inbufPos:4 bd->inbufBitCount0, bits_wanted:18
PAX: size overflow detected in function get_bits lib/decompress_bunzip2.c:144 ci
cus.151_118 max, count: 19, decl: inbufBits; num: 0; context: bunzip_data;
CPU: 0 PID: 1 Comm: swapper/0 Not tainted 4.2.6-hardened-r6 #5
Comment 9 Brad Spengler 2015-11-29 15:16:22 UTC
The sequence of computation you're seeing shouldn't be possible -- the last iteration of the loop shouldn't be happening, but is happening for some reason unexplained by the values being printed.  Can you provide your config and gcc version?  Are you using any additional compiler flags we should be aware of?  If possible, could you also provide me with the decompress_bunzip2.o file from your built kernel source?

Thanks,
-Brad
Comment 10 Martin Filo 2015-11-29 16:16:45 UTC
gcc --version
gcc (Gentoo Hardened 4.9.3 p1.2, pie-0.6.3) 4.9.3

use flags:
 Installed versions:  4.9.3(4.9)^s(17:32:08 02.10.2015)(cxx hardened nls nptl op
enmp -altivec -awt -cilk -debug -doc -fixed-point -fortran -gcj -go -graphite -l
ibssp -multilib -multislot -nopie -nossp -objc -objc++ -objc-gc -regression-test
 -sanitize -vanilla)

From make.conf:
CFLAGS="${CFLAGS} -march=bdver2 -mtune=bdver2 -mfpmath=sse -O2 -pipe"
LDFLAGS="${LDFLAGS} -Wl,--hash-style=gnu"
CXXFLAGS="${CFLAGS}"

.config and decompress_bunzip2.o are in attachment
Comment 11 Martin Filo 2015-11-29 16:17:44 UTC
Created attachment 418148 [details]
.config
Comment 12 Martin Filo 2015-11-29 16:18:31 UTC
Created attachment 418150 [details]
decompress_bunzip.o
Comment 13 Emese Revfy 2015-11-29 22:10:36 UTC
Could you please send me the results (lib/decompress_bunzip2.*) of make lib/decompress_bunzip2.o EXTRA_CFLAGS="-fdump-tree-all -fdump-ipa-all", make lib/decompress_bunzip2.s and your vmlinux, bzImage?
Comment 14 Martin Filo 2015-11-30 18:16:29 UTC
Created attachment 418234 [details]
result of EXTRA_CFLAGS="-fdump-tree-all -fdumo-ipa-all" make lib/decompress_bunzip2.o
Comment 15 Martin Filo 2015-11-30 18:17:42 UTC
Created attachment 418236 [details]
decompress_bunzip2.s
Comment 16 Martin Filo 2015-11-30 18:23:05 UTC
Result of
EXTRA_CFLAGS="-fdump-tree-all -fdumo-ipa-all" make lib/decompress_bunzip2.o
EXTRA_CFLAGS="-fdump-tree-all -fdumo-ipa-all" make lib/decompress_bunzip2.s
are in attachment.
How can I send bzImage vmlinux to you?
Will be useful try boot this kernel?
Buggy kernel has been compiled by make -j8 bzImage modules.
Comment 17 Emese Revfy 2015-11-30 23:59:38 UTC
I need all gcc dump files (lib/decompress_bunzip2.*). Could you please run this command (use EXTRA_CFLAGS after make) and send me the files? :):
make lib/decompress_bunzip2.o EXTRA_CFLAGS="-fdump-tree-all -fdump-ipa-all"
Comment 18 Emese Revfy 2015-12-01 00:06:28 UTC
(In reply to Martin Filo from comment #16)
> How can I send bzImage vmlinux to you?
> Will be useful try boot this kernel?
> Buggy kernel has been compiled by make -j8 bzImage modules.

Yes, I'd boot your kernel (bzImage) and debug vmlinux with gdb.
Please enable these options as well:
CONFIG_DEBUG_INFO
CONFIG_FRAME_POINTER
Comment 19 Martin Filo 2015-12-01 18:12:18 UTC
After make clean, I added CONFIG_DEBUG_INFO CONFIG_FRAME_POINTER, compiled this with make bzImage modules modules_install. I tested that it crashes the same way.
I ran make lib/decompress_bunzip2.o EXTRA_CFLAGS="-fdump-tree-all -fdump-ipa-all"
I will send decompress_bunzip2.*, bzImage and vmlinux to you via email because they are too large to add them here.
Comment 20 Emese Revfy 2015-12-02 19:19:02 UTC
I can't boot your image, some kernel config options are missing. Could you please enable these options too:
CONFIG_VIRTIO_BLK=y
CONFIG_SCSI_VIRTIO=y
CONFIG_HW_RANDOM_VIRTIO=y
CONFIG_VIRTIO=y
CONFIG_VIRTIO_PCI=y
CONFIG_VIRTIO_PCI_LEGACY=y
CONFIG_VIRTIO_BALLOON=y
CONFIG_VIRTIO_INPUT=y
CONFIG_VIRTIO_MMIO=y
CONFIG_VIRTIO_MMIO_CMDLINE_DEVICES=y
and send me the previous files (include your initramfs).
Comment 21 Martin Filo 2015-12-03 06:50:08 UTC
I enabled options, which you mentioned. I reproduced crash with this kernel and this test initram in qemu.
Files are there: http://uloz.to/xVk9MhJt/debug-tar-xz-gpg
deletion link: http://uloz.to/smazat/xVk9MhJt/4123002014808367616
Password the same as previously.
Comment 22 Emese Revfy 2015-12-19 12:56:43 UTC
(In reply to Martin Filo from comment #0)
> This bug is new in 4.2.6-r6.
> 
> PAX: size overflow detected in function get_bits
> lib/decompress_bunzip2.c:143 cicus.147_113 max, count: 19, decl: inbufBits;
> num: 0; cont

Did you reproduce it with grsec version 4.3.3?
Comment 23 Martin Filo 2015-12-22 16:22:14 UTC
Yes, I tried 4.3.3-r1 with same result.
Comment 24 Anthony Basile gentoo-dev 2015-12-23 08:22:00 UTC
(In reply to Martin Filo from comment #23)
> Yes, I tried 4.3.3-r1 with same result.

I just added 4.3.3-r2 to the tree.  I'm punting -r1.
Comment 25 Martin Filo 2015-12-29 13:49:32 UTC
Version 4.3.3-r2 is affected too.
Comment 26 Anthony Basile gentoo-dev 2016-01-07 14:14:01 UTC
(In reply to Martin Filo from comment #25)
> Version 4.3.3-r2 is affected too.

can you check 4.3.3-r4 please.  its our next stabilization candidate.
Comment 27 Martin Filo 2016-01-10 13:39:22 UTC
Kernel bunzip2 still crashing, but xz work fine. I'm using xz instead of bz2. I have nothing against stabilization of 4.3.3-r4.
Comment 28 Emese Revfy 2016-01-12 23:23:50 UTC
(In reply to Martin Filo from comment #27)
> Kernel bunzip2 still crashing, but xz work fine. I'm using xz instead of
> bz2. I have nothing against stabilization of 4.3.3-r4.

Thanks for the report, it will be fixed in the next grsec patch.
Comment 29 Anthony Basile gentoo-dev 2016-07-21 16:54:45 UTC
(In reply to Emese Revfy from comment #28)
> (In reply to Martin Filo from comment #27)
> > Kernel bunzip2 still crashing, but xz work fine. I'm using xz instead of
> > bz2. I have nothing against stabilization of 4.3.3-r4.
> 
> Thanks for the report, it will be fixed in the next grsec patch.

Okay this has been fixed for a while.