Skip to content

Commit

Permalink
Fix ubsan: shift exponent is too large
Browse files Browse the repository at this point in the history
When running libzpool with the Undefined Behavior Sanitizer (ubsan)
enabled, a zpool create causes a run-time error:
    module/zfs/vdev_label.c:600:14: runtime error: shift exponent 64 is
    too large for 64-bit type 'long long unsigned int'`
in vdev_config_generate()

Fix is to convert vdev_removal_max_span to its base-2 logarithm, using
highbit64(), and then compare the "shifts".

Fixes #9744

Signed-off-by: Chuck Tuffli <[email protected]>
  • Loading branch information
ctuffli committed Oct 7, 2020
1 parent a76e4e6 commit 75a6156
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion module/zfs/vdev_label.c
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,8 @@ vdev_config_generate(spa_t *spa, vdev_t *vd, boolean_t getstats,
* as a single mapping.
*/
for (int i = 0; i < RANGE_TREE_HISTOGRAM_SIZE; i++) {
if (1ULL << (i + 1) < vdev_removal_max_span) {
if (i + 1 < highbit64(vdev_removal_max_span)
- 1) {
to_alloc +=
vd->vdev_mg->mg_histogram[i] <<
(i + 1);
Expand Down

0 comments on commit 75a6156

Please sign in to comment.