]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - releases/4.19.51/percpu-do-not-search-past-bitmap-when-allocating-an-.patch
Linux 4.19.51
[thirdparty/kernel/stable-queue.git] / releases / 4.19.51 / percpu-do-not-search-past-bitmap-when-allocating-an-.patch
CommitLineData
37554d48
SL
1From 98506788746933b7d1212684fc42e9798651d943 Mon Sep 17 00:00:00 2001
2From: Dennis Zhou <dennis@kernel.org>
3Date: Thu, 21 Feb 2019 15:54:11 -0800
4Subject: percpu: do not search past bitmap when allocating an area
5
6[ Upstream commit 8c43004af01635cc9fbb11031d070e5e0d327ef2 ]
7
8pcpu_find_block_fit() guarantees that a fit is found within
9PCPU_BITMAP_BLOCK_BITS. Iteration is used to determine the first fit as
10it compares against the block's contig_hint. This can lead to
11incorrectly scanning past the end of the bitmap. The behavior was okay
12given the check after for bit_off >= end and the correctness of the
13hints from pcpu_find_block_fit().
14
15This patch fixes this by bounding the end offset by the number of bits
16in a chunk.
17
18Signed-off-by: Dennis Zhou <dennis@kernel.org>
19Reviewed-by: Peng Fan <peng.fan@nxp.com>
20Signed-off-by: Sasha Levin <sashal@kernel.org>
21---
22 mm/percpu.c | 3 ++-
23 1 file changed, 2 insertions(+), 1 deletion(-)
24
25diff --git a/mm/percpu.c b/mm/percpu.c
26index 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--
402.20.1
41