Skip to content

Commit c9efe51

Browse files
author
Al Viro
committed
fix a kmap leak in virtio_console
While we are at it, don't do kmap() under kmap_atomic(), *especially* for a page we'd allocated with GFP_KERNEL. It's spelled "page_address", and had that been more than that, we'd have a real trouble - kmap_high() can block, and doing that while holding kmap_atomic() is a Bad Idea(tm). Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent d311d79 commit c9efe51

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

drivers/char/virtio_console.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -890,22 +890,19 @@ static int pipe_to_sg(struct pipe_inode_info *pipe, struct pipe_buffer *buf,
890890
} else {
891891
/* Failback to copying a page */
892892
struct page *page = alloc_page(GFP_KERNEL);
893-
char *src = buf->ops->map(pipe, buf, 1);
894-
char *dst;
893+
char *src;
895894

896895
if (!page)
897896
return -ENOMEM;
898-
dst = kmap(page);
899897

900898
offset = sd->pos & ~PAGE_MASK;
901899

902900
len = sd->len;
903901
if (len + offset > PAGE_SIZE)
904902
len = PAGE_SIZE - offset;
905903

906-
memcpy(dst + offset, src + buf->offset, len);
907-
908-
kunmap(page);
904+
src = buf->ops->map(pipe, buf, 1);
905+
memcpy(page_address(page) + offset, src + buf->offset, len);
909906
buf->ops->unmap(pipe, buf, src);
910907

911908
sg_set_page(&(sgl->sg[sgl->n]), page, len, offset);

0 commit comments

Comments
 (0)