Skip to content

Commit 49521b1

Browse files
dvyukovdanvet
authored andcommitted
drivers/gpu/vga: allocate vga_arb_write() buffer on stack
Size of kmalloc() in vga_arb_write() is controlled by user. Too large kmalloc() size triggers WARNING message on console. Allocate the buffer on stack to avoid the WARNING. The string must be small (e.g "target PCI:domain:bus:dev.fn"). Signed-off-by: Dmitry Vyukov <[email protected]> Reviewed-by: Ville Syrjälä <[email protected]> Cc: Dave Airlie <[email protected]> Cc: Ville Syrjälä <[email protected]> Cc: [email protected] Cc: [email protected] Signed-off-by: Daniel Vetter <[email protected]> Link: http://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent 0853695 commit 49521b1

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

drivers/gpu/vga/vgaarb.c

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,21 +1022,16 @@ static ssize_t vga_arb_write(struct file *file, const char __user *buf,
10221022

10231023
unsigned int io_state;
10241024

1025-
char *kbuf, *curr_pos;
1025+
char kbuf[64], *curr_pos;
10261026
size_t remaining = count;
10271027

10281028
int ret_val;
10291029
int i;
10301030

1031-
1032-
kbuf = kmalloc(count + 1, GFP_KERNEL);
1033-
if (!kbuf)
1034-
return -ENOMEM;
1035-
1036-
if (copy_from_user(kbuf, buf, count)) {
1037-
kfree(kbuf);
1031+
if (count >= sizeof(kbuf))
1032+
return -EINVAL;
1033+
if (copy_from_user(kbuf, buf, count))
10381034
return -EFAULT;
1039-
}
10401035
curr_pos = kbuf;
10411036
kbuf[count] = '\0'; /* Just to make sure... */
10421037

@@ -1259,11 +1254,9 @@ static ssize_t vga_arb_write(struct file *file, const char __user *buf,
12591254
goto done;
12601255
}
12611256
/* If we got here, the message written is not part of the protocol! */
1262-
kfree(kbuf);
12631257
return -EPROTO;
12641258

12651259
done:
1266-
kfree(kbuf);
12671260
return ret_val;
12681261
}
12691262

0 commit comments

Comments
 (0)