Skip to content

Commit 549cd0b

Browse files
tiwaibroonie
authored andcommitted
ASoC: intel: skl: Fix possible buffer overflow in debug outputs
The debugfs output of intel skl driver writes strings with multiple snprintf() calls with the fixed size. This was supposed to avoid the buffer overflow but actually it still would, because snprintf() returns the expected size to be output, not the actual output size. Fix it by replacing snprintf() calls with scnprintf(). Fixes: d14700a ("ASoC: Intel: Skylake: Debugfs facility to dump module config") Signed-off-by: Takashi Iwai <[email protected]> Acked-by: Cezary Rojewski <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 64bbacc commit 549cd0b

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

sound/soc/intel/skylake/skl-debug.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ static ssize_t skl_print_pins(struct skl_module_pin *m_pin, char *buf,
3535
ssize_t ret = 0;
3636

3737
for (i = 0; i < max_pin; i++) {
38-
ret += snprintf(buf + size, MOD_BUF - size,
38+
ret += scnprintf(buf + size, MOD_BUF - size,
3939
"%s %d\n\tModule %d\n\tInstance %d\n\t"
4040
"In-used %s\n\tType %s\n"
4141
"\tState %d\n\tIndex %d\n",
@@ -53,7 +53,7 @@ static ssize_t skl_print_pins(struct skl_module_pin *m_pin, char *buf,
5353
static ssize_t skl_print_fmt(struct skl_module_fmt *fmt, char *buf,
5454
ssize_t size, bool direction)
5555
{
56-
return snprintf(buf + size, MOD_BUF - size,
56+
return scnprintf(buf + size, MOD_BUF - size,
5757
"%s\n\tCh %d\n\tFreq %d\n\tBit depth %d\n\t"
5858
"Valid bit depth %d\n\tCh config %#x\n\tInterleaving %d\n\t"
5959
"Sample Type %d\n\tCh Map %#x\n",
@@ -77,16 +77,16 @@ static ssize_t module_read(struct file *file, char __user *user_buf,
7777
if (!buf)
7878
return -ENOMEM;
7979

80-
ret = snprintf(buf, MOD_BUF, "Module:\n\tUUID %pUL\n\tModule id %d\n"
80+
ret = scnprintf(buf, MOD_BUF, "Module:\n\tUUID %pUL\n\tModule id %d\n"
8181
"\tInstance id %d\n\tPvt_id %d\n", mconfig->guid,
8282
mconfig->id.module_id, mconfig->id.instance_id,
8383
mconfig->id.pvt_id);
8484

85-
ret += snprintf(buf + ret, MOD_BUF - ret,
85+
ret += scnprintf(buf + ret, MOD_BUF - ret,
8686
"Resources:\n\tCPC %#x\n\tIBS %#x\n\tOBS %#x\t\n",
8787
res->cpc, res->ibs, res->obs);
8888

89-
ret += snprintf(buf + ret, MOD_BUF - ret,
89+
ret += scnprintf(buf + ret, MOD_BUF - ret,
9090
"Module data:\n\tCore %d\n\tIn queue %d\n\t"
9191
"Out queue %d\n\tType %s\n",
9292
mconfig->core_id, mconfig->max_in_queue,
@@ -96,38 +96,38 @@ static ssize_t module_read(struct file *file, char __user *user_buf,
9696
ret += skl_print_fmt(mconfig->in_fmt, buf, ret, true);
9797
ret += skl_print_fmt(mconfig->out_fmt, buf, ret, false);
9898

99-
ret += snprintf(buf + ret, MOD_BUF - ret,
99+
ret += scnprintf(buf + ret, MOD_BUF - ret,
100100
"Fixup:\n\tParams %#x\n\tConverter %#x\n",
101101
mconfig->params_fixup, mconfig->converter);
102102

103-
ret += snprintf(buf + ret, MOD_BUF - ret,
103+
ret += scnprintf(buf + ret, MOD_BUF - ret,
104104
"Module Gateway:\n\tType %#x\n\tVbus %#x\n\tHW conn %#x\n\tSlot %#x\n",
105105
mconfig->dev_type, mconfig->vbus_id,
106106
mconfig->hw_conn_type, mconfig->time_slot);
107107

108-
ret += snprintf(buf + ret, MOD_BUF - ret,
108+
ret += scnprintf(buf + ret, MOD_BUF - ret,
109109
"Pipeline:\n\tID %d\n\tPriority %d\n\tConn Type %d\n\t"
110110
"Pages %#x\n", mconfig->pipe->ppl_id,
111111
mconfig->pipe->pipe_priority, mconfig->pipe->conn_type,
112112
mconfig->pipe->memory_pages);
113113

114-
ret += snprintf(buf + ret, MOD_BUF - ret,
114+
ret += scnprintf(buf + ret, MOD_BUF - ret,
115115
"\tParams:\n\t\tHost DMA %d\n\t\tLink DMA %d\n",
116116
mconfig->pipe->p_params->host_dma_id,
117117
mconfig->pipe->p_params->link_dma_id);
118118

119-
ret += snprintf(buf + ret, MOD_BUF - ret,
119+
ret += scnprintf(buf + ret, MOD_BUF - ret,
120120
"\tPCM params:\n\t\tCh %d\n\t\tFreq %d\n\t\tFormat %d\n",
121121
mconfig->pipe->p_params->ch,
122122
mconfig->pipe->p_params->s_freq,
123123
mconfig->pipe->p_params->s_fmt);
124124

125-
ret += snprintf(buf + ret, MOD_BUF - ret,
125+
ret += scnprintf(buf + ret, MOD_BUF - ret,
126126
"\tLink %#x\n\tStream %#x\n",
127127
mconfig->pipe->p_params->linktype,
128128
mconfig->pipe->p_params->stream);
129129

130-
ret += snprintf(buf + ret, MOD_BUF - ret,
130+
ret += scnprintf(buf + ret, MOD_BUF - ret,
131131
"\tState %d\n\tPassthru %s\n",
132132
mconfig->pipe->state,
133133
mconfig->pipe->passthru ? "true" : "false");
@@ -137,7 +137,7 @@ static ssize_t module_read(struct file *file, char __user *user_buf,
137137
ret += skl_print_pins(mconfig->m_out_pin, buf,
138138
mconfig->max_out_queue, ret, false);
139139

140-
ret += snprintf(buf + ret, MOD_BUF - ret,
140+
ret += scnprintf(buf + ret, MOD_BUF - ret,
141141
"Other:\n\tDomain %d\n\tHomogeneous Input %s\n\t"
142142
"Homogeneous Output %s\n\tIn Queue Mask %d\n\t"
143143
"Out Queue Mask %d\n\tDMA ID %d\n\tMem Pages %d\n\t"
@@ -193,7 +193,7 @@ static ssize_t fw_softreg_read(struct file *file, char __user *user_buf,
193193
__ioread32_copy(d->fw_read_buff, fw_reg_addr, w0_stat_sz >> 2);
194194

195195
for (offset = 0; offset < FW_REG_SIZE; offset += 16) {
196-
ret += snprintf(tmp + ret, FW_REG_BUF - ret, "%#.4x: ", offset);
196+
ret += scnprintf(tmp + ret, FW_REG_BUF - ret, "%#.4x: ", offset);
197197
hex_dump_to_buffer(d->fw_read_buff + offset, 16, 16, 4,
198198
tmp + ret, FW_REG_BUF - ret, 0);
199199
ret += strlen(tmp + ret);

0 commit comments

Comments
 (0)