Skip to content

Commit eb52676

Browse files
osandovgregkh
authored andcommitted
virtio-console: avoid DMA from stack
commit c4baad50297d84bde1a7ad45e50c73adae4a2192 upstream. put_chars() stuffs the buffer it gets into an sg, but that buffer may be on the stack. This breaks with CONFIG_VMAP_STACK=y (for me, it manifested as printks getting turned into NUL bytes). Signed-off-by: Omar Sandoval <osandov@fb.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Reviewed-by: Amit Shah <amit.shah@redhat.com> Cc: Ben Hutchings <ben@decadent.org.uk> Cc: Brad Spengler <spender@grsecurity.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 6be431f commit eb52676

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

drivers/char/virtio_console.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,6 +1130,8 @@ static int put_chars(u32 vtermno, const char *buf, int count)
11301130
{
11311131
struct port *port;
11321132
struct scatterlist sg[1];
1133+
void *data;
1134+
int ret;
11331135

11341136
if (unlikely(early_put_chars))
11351137
return early_put_chars(vtermno, buf, count);
@@ -1138,8 +1140,14 @@ static int put_chars(u32 vtermno, const char *buf, int count)
11381140
if (!port)
11391141
return -EPIPE;
11401142

1141-
sg_init_one(sg, buf, count);
1142-
return __send_to_port(port, sg, 1, count, (void *)buf, false);
1143+
data = kmemdup(buf, count, GFP_ATOMIC);
1144+
if (!data)
1145+
return -ENOMEM;
1146+
1147+
sg_init_one(sg, data, count);
1148+
ret = __send_to_port(port, sg, 1, count, data, false);
1149+
kfree(data);
1150+
return ret;
11431151
}
11441152

11451153
/*

0 commit comments

Comments
 (0)