Skip to content

Commit 02ac3a9

Browse files
tiwaigregkh
authored andcommitted
parport: Proper fix for array out-of-bounds access
The recent fix for array out-of-bounds accesses replaced sprintf() calls blindly with snprintf(). However, since snprintf() returns the would-be-printed size, not the actually output size, the length calculation can still go over the given limit. Use scnprintf() instead of snprintf(), which returns the actually output letters, for addressing the potential out-of-bounds access properly. Fixes: ab11dac ("dev/parport: fix the array out-of-bounds risk") Cc: [email protected] Signed-off-by: Takashi Iwai <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 7528cb0 commit 02ac3a9

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

drivers/parport/procfs.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ static int do_active_device(const struct ctl_table *table, int write,
5151

5252
for (dev = port->devices; dev ; dev = dev->next) {
5353
if(dev == port->cad) {
54-
len += snprintf(buffer, sizeof(buffer), "%s\n", dev->name);
54+
len += scnprintf(buffer, sizeof(buffer), "%s\n", dev->name);
5555
}
5656
}
5757

5858
if(!len) {
59-
len += snprintf(buffer, sizeof(buffer), "%s\n", "none");
59+
len += scnprintf(buffer, sizeof(buffer), "%s\n", "none");
6060
}
6161

6262
if (len > *lenp)
@@ -87,19 +87,19 @@ static int do_autoprobe(const struct ctl_table *table, int write,
8787
}
8888

8989
if ((str = info->class_name) != NULL)
90-
len += snprintf (buffer + len, sizeof(buffer) - len, "CLASS:%s;\n", str);
90+
len += scnprintf (buffer + len, sizeof(buffer) - len, "CLASS:%s;\n", str);
9191

9292
if ((str = info->model) != NULL)
93-
len += snprintf (buffer + len, sizeof(buffer) - len, "MODEL:%s;\n", str);
93+
len += scnprintf (buffer + len, sizeof(buffer) - len, "MODEL:%s;\n", str);
9494

9595
if ((str = info->mfr) != NULL)
96-
len += snprintf (buffer + len, sizeof(buffer) - len, "MANUFACTURER:%s;\n", str);
96+
len += scnprintf (buffer + len, sizeof(buffer) - len, "MANUFACTURER:%s;\n", str);
9797

9898
if ((str = info->description) != NULL)
99-
len += snprintf (buffer + len, sizeof(buffer) - len, "DESCRIPTION:%s;\n", str);
99+
len += scnprintf (buffer + len, sizeof(buffer) - len, "DESCRIPTION:%s;\n", str);
100100

101101
if ((str = info->cmdset) != NULL)
102-
len += snprintf (buffer + len, sizeof(buffer) - len, "COMMAND SET:%s;\n", str);
102+
len += scnprintf (buffer + len, sizeof(buffer) - len, "COMMAND SET:%s;\n", str);
103103

104104
if (len > *lenp)
105105
len = *lenp;
@@ -128,7 +128,7 @@ static int do_hardware_base_addr(const struct ctl_table *table, int write,
128128
if (write) /* permissions prevent this anyway */
129129
return -EACCES;
130130

131-
len += snprintf (buffer, sizeof(buffer), "%lu\t%lu\n", port->base, port->base_hi);
131+
len += scnprintf (buffer, sizeof(buffer), "%lu\t%lu\n", port->base, port->base_hi);
132132

133133
if (len > *lenp)
134134
len = *lenp;
@@ -155,7 +155,7 @@ static int do_hardware_irq(const struct ctl_table *table, int write,
155155
if (write) /* permissions prevent this anyway */
156156
return -EACCES;
157157

158-
len += snprintf (buffer, sizeof(buffer), "%d\n", port->irq);
158+
len += scnprintf (buffer, sizeof(buffer), "%d\n", port->irq);
159159

160160
if (len > *lenp)
161161
len = *lenp;
@@ -182,7 +182,7 @@ static int do_hardware_dma(const struct ctl_table *table, int write,
182182
if (write) /* permissions prevent this anyway */
183183
return -EACCES;
184184

185-
len += snprintf (buffer, sizeof(buffer), "%d\n", port->dma);
185+
len += scnprintf (buffer, sizeof(buffer), "%d\n", port->dma);
186186

187187
if (len > *lenp)
188188
len = *lenp;
@@ -213,7 +213,7 @@ static int do_hardware_modes(const struct ctl_table *table, int write,
213213
#define printmode(x) \
214214
do { \
215215
if (port->modes & PARPORT_MODE_##x) \
216-
len += snprintf(buffer + len, sizeof(buffer) - len, "%s%s", f++ ? "," : "", #x); \
216+
len += scnprintf(buffer + len, sizeof(buffer) - len, "%s%s", f++ ? "," : "", #x); \
217217
} while (0)
218218
int f = 0;
219219
printmode(PCSPP);

0 commit comments

Comments
 (0)