Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp4482883ybx; Mon, 4 Nov 2019 14:10:26 -0800 (PST) X-Google-Smtp-Source: APXvYqx0HEk2N+JwE7yuqRo49lC31X6PuF0h4r2xY34RIPSwzohwMOHrthWQMnGR9G4HnWvT2wGm X-Received: by 2002:a17:906:6a8e:: with SMTP id p14mr26279572ejr.137.1572905426882; Mon, 04 Nov 2019 14:10:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1572905426; cv=none; d=google.com; s=arc-20160816; b=hxA1gIBkyFzsHZXw0QQpZotQ//u4wPn/Xxl2aUnY91POiI5Tz/0lJLGCX+a/Wq2bw+ aHlA3g78/6YDDnY2gfOiqM0ncbK/C1fs2Hu+DzD46q9x6+dyrh2wySt0jDRIqT5SJ2Mv KHoyknfqegRgm5kFX6Okq3FP4OeKLmYUlJBcv0PnetBMMZQ/hRcw0OGdefsI4jnhdAhi KYIQkaDcIpuNBZD3dE0Oo/V4UD5Uh5KEP4jfVlwgHCw8irWjAkWvKTRd0BCYb50y+TcV P8U567HZY7r8sI0BK8IXo+SCIIVApi89BQCaiWRkmoylEIq0DV+KiY9MV9JD217Qm9GC Q66Q== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=yAB2YpElgYs3jJ7RFA1BFuARh3VDE8FqljYkO/v64Xo=; b=ByYdYq1LA6Fuqr0ekWnC9bu47iEX8TpMNfoya1BQF76jxqnzBePYQ9EjfmpKa2G2md 5C3RVtGygoz+pLA/uqy/Js86A/A4MhpzK2/ajgzdBLm1IuHr7yhc+tIsFokgY60IWp5R jt20j8lzS0Tq+2fodCWdIcCF/8c5ow2g7avwd8AXk/iLcIgnhntv+caYBNovqz6HVkJI 2+g3Hh6cK2wFYxQ+wfJSgc1SqQMe2YKvlLLjR+wUONiINnLhfcPaMU0BbQB0BWeiedRQ LHP9XBbCce51QGLLQ1/qn+BVgSoxn/Qw/1C2OxXKE9xVHaCuQHxY75UfsdY8cz2H6p8l sS4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=tTFblPnU; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d13si11904950ejj.317.2019.11.04.14.10.04; Mon, 04 Nov 2019 14:10:26 -0800 (PST) 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; dkim=pass header.i=@kernel.org header.s=default header.b=tTFblPnU; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390434AbfKDWJh (ORCPT + 99 others); Mon, 4 Nov 2019 17:09:37 -0500 Received: from mail.kernel.org ([198.145.29.99]:42700 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390428AbfKDWJf (ORCPT ); Mon, 4 Nov 2019 17:09:35 -0500 Received: from localhost (6.204-14-84.ripe.coltfrance.com [84.14.204.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9A9F5205C9; Mon, 4 Nov 2019 22:09:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1572905374; bh=FcvIkPlZoo1KYgkGZrbwj5COfkWLmbCCRLPv1vLgQsg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tTFblPnUUg194vcu++HU8x651L0QyiFi09hgdDHboNFbp5LcTz2r3xJPl+YNWZohd sXLpGHe0Bwe1B2BKEbsydZGbvCtHBQY+CRdtrtU7++xd3UC2/eEE3PubwJUsZPm3iV Trl8tMcAuH7CsAkJ03H9h/dsAft4tf1KUZuXzojE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Yihui Zeng , Dan Carpenter , Heiko Carstens , Vasily Gorbik Subject: [PATCH 5.3 123/163] s390/cmm: fix information leak in cmm_timeout_handler() Date: Mon, 4 Nov 2019 22:45:13 +0100 Message-Id: <20191104212149.127095645@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191104212140.046021995@linuxfoundation.org> References: <20191104212140.046021995@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Yihui ZENG commit b8e51a6a9db94bc1fb18ae831b3dab106b5a4b5f upstream. The problem is that we were putting the NUL terminator too far: buf[sizeof(buf) - 1] = '\0'; If the user input isn't NUL terminated and they haven't initialized the whole buffer then it leads to an info leak. The NUL terminator should be: buf[len - 1] = '\0'; Signed-off-by: Yihui Zeng Cc: stable@vger.kernel.org Signed-off-by: Dan Carpenter [heiko.carstens@de.ibm.com: keep semantics of how *lenp and *ppos are handled] Signed-off-by: Heiko Carstens Signed-off-by: Vasily Gorbik Signed-off-by: Greg Kroah-Hartman --- arch/s390/mm/cmm.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) --- a/arch/s390/mm/cmm.c +++ b/arch/s390/mm/cmm.c @@ -298,16 +298,16 @@ static int cmm_timeout_handler(struct ct } if (write) { - len = *lenp; - if (copy_from_user(buf, buffer, - len > sizeof(buf) ? sizeof(buf) : len)) + len = min(*lenp, sizeof(buf)); + if (copy_from_user(buf, buffer, len)) return -EFAULT; - buf[sizeof(buf) - 1] = '\0'; + buf[len - 1] = '\0'; cmm_skip_blanks(buf, &p); nr = simple_strtoul(p, &p, 0); cmm_skip_blanks(p, &p); seconds = simple_strtoul(p, &p, 0); cmm_set_timeout(nr, seconds); + *ppos += *lenp; } else { len = sprintf(buf, "%ld %ld\n", cmm_timeout_pages, cmm_timeout_seconds); @@ -315,9 +315,9 @@ static int cmm_timeout_handler(struct ct len = *lenp; if (copy_to_user(buffer, buf, len)) return -EFAULT; + *lenp = len; + *ppos += len; } - *lenp = len; - *ppos += len; return 0; }