Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp3200406ybh; Mon, 16 Mar 2020 18:05:43 -0700 (PDT) X-Google-Smtp-Source: ADFU+vs+9vpBt7qOpMa3vCmIOA7yX65GAocRTspr5VxFcNNG4Y2TwMxJa+43QTtZiYMWl2zohXYd X-Received: by 2002:a9d:4d82:: with SMTP id u2mr1523511otk.150.1584407143127; Mon, 16 Mar 2020 18:05:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584407143; cv=none; d=google.com; s=arc-20160816; b=w7LIT7R++I/7hinnBbiNCg67IQJ0+dVmeJqnKagq0t8ygi2qSmhfgWv9XW+ddy37AF AO4PGbEwZHkOuAkIMzAczm9iOZD/W7ViTqxywmd24hV1v9In1hJmqtotMdsB/eZQ2zuT l9URDMhaiv9BA3pTWeeVQsKfAzMv2BgKEDz26kS1SdAlGVWaDRRQNYcNQkyjLnH/rffS 2uWyBZIu9sXuzPioLBRvUXdfOuQt5A3pRFCWfqFQvBtwtG3qN27VhyDoQuTBycaUq2T0 q8q70Vhw9xJtLSqHRjcVgRQ+e07IkGoF3WQPlOi7jxK8WQT/1Z8PYiFYpwBsVCcCIgY6 8+YA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=eRape+4ln0nqZrH/8SPLwX5CTSTXdty26jiF2krEv7M=; b=QC7qsbQeidoigVGu9Q3ktj5fMwedVIicaccmmNkVNZl4rPWHE89U7om/ip3c/bG13R d+JXhQsr6Oz4Bp4+ZbKGt3Jc/Zum1RBRz9Y3Q+vCRDZIhVZB77oFI2IUVQwnqwCtqHW0 +tuyPM+WrvDlyEsIaWNeUrsNTDFh0c44LYN7gVKBk1pqU33ygluVWfaqInctW7W1VZ8Q xKJjyEi1TAa9UlxOFZY6+FRSi+kKxIfQBX+qs0QZhr0VhpBHNpdyY0v1cOaXZWMYvMxB H7ThUzgnfbMIcOW1BNzAIKwtQcPn9zRXhgzkjqN2IYAIPhga0uE8iUgLm8zh9EC+aIBP TFbA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f36si878322otf.201.2020.03.16.18.05.25; Mon, 16 Mar 2020 18:05:43 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733130AbgCQApY (ORCPT + 99 others); Mon, 16 Mar 2020 20:45:24 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:53802 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733005AbgCQApX (ORCPT ); Mon, 16 Mar 2020 20:45:23 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: krisman) with ESMTPSA id 47A2528AE2F From: Gabriel Krisman Bertazi To: jdike@addtoit.com Cc: richard@nod.at, anton.ivanov@cambridgegreys.com, linux-um@lists.infradead.org, linux-kernel@vger.kernel.org, Gabriel Krisman Bertazi , kernel@collabora.com, Martyn Welch Subject: [PATCH 1/2] um: ubd: Prevent buffer overrun on command completion Date: Mon, 16 Mar 2020 20:45:06 -0400 Message-Id: <20200317004507.1513370-2-krisman@collabora.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200317004507.1513370-1-krisman@collabora.com> References: <20200317004507.1513370-1-krisman@collabora.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On the hypervisor side, when completing commands and the pipe is full, we retry writing only the entries that failed, by offsetting io_req_buffer, but we don't reduce the number of bytes written, which can cause a buffer overrun of io_req_buffer, and write garbage to the pipe. Cc: Martyn Welch Signed-off-by: Gabriel Krisman Bertazi --- arch/um/drivers/ubd_kern.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/arch/um/drivers/ubd_kern.c b/arch/um/drivers/ubd_kern.c index 6627d7c30f37..0f5d0a699a49 100644 --- a/arch/um/drivers/ubd_kern.c +++ b/arch/um/drivers/ubd_kern.c @@ -1606,7 +1606,9 @@ int io_thread(void *arg) written = 0; do { - res = os_write_file(kernel_fd, ((char *) io_req_buffer) + written, n); + res = os_write_file(kernel_fd, + ((char *) io_req_buffer) + written, + n - written); if (res >= 0) { written += res; } -- 2.25.0