badblocks: fix infinite loop due to incorrect rounding and overflow#774
badblocks: fix infinite loop due to incorrect rounding and overflow#774blktests-ci[bot] wants to merge 1 commit into
Conversation
|
Upstream branch: dd6c438 |
857ada9 to
482ce5b
Compare
|
Upstream branch: dca922e |
7ac44d2 to
6a567cb
Compare
482ce5b to
5a9f7c7
Compare
|
Upstream branch: e75a43c |
6a567cb to
5b169a8
Compare
5a9f7c7 to
25a041f
Compare
|
Upstream branch: 66edb90 |
5b169a8 to
ca2611b
Compare
25a041f to
6f75bd1
Compare
|
Upstream branch: 6d35786 |
ca2611b to
8ad5528
Compare
6f75bd1 to
1f0d33a
Compare
|
Upstream branch: 6d35786 |
8ad5528 to
e16a4aa
Compare
1f0d33a to
b1870f6
Compare
|
Upstream branch: aa54b1d |
e16a4aa to
8e11fa9
Compare
b1870f6 to
ca57796
Compare
|
Upstream branch: 70eda68 |
8e11fa9 to
20e0908
Compare
ca57796 to
c1feb59
Compare
|
Upstream branch: 8bc67e4 |
20e0908 to
4016081
Compare
c1feb59 to
ea833a1
Compare
|
Upstream branch: 6779b50 |
4016081 to
7741e24
Compare
ea833a1 to
7af85d1
Compare
|
Upstream branch: 79bd2dd |
The roundup() and rounddown() macros return the rounded value but do not modify the input in place. In _badblocks_set(), _badblocks_clear(), and badblocks_check(), the return values were being discarded, causing s and target/next to remain unrounded. This resulted in sectors being calculated from unrounded values, which could lead to sectors being way too large (or zero), causing infinite loops in the re_insert/re_clear/re_check loops. Additionally, add integer overflow checks (s > ULLONG_MAX - sectors) before the s + sectors calculation in all three functions to prevent overflow-related issues. Also add early return when sectors becomes zero after rounding in badblocks_check(). Root cause: When s and sectors have specific values (e.g., from syzkaller fuzzing via nvdimm ioctl), the unrounded values cause sectors to be incorrectly calculated. In _badblocks_clear(), this could result in needing 2^46 iterations to process 2^55 sectors, triggering RCU stall warnings and effectively hanging the kernel. Fix by properly capturing the return values from roundup() and rounddown(), adding overflow checks before sector arithmetic, and handling the zero-sectors case in badblocks_check(). Signed-off-by: Ramesh Adhikari <adhikari.resume@gmail.com>
7741e24 to
cb2ab88
Compare
Pull request for series with
subject: badblocks: fix infinite loop due to incorrect rounding and overflow
version: 1
url: https://patchwork.kernel.org/project/linux-block/list/?series=1086213