Skip to content

Commit

Permalink
fix a kmap leak in virtio_console
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Al Viro committed Feb 9, 2014
1 parent d311d79 commit c9efe51
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions drivers/char/virtio_console.c
Original file line number Diff line number Diff line change
Expand Up @@ -890,22 +890,19 @@ static int pipe_to_sg(struct pipe_inode_info *pipe, struct pipe_buffer *buf,
} else {
/* Failback to copying a page */
struct page *page = alloc_page(GFP_KERNEL);
char *src = buf->ops->map(pipe, buf, 1);
char *dst;
char *src;

if (!page)
return -ENOMEM;
dst = kmap(page);

offset = sd->pos & ~PAGE_MASK;

len = sd->len;
if (len + offset > PAGE_SIZE)
len = PAGE_SIZE - offset;

memcpy(dst + offset, src + buf->offset, len);

kunmap(page);
src = buf->ops->map(pipe, buf, 1);
memcpy(page_address(page) + offset, src + buf->offset, len);
buf->ops->unmap(pipe, buf, src);

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

0 comments on commit c9efe51

Please sign in to comment.