]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-ci.git/commit
osd: fix UBSan shift overflow in pg_pool_t::calc_pg_masks
authorAlexander Indenbaum <aindenba@redhat.com>
Sun, 22 Feb 2026 12:54:59 +0000 (14:54 +0200)
committerAlexander Indenbaum <aindenba@redhat.com>
Mon, 23 Feb 2026 11:20:24 +0000 (13:20 +0200)
commitde56a05750107464b861dc0f9e0986121a98ccf7
tree613c680b1f958bdd940b72ccb96bec2b312ed881
parent34039ef016d9fa884a494ada3170c8b07fd31ff8
osd: fix UBSan shift overflow in pg_pool_t::calc_pg_masks

UBSan reports: shift exponent 32 is too large for 32-bit type 'int'

When pg_num or pgp_num is 0, pg_num-1 wraps to UINT_MAX (unsigned),
cbits() returns 32, and (1 << 32) on 32-bit int is undefined behavior

Use 1ULL for the shift and guard when cbits >= sizeof(unsigned)*CHAR_BIT
to avoid UB

- add unittest-crimson-pg-pool-shift to exercise the fix

Signed-off-by: Alexander Indenbaum <aindenba@redhat.com>
src/osd/osd_types.cc
src/test/crimson/CMakeLists.txt
src/test/crimson/test_pg_pool_shift.cc [new file with mode: 0644]