sbin/hammer: Don't access beyond 16KB of HAMMER userspace buffer
authorTomohiro Kusumi <kusumi.tomohiro@gmail.com>
Fri, 4 Mar 2016 16:08:46 +0000 (01:08 +0900)
committerTomohiro Kusumi <kusumi.tomohiro@gmail.com>
Sun, 20 Mar 2016 14:15:55 +0000 (23:15 +0900)
commitd30b24e65b830560fa2874bb2919caca2725abee
tree2ee7e4aeff436df53c066c1c505afb99a77d3533
parentc34b9df50c3d8107955d628046b82e924e54bac8
sbin/hammer: Don't access beyond 16KB of HAMMER userspace buffer

HAMMER userspace only supports upto 16KB buffer size while HAMMER
filesystem itself supports both 16KB and 64KB. This means even if
a leaf node elm says the record data is >16KB, HAMMER userspace can
only retrieve the first 16KB of the record data. Anything beyond
16KB is not supported (not malloc'd in userspace).

print_record() in hammer show is passing a pointer to maximum 16KB
buffer to hexdump(3), but is also passing data_len which is taken
from elm->leaf.data_len. This becomes an issue when the file size
is >1MB where HAMMER starts to use 64KB buffer for data beyond 1MB.
elm->leaf.data_len will typically say the length is 64KB, but
the maximum HAMMER userspace can handle is still 16KB regardless
of what the leaf node elm says. hammer show needs to omit anything
beyond 16KB (for now).

 # hammer -vvvv -f /dev/da1:/dev/da2:/dev/da3 show > /dev/null
 zsh: segmentation fault (core dumped)  hammer -vvvv -f /dev/da1:/dev/da2:/dev/da3 show > /dev/null

(cherry picked from commit 7d0dab482a8621fa2fcb8ae0d5f27e62aed4c9f4)
sbin/hammer/cmd_show.c