summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSilvio Cesare <silvio.cesare@gmail.com>2019-01-14 22:27:27 -0500
committerMark Brown <broonie@kernel.org>2019-01-15 14:06:08 -0500
commitc407cd008fd039320d147088b52d0fa34ed3ddcb (patch)
tree3a1d627df42547bfb0036911eccdd73514d73b66
parent060d0bf491874daece47053c4e1fb0489eb867d2 (diff)
ASoC: imx-audmux: change snprintf to scnprintf for possible overflow
Change snprintf to scnprintf. There are generally two cases where using snprintf causes problems. 1) Uses of size += snprintf(buf, SIZE - size, fmt, ...) In this case, if snprintf would have written more characters than what the buffer size (SIZE) is, then size will end up larger than SIZE. In later uses of snprintf, SIZE - size will result in a negative number, leading to problems. Note that size might already be too large by using size = snprintf before the code reaches a case of size += snprintf. 2) If size is ultimately used as a length parameter for a copy back to user space, then it will potentially allow for a buffer overflow and information disclosure when size is greater than SIZE. When the size is used to index the buffer directly, we can have memory corruption. This also means when size = snprintf... is used, it may also cause problems since size may become large. Copying to userspace is mitigated by the HARDENED_USERCOPY kernel configuration. The solution to these issues is to use scnprintf which returns the number of characters actually written to the buffer, so the size variable will never exceed SIZE. Signed-off-by: Silvio Cesare <silvio.cesare@gmail.com> Cc: Timur Tabi <timur@kernel.org> Cc: Nicolin Chen <nicoleotsuka@gmail.com> Cc: Mark Brown <broonie@kernel.org> Cc: Xiubo Li <Xiubo.Lee@gmail.com> Cc: Fabio Estevam <fabio.estevam@nxp.com> Cc: Dan Carpenter <dan.carpenter@oracle.com> Cc: Kees Cook <keescook@chromium.org> Cc: Will Deacon <will.deacon@arm.com> Cc: Greg KH <greg@kroah.com> Signed-off-by: Willy Tarreau <w@1wt.eu> Acked-by: Nicolin Chen <nicoleotsuka@gmail.com> Reviewed-by: Kees Cook <keescook@chromium.org> Signed-off-by: Mark Brown <broonie@kernel.org>
-rw-r--r--sound/soc/fsl/imx-audmux.c24
1 files changed, 12 insertions, 12 deletions
diff --git a/sound/soc/fsl/imx-audmux.c b/sound/soc/fsl/imx-audmux.c
index 392d5eef356d..99e07b01a2ce 100644
--- a/sound/soc/fsl/imx-audmux.c
+++ b/sound/soc/fsl/imx-audmux.c
@@ -86,49 +86,49 @@ static ssize_t audmux_read_file(struct file *file, char __user *user_buf,
86 if (!buf) 86 if (!buf)
87 return -ENOMEM; 87 return -ENOMEM;
88 88
89 ret = snprintf(buf, PAGE_SIZE, "PDCR: %08x\nPTCR: %08x\n", 89 ret = scnprintf(buf, PAGE_SIZE, "PDCR: %08x\nPTCR: %08x\n",
90 pdcr, ptcr); 90 pdcr, ptcr);
91 91
92 if (ptcr & IMX_AUDMUX_V2_PTCR_TFSDIR) 92 if (ptcr & IMX_AUDMUX_V2_PTCR_TFSDIR)
93 ret += snprintf(buf + ret, PAGE_SIZE - ret, 93 ret += scnprintf(buf + ret, PAGE_SIZE - ret,
94 "TxFS output from %s, ", 94 "TxFS output from %s, ",
95 audmux_port_string((ptcr >> 27) & 0x7)); 95 audmux_port_string((ptcr >> 27) & 0x7));
96 else 96 else
97 ret += snprintf(buf + ret, PAGE_SIZE - ret, 97 ret += scnprintf(buf + ret, PAGE_SIZE - ret,
98 "TxFS input, "); 98 "TxFS input, ");
99 99
100 if (ptcr & IMX_AUDMUX_V2_PTCR_TCLKDIR) 100 if (ptcr & IMX_AUDMUX_V2_PTCR_TCLKDIR)
101 ret += snprintf(buf + ret, PAGE_SIZE - ret, 101 ret += scnprintf(buf + ret, PAGE_SIZE - ret,
102 "TxClk output from %s", 102 "TxClk output from %s",
103 audmux_port_string((ptcr >> 22) & 0x7)); 103 audmux_port_string((ptcr >> 22) & 0x7));
104 else 104 else
105 ret += snprintf(buf + ret, PAGE_SIZE - ret, 105 ret += scnprintf(buf + ret, PAGE_SIZE - ret,
106 "TxClk input"); 106 "TxClk input");
107 107
108 ret += snprintf(buf + ret, PAGE_SIZE - ret, "\n"); 108 ret += scnprintf(buf + ret, PAGE_SIZE - ret, "\n");
109 109
110 if (ptcr & IMX_AUDMUX_V2_PTCR_SYN) { 110 if (ptcr & IMX_AUDMUX_V2_PTCR_SYN) {
111 ret += snprintf(buf + ret, PAGE_SIZE - ret, 111 ret += scnprintf(buf + ret, PAGE_SIZE - ret,
112 "Port is symmetric"); 112 "Port is symmetric");
113 } else { 113 } else {
114 if (ptcr & IMX_AUDMUX_V2_PTCR_RFSDIR) 114 if (ptcr & IMX_AUDMUX_V2_PTCR_RFSDIR)
115 ret += snprintf(buf + ret, PAGE_SIZE - ret, 115 ret += scnprintf(buf + ret, PAGE_SIZE - ret,
116 "RxFS output from %s, ", 116 "RxFS output from %s, ",
117 audmux_port_string((ptcr >> 17) & 0x7)); 117 audmux_port_string((ptcr >> 17) & 0x7));
118 else 118 else
119 ret += snprintf(buf + ret, PAGE_SIZE - ret, 119 ret += scnprintf(buf + ret, PAGE_SIZE - ret,
120 "RxFS input, "); 120 "RxFS input, ");
121 121
122 if (ptcr & IMX_AUDMUX_V2_PTCR_RCLKDIR) 122 if (ptcr & IMX_AUDMUX_V2_PTCR_RCLKDIR)
123 ret += snprintf(buf + ret, PAGE_SIZE - ret, 123 ret += scnprintf(buf + ret, PAGE_SIZE - ret,
124 "RxClk output from %s", 124 "RxClk output from %s",
125 audmux_port_string((ptcr >> 12) & 0x7)); 125 audmux_port_string((ptcr >> 12) & 0x7));
126 else 126 else
127 ret += snprintf(buf + ret, PAGE_SIZE - ret, 127 ret += scnprintf(buf + ret, PAGE_SIZE - ret,
128 "RxClk input"); 128 "RxClk input");
129 } 129 }
130 130
131 ret += snprintf(buf + ret, PAGE_SIZE - ret, 131 ret += scnprintf(buf + ret, PAGE_SIZE - ret,
132 "\nData received from %s\n", 132 "\nData received from %s\n",
133 audmux_port_string((pdcr >> 13) & 0x7)); 133 audmux_port_string((pdcr >> 13) & 0x7));
134 134