Skip to content

Commit

Permalink
ASoC: SOF: ipc3-dtrace: uninitialized data in dfsentry_trace_filter_w…
Browse files Browse the repository at this point in the history
…rite()

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>
  • Loading branch information
Dan Carpenter authored and broonie committed Jul 17, 2023
1 parent e51df4f commit 469e2f2
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions sound/soc/sof/ipc3-dtrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ static ssize_t dfsentry_trace_filter_write(struct file *file, const char __user
struct snd_sof_dfsentry *dfse = file->private_data;
struct sof_ipc_trace_filter_elem *elems = NULL;
struct snd_sof_dev *sdev = dfse->sdev;
loff_t pos = 0;
int num_elems;
char *string;
int ret;
Expand All @@ -201,11 +200,11 @@ static ssize_t dfsentry_trace_filter_write(struct file *file, const char __user
if (!string)
return -ENOMEM;

/* assert null termination */
string[count] = 0;
ret = simple_write_to_buffer(string, count, &pos, from, count);
if (ret < 0)
if (copy_from_user(string, from, count)) {
ret = -EFAULT;
goto error;
}
string[count] = '\0';

ret = trace_filter_parse(sdev, string, &num_elems, &elems);
if (ret < 0)
Expand Down

0 comments on commit 469e2f2

Please sign in to comment.