1 From foo@baz Tue Nov 28 10:58:31 CET 2017
2 From: Richard Fitzgerald <rf@opensource.wolfsonmicro.com>
3 Date: Tue, 20 Dec 2016 10:29:12 +0000
4 Subject: ASoC: wm_adsp: Don't overrun firmware file buffer when reading region data
6 From: Richard Fitzgerald <rf@opensource.wolfsonmicro.com>
9 [ Upstream commit 1cab2a84f470e15ecc8e5143bfe9398c6e888032 ]
11 Protect against corrupt firmware files by ensuring that the length we
12 get for the data in a region actually lies within the available firmware
15 Signed-off-by: Richard Fitzgerald <rf@opensource.wolfsonmicro.com>
16 Signed-off-by: Mark Brown <broonie@kernel.org>
17 Signed-off-by: Sasha Levin <alexander.levin@verizon.com>
18 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
20 sound/soc/codecs/wm_adsp.c | 25 ++++++++++++++++++++++++-
21 1 file changed, 24 insertions(+), 1 deletion(-)
23 --- a/sound/soc/codecs/wm_adsp.c
24 +++ b/sound/soc/codecs/wm_adsp.c
25 @@ -532,7 +532,7 @@ static int wm_adsp_load(struct wm_adsp *
26 const struct wmfw_region *region;
27 const struct wm_adsp_region *mem;
28 const char *region_name;
30 + char *file, *text = NULL;
31 struct wm_adsp_buf *buf;
34 @@ -677,10 +677,21 @@ static int wm_adsp_load(struct wm_adsp *
35 regions, le32_to_cpu(region->len), offset,
38 + if ((pos + le32_to_cpu(region->len) + sizeof(*region)) >
41 + "%s.%d: %s region len %d bytes exceeds file length %zu\n",
42 + file, regions, region_name,
43 + le32_to_cpu(region->len), firmware->size);
49 memcpy(text, region->data, le32_to_cpu(region->len));
50 adsp_info(dsp, "%s: %s\n", file, text);
56 @@ -737,6 +748,7 @@ out_fw:
57 regmap_async_complete(regmap);
58 wm_adsp_buf_free(&buf_list);
59 release_firmware(firmware);
64 @@ -1316,6 +1328,17 @@ static int wm_adsp_load_coeff(struct wm_
68 + if ((pos + le32_to_cpu(blk->len) + sizeof(*blk)) >
71 + "%s.%d: %s region len %d bytes exceeds file length %zu\n",
72 + file, blocks, region_name,
73 + le32_to_cpu(blk->len),
79 buf = wm_adsp_buf_alloc(blk->data,
80 le32_to_cpu(blk->len),