]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-4.19/percpu-do-not-search-past-bitmap-when-allocating-an-.patch
1ce90b41896a2d10c94a9919712581b494b22c55
[thirdparty/kernel/stable-queue.git] / queue-4.19 / percpu-do-not-search-past-bitmap-when-allocating-an-.patch
1 From 98506788746933b7d1212684fc42e9798651d943 Mon Sep 17 00:00:00 2001
2 From: Dennis Zhou <dennis@kernel.org>
3 Date: Thu, 21 Feb 2019 15:54:11 -0800
4 Subject: percpu: do not search past bitmap when allocating an area
5
6 [ Upstream commit 8c43004af01635cc9fbb11031d070e5e0d327ef2 ]
7
8 pcpu_find_block_fit() guarantees that a fit is found within
9 PCPU_BITMAP_BLOCK_BITS. Iteration is used to determine the first fit as
10 it compares against the block's contig_hint. This can lead to
11 incorrectly scanning past the end of the bitmap. The behavior was okay
12 given the check after for bit_off >= end and the correctness of the
13 hints from pcpu_find_block_fit().
14
15 This patch fixes this by bounding the end offset by the number of bits
16 in a chunk.
17
18 Signed-off-by: Dennis Zhou <dennis@kernel.org>
19 Reviewed-by: Peng Fan <peng.fan@nxp.com>
20 Signed-off-by: Sasha Levin <sashal@kernel.org>
21 ---
22 mm/percpu.c | 3 ++-
23 1 file changed, 2 insertions(+), 1 deletion(-)
24
25 diff --git a/mm/percpu.c b/mm/percpu.c
26 index c66149ce1fe6..ff76fa0b7528 100644
27 --- a/mm/percpu.c
28 +++ b/mm/percpu.c
29 @@ -988,7 +988,8 @@ static int pcpu_alloc_area(struct pcpu_chunk *chunk, int alloc_bits,
30 /*
31 * Search to find a fit.
32 */
33 - end = start + alloc_bits + PCPU_BITMAP_BLOCK_BITS;
34 + end = min_t(int, start + alloc_bits + PCPU_BITMAP_BLOCK_BITS,
35 + pcpu_chunk_map_bits(chunk));
36 bit_off = bitmap_find_next_zero_area(chunk->alloc_map, end, start,
37 alloc_bits, align_mask);
38 if (bit_off >= end)
39 --
40 2.20.1
41