]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.19.27/asoc-dapm-change-snprintf-to-scnprintf-for-possible-.patch
Linux 4.14.105
[thirdparty/kernel/stable-queue.git] / releases / 4.19.27 / asoc-dapm-change-snprintf-to-scnprintf-for-possible-.patch
1 From f3beb7b50f5a00fd391c2346b70a63d450156306 Mon Sep 17 00:00:00 2001
2 From: Silvio Cesare <silvio.cesare@gmail.com>
3 Date: Sat, 12 Jan 2019 16:28:43 +0100
4 Subject: ASoC: dapm: change snprintf to scnprintf for possible overflow
5
6 [ Upstream commit e581e151e965bf1f2815dd94620b638fec4d0a7e ]
7
8 Change snprintf to scnprintf. There are generally two cases where using
9 snprintf causes problems.
10
11 1) Uses of size += snprintf(buf, SIZE - size, fmt, ...)
12 In this case, if snprintf would have written more characters than what the
13 buffer size (SIZE) is, then size will end up larger than SIZE. In later
14 uses of snprintf, SIZE - size will result in a negative number, leading
15 to problems. Note that size might already be too large by using
16 size = snprintf before the code reaches a case of size += snprintf.
17
18 2) If size is ultimately used as a length parameter for a copy back to user
19 space, then it will potentially allow for a buffer overflow and information
20 disclosure when size is greater than SIZE. When the size is used to index
21 the buffer directly, we can have memory corruption. This also means when
22 size = snprintf... is used, it may also cause problems since size may become
23 large. Copying to userspace is mitigated by the HARDENED_USERCOPY kernel
24 configuration.
25
26 The solution to these issues is to use scnprintf which returns the number of
27 characters actually written to the buffer, so the size variable will never
28 exceed SIZE.
29
30 Signed-off-by: Silvio Cesare <silvio.cesare@gmail.com>
31 Cc: Liam Girdwood <lgirdwood@gmail.com>
32 Cc: Mark Brown <broonie@kernel.org>
33 Cc: Dan Carpenter <dan.carpenter@oracle.com>
34 Cc: Kees Cook <keescook@chromium.org>
35 Cc: Will Deacon <will.deacon@arm.com>
36 Cc: Greg KH <greg@kroah.com>
37 Signed-off-by: Willy Tarreau <w@1wt.eu>
38 Signed-off-by: Mark Brown <broonie@kernel.org>
39 Signed-off-by: Sasha Levin <sashal@kernel.org>
40 ---
41 sound/soc/soc-dapm.c | 10 +++++-----
42 1 file changed, 5 insertions(+), 5 deletions(-)
43
44 diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c
45 index 461d951917c05..6537069452226 100644
46 --- a/sound/soc/soc-dapm.c
47 +++ b/sound/soc/soc-dapm.c
48 @@ -2028,19 +2028,19 @@ static ssize_t dapm_widget_power_read_file(struct file *file,
49 out = is_connected_output_ep(w, NULL, NULL);
50 }
51
52 - ret = snprintf(buf, PAGE_SIZE, "%s: %s%s in %d out %d",
53 + ret = scnprintf(buf, PAGE_SIZE, "%s: %s%s in %d out %d",
54 w->name, w->power ? "On" : "Off",
55 w->force ? " (forced)" : "", in, out);
56
57 if (w->reg >= 0)
58 - ret += snprintf(buf + ret, PAGE_SIZE - ret,
59 + ret += scnprintf(buf + ret, PAGE_SIZE - ret,
60 " - R%d(0x%x) mask 0x%x",
61 w->reg, w->reg, w->mask << w->shift);
62
63 - ret += snprintf(buf + ret, PAGE_SIZE - ret, "\n");
64 + ret += scnprintf(buf + ret, PAGE_SIZE - ret, "\n");
65
66 if (w->sname)
67 - ret += snprintf(buf + ret, PAGE_SIZE - ret, " stream %s %s\n",
68 + ret += scnprintf(buf + ret, PAGE_SIZE - ret, " stream %s %s\n",
69 w->sname,
70 w->active ? "active" : "inactive");
71
72 @@ -2053,7 +2053,7 @@ static ssize_t dapm_widget_power_read_file(struct file *file,
73 if (!p->connect)
74 continue;
75
76 - ret += snprintf(buf + ret, PAGE_SIZE - ret,
77 + ret += scnprintf(buf + ret, PAGE_SIZE - ret,
78 " %s \"%s\" \"%s\"\n",
79 (rdir == SND_SOC_DAPM_DIR_IN) ? "in" : "out",
80 p->name ? p->name : "static",
81 --
82 2.19.1
83