]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/5.0.19/stm-class-fix-channel-bitmap-on-32-bit-systems.patch
4.9-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 5.0.19 / stm-class-fix-channel-bitmap-on-32-bit-systems.patch
1 From 51e0f227812ed81a368de54157ebe14396b4be03 Mon Sep 17 00:00:00 2001
2 From: Alexander Shishkin <alexander.shishkin@linux.intel.com>
3 Date: Wed, 17 Apr 2019 10:35:35 +0300
4 Subject: stm class: Fix channel bitmap on 32-bit systems
5
6 From: Alexander Shishkin <alexander.shishkin@linux.intel.com>
7
8 commit 51e0f227812ed81a368de54157ebe14396b4be03 upstream.
9
10 Commit 7bd1d4093c2f ("stm class: Introduce an abstraction for System Trace
11 Module devices") naively calculates the channel bitmap size in 64-bit
12 chunks regardless of the size of underlying unsigned long, making the
13 bitmap half as big on a 32-bit system. This leads to an out of bounds
14 access with the upper half of the bitmap.
15
16 Fix this by using BITS_TO_LONGS. While at it, convert to using
17 struct_size() for the total size calculation of the master struct.
18
19 Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
20 Fixes: 7bd1d4093c2f ("stm class: Introduce an abstraction for System Trace Module devices")
21 Reported-by: Mulu He <muluhe@codeaurora.org>
22 Cc: stable@vger.kernel.org # v4.4+
23 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
24
25 ---
26 drivers/hwtracing/stm/core.c | 7 +++----
27 1 file changed, 3 insertions(+), 4 deletions(-)
28
29 --- a/drivers/hwtracing/stm/core.c
30 +++ b/drivers/hwtracing/stm/core.c
31 @@ -166,11 +166,10 @@ stm_master(struct stm_device *stm, unsig
32 static int stp_master_alloc(struct stm_device *stm, unsigned int idx)
33 {
34 struct stp_master *master;
35 - size_t size;
36
37 - size = ALIGN(stm->data->sw_nchannels, 8) / 8;
38 - size += sizeof(struct stp_master);
39 - master = kzalloc(size, GFP_ATOMIC);
40 + master = kzalloc(struct_size(master, chan_map,
41 + BITS_TO_LONGS(stm->data->sw_nchannels)),
42 + GFP_ATOMIC);
43 if (!master)
44 return -ENOMEM;
45