From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48079) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z8Rig-0004jC-V2 for qemu-devel@nongnu.org; Fri, 26 Jun 2015 07:22:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z8Ric-0006XD-01 for qemu-devel@nongnu.org; Fri, 26 Jun 2015 07:22:54 -0400 Received: from mx-v6.kamp.de ([2a02:248:0:51::16]:58617 helo=mx01.kamp.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z8Rib-0006Wh-M1 for qemu-devel@nongnu.org; Fri, 26 Jun 2015 07:22:49 -0400 From: Peter Lieven Date: Fri, 26 Jun 2015 13:14:01 +0200 Message-Id: <1435317241-25585-1-git-send-email-pl@kamp.de> Subject: [Qemu-devel] [PATCH] block/nfs: limit maximum readahead size to 1MB List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-block@nongnu.org, qemu-devel@nongnu.org Cc: kwolf@redhat.com, jcody@redhat.com, Peter Lieven , qemu-stable@nongnu.org, ronniesahlberg@gmail.com a malicious caller could otherwise specify a very large value via the URI and force libnfs to allocate a large amount of memory for the readahead buffer. Cc: qemu-stable@nongnu.org Signed-off-by: Peter Lieven --- block/nfs.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/block/nfs.c b/block/nfs.c index 43d48ae..4fb1937 100644 --- a/block/nfs.c +++ b/block/nfs.c @@ -35,6 +35,8 @@ #include "sysemu/sysemu.h" #include +#define QEMU_NFS_MAX_READAHEAD_SIZE 1048576 + typedef struct NFSClient { struct nfs_context *context; struct nfsfh *fh; @@ -351,6 +353,11 @@ static int64_t nfs_client_open(NFSClient *client, const char *filename, nfs_set_tcp_syncnt(client->context, val); #ifdef LIBNFS_FEATURE_READAHEAD } else if (!strcmp(qp->p[i].name, "readahead")) { + if (val > QEMU_NFS_MAX_READAHEAD_SIZE) { + error_report("NFS Warning: Truncating NFS readahead" + " size to %d", QEMU_NFS_MAX_READAHEAD_SIZE); + val = QEMU_NFS_MAX_READAHEAD_SIZE; + } nfs_set_readahead(client->context, val); #endif } else { -- 1.7.9.5