ASoC: SOF: ipc3-dtrace: uninitialized data in dfsentry_trace_filter_write()

[ Upstream commit 469e2f28c2cbee2430058c1c9bb6d1675d7195fb ]

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: 671e0b9005 ("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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
Dan Carpenter 2023-07-07 14:25:23 +03:00 committed by Greg Kroah-Hartman
parent c55901d381
commit 813572a08d

View File

@ -187,7 +187,6 @@ static ssize_t dfsentry_trace_filter_write(struct file *file, const char __user
struct snd_sof_dfsentry *dfse = file->private_data; struct snd_sof_dfsentry *dfse = file->private_data;
struct sof_ipc_trace_filter_elem *elems = NULL; struct sof_ipc_trace_filter_elem *elems = NULL;
struct snd_sof_dev *sdev = dfse->sdev; struct snd_sof_dev *sdev = dfse->sdev;
loff_t pos = 0;
int num_elems; int num_elems;
char *string; char *string;
int ret; int ret;
@ -202,11 +201,11 @@ static ssize_t dfsentry_trace_filter_write(struct file *file, const char __user
if (!string) if (!string)
return -ENOMEM; return -ENOMEM;
/* assert null termination */ if (copy_from_user(string, from, count)) {
string[count] = 0; ret = -EFAULT;
ret = simple_write_to_buffer(string, count, &pos, from, count);
if (ret < 0)
goto error; goto error;
}
string[count] = '\0';
ret = trace_filter_parse(sdev, string, &num_elems, &elems); ret = trace_filter_parse(sdev, string, &num_elems, &elems);
if (ret < 0) if (ret < 0)