Skip to content

Commit 469e2f2

Browse files
Dan Carpenterbroonie
authored andcommitted
ASoC: SOF: ipc3-dtrace: uninitialized data in dfsentry_trace_filter_write()
This doesn't check how many bytes the simple_write_to_buffer() writes to the buffer. The only thing that we know is that the first byte is initialized and the last byte of the buffer is set to NUL. However the middle bytes could be uninitialized. There is no need to use simple_write_to_buffer(). This code does not support partial writes but instead passes "pos = 0" as the starting offset regardless of what the user passed as "*ppos". Just use the copy_from_user() function and initialize the whole buffer. Fixes: 671e0b9 ("ASoC: SOF: Clone the trace code to ipc3-dtrace as fw_tracing implementation") Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org> Link: https://lore.kernel.org/r/74148292-ce4d-4e01-a1a7-921e6767da14@moroto.mountain Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent e51df4f commit 469e2f2

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

sound/soc/sof/ipc3-dtrace.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ static ssize_t dfsentry_trace_filter_write(struct file *file, const char __user
186186
struct snd_sof_dfsentry *dfse = file->private_data;
187187
struct sof_ipc_trace_filter_elem *elems = NULL;
188188
struct snd_sof_dev *sdev = dfse->sdev;
189-
loff_t pos = 0;
190189
int num_elems;
191190
char *string;
192191
int ret;
@@ -201,11 +200,11 @@ static ssize_t dfsentry_trace_filter_write(struct file *file, const char __user
201200
if (!string)
202201
return -ENOMEM;
203202

204-
/* assert null termination */
205-
string[count] = 0;
206-
ret = simple_write_to_buffer(string, count, &pos, from, count);
207-
if (ret < 0)
203+
if (copy_from_user(string, from, count)) {
204+
ret = -EFAULT;
208205
goto error;
206+
}
207+
string[count] = '\0';
209208

210209
ret = trace_filter_parse(sdev, string, &num_elems, &elems);
211210
if (ret < 0)

0 commit comments

Comments
 (0)