Skip to content

Commit 8049387

Browse files
Tetsuo Handatorvalds
authored andcommitted
Revert "cpumask: fix checking valid cpu range".
This reverts commit 78e5a33 ("cpumask: fix checking valid cpu range"). syzbot is hitting WARN_ON_ONCE(cpu >= nr_cpumask_bits) warning at cpu_max_bits_warn() [1], for commit 78e5a33 ("cpumask: fix checking valid cpu range") is broken. Obviously that patch hits WARN_ON_ONCE() when e.g. reading /proc/cpuinfo because passing "cpu + 1" instead of "cpu" will trivially hit cpu == nr_cpumask_bits condition. Although syzbot found this problem in linux-next.git on 2022/09/27 [2], this problem was not fixed immediately. As a result, that patch was sent to linux.git before the patch author recognizes this problem, and syzbot started failing to test changes in linux.git since 2022/10/10 [3]. Andrew Jones proposed a fix for x86 and riscv architectures [4]. But [2] and [5] indicate that affected locations are not limited to arch code. More delay before we find and fix affected locations, less tested kernel (and more difficult to bisect and fix) before release. We should have inspected and fixed basically all cpumask users before applying that patch. We should not crash kernels in order to ask existing cpumask users to update their code, even if limited to CONFIG_DEBUG_PER_CPU_MAPS=y case. Link: https://syzkaller.appspot.com/bug?extid=d0fd2bf0dd6da72496dd [1] Link: https://syzkaller.appspot.com/bug?extid=21da700f3c9f0bc40150 [2] Link: https://syzkaller.appspot.com/bug?extid=51a652e2d24d53e75734 [3] Link: https://lkml.kernel.org/r/[email protected] [4] Link: https://syzkaller.appspot.com/bug?extid=4d46c43d81c3bd155060 [5] Reported-by: Andrew Jones <[email protected]> Reported-by: [email protected] Signed-off-by: Tetsuo Handa <[email protected]> Cc: Yury Norov <[email protected]> Cc: Borislav Petkov <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 1501278 commit 8049387

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

include/linux/cpumask.h

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,9 @@ static inline unsigned int cpumask_last(const struct cpumask *srcp)
174174
static inline
175175
unsigned int cpumask_next(int n, const struct cpumask *srcp)
176176
{
177-
/* n is a prior cpu */
178-
cpumask_check(n + 1);
177+
/* -1 is a legal arg here. */
178+
if (n != -1)
179+
cpumask_check(n);
179180
return find_next_bit(cpumask_bits(srcp), nr_cpumask_bits, n + 1);
180181
}
181182

@@ -188,8 +189,9 @@ unsigned int cpumask_next(int n, const struct cpumask *srcp)
188189
*/
189190
static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
190191
{
191-
/* n is a prior cpu */
192-
cpumask_check(n + 1);
192+
/* -1 is a legal arg here. */
193+
if (n != -1)
194+
cpumask_check(n);
193195
return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
194196
}
195197

@@ -229,8 +231,9 @@ static inline
229231
unsigned int cpumask_next_and(int n, const struct cpumask *src1p,
230232
const struct cpumask *src2p)
231233
{
232-
/* n is a prior cpu */
233-
cpumask_check(n + 1);
234+
/* -1 is a legal arg here. */
235+
if (n != -1)
236+
cpumask_check(n);
234237
return find_next_and_bit(cpumask_bits(src1p), cpumask_bits(src2p),
235238
nr_cpumask_bits, n + 1);
236239
}
@@ -260,8 +263,8 @@ static inline
260263
unsigned int cpumask_next_wrap(int n, const struct cpumask *mask, int start, bool wrap)
261264
{
262265
cpumask_check(start);
263-
/* n is a prior cpu */
264-
cpumask_check(n + 1);
266+
if (n != -1)
267+
cpumask_check(n);
265268

266269
/*
267270
* Return the first available CPU when wrapping, or when starting before cpu0,

0 commit comments

Comments
 (0)