Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935813AbdDSOrR (ORCPT ); Wed, 19 Apr 2017 10:47:17 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:47452 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1760927AbdDSOqG (ORCPT ); Wed, 19 Apr 2017 10:46:06 -0400 From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Omar Sandoval , "Michael S. Tsirkin" , Amit Shah , Ben Hutchings , Brad Spengler Subject: [PATCH 4.9 67/69] virtio-console: avoid DMA from stack Date: Wed, 19 Apr 2017 16:43:23 +0200 Message-Id: <20170419141619.676608860@linuxfoundation.org> X-Mailer: git-send-email 2.12.2 In-Reply-To: <20170419141616.919951169@linuxfoundation.org> References: <20170419141616.919951169@linuxfoundation.org> User-Agent: quilt/0.65 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1471 Lines: 52 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Omar Sandoval 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 Signed-off-by: Michael S. Tsirkin Reviewed-by: Amit Shah Cc: Ben Hutchings Cc: Brad Spengler Signed-off-by: Greg Kroah-Hartman --- drivers/char/virtio_console.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) --- a/drivers/char/virtio_console.c +++ b/drivers/char/virtio_console.c @@ -1136,6 +1136,8 @@ static int put_chars(u32 vtermno, const { struct port *port; struct scatterlist sg[1]; + void *data; + int ret; if (unlikely(early_put_chars)) return early_put_chars(vtermno, buf, count); @@ -1144,8 +1146,14 @@ static int put_chars(u32 vtermno, const if (!port) return -EPIPE; - sg_init_one(sg, buf, count); - return __send_to_port(port, sg, 1, count, (void *)buf, false); + data = kmemdup(buf, count, GFP_ATOMIC); + if (!data) + return -ENOMEM; + + sg_init_one(sg, data, count); + ret = __send_to_port(port, sg, 1, count, data, false); + kfree(data); + return ret; } /*