linux/include/asm-generic/bitops
Benjamin Marzinski 1c61b0a6e5 bitops: make the *_bit_le functions use unsigned long
The *_bit_le functions use a signed integer for the bit number.
However, the *_bit functions can use an unsigned long. This causes
problems if there is a large bitmap and a bit number > 0x80000000 is
passed in. Since that is a negative int, it will get sign extended to a
long when getting passed to the *_bit function, turning it into a huge
bit number. This usually ends up with the memory address wrapping around
and the function accessing memory before the start of the bitmap.

Avoid this by making the *_bit_le functions take an unsigned long.

This can be triggered by faking an almost 4TB dm-mirror device, which
uses bitmaps to track the mirror regions:

$ dmsetup create bigzero --table '0 8589934590 zero'
$ dmsetup create mymirror --table '0 8589934590 mirror core 2 2 nosync 2 /dev/mapper/bigzero 0 /dev/mapper/bigzero 0'

This will access memory before the start of the sync_bits bitmap, and
likely hit the guard page of the previously allocated clean_bits bitmap,
causing a kernel panic with the old code.

I looked and didn't see any crazy code using the signed int to
intentionally try and access bits before some address within the bitmap.

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
Signed-off-by: Yury Norov <ynorov@nvidia.com>
2026-07-22 15:38:37 -04:00
..
__bitrev.h bitops: Define generic___bitrev8/16/32 for reuse 2026-05-28 11:39:16 -04:00
__ffs.h bitops: Add __attribute_const__ to generic ffs()-family implementations 2025-09-08 14:58:50 -07:00
__fls.h bitops: Add __attribute_const__ to generic ffs()-family implementations 2025-09-08 14:58:50 -07:00
arch_hweight.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
atomic.h locking/atomic: treewide: use raw_atomic*_<op>() 2023-06-05 09:57:20 +02:00
builtin-__ffs.h bitops: Add __attribute_const__ to generic ffs()-family implementations 2025-09-08 14:58:50 -07:00
builtin-__fls.h bitops: Add __attribute_const__ to generic ffs()-family implementations 2025-09-08 14:58:50 -07:00
builtin-ffs.h asm-generic: ffs: Drop bogus reference to ffz location 2021-08-11 11:38:10 +02:00
builtin-fls.h bitops: Add __attribute_const__ to generic ffs()-family implementations 2025-09-08 14:58:50 -07:00
const_hweight.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
ext2-atomic-setbit.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
ext2-atomic.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
ffs.h bitops: Add __attribute_const__ to generic ffs()-family implementations 2025-09-08 14:58:50 -07:00
ffz.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
fls.h bitops: Add __attribute_const__ to generic ffs()-family implementations 2025-09-08 14:58:50 -07:00
fls64.h bitops: Add __attribute_const__ to generic ffs()-family implementations 2025-09-08 14:58:50 -07:00
generic-non-atomic.h wait_on_bit: add an acquire memory barrier 2022-08-26 09:30:25 -07:00
hweight.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
instrumented-atomic.h asm-generic/bitops: Fix a comment typo in instrumented-atomic.h 2026-03-23 13:33:51 -04:00
instrumented-lock.h mm: delete checks for xor_unlock_is_negative_byte() 2023-10-18 14:34:17 -07:00
instrumented-non-atomic.h wait_on_bit: add an acquire memory barrier 2022-08-26 09:30:25 -07:00
le.h bitops: make the *_bit_le functions use unsigned long 2026-07-22 15:38:37 -04:00
lock.h bitops: use common function parameter names 2026-05-20 11:18:27 -04:00
non-atomic.h wait_on_bit: add an acquire memory barrier 2022-08-26 09:30:25 -07:00
non-instrumented-non-atomic.h wait_on_bit: add an acquire memory barrier 2022-08-26 09:30:25 -07:00
sched.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00