Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3334035imu; Sun, 11 Nov 2018 12:36:10 -0800 (PST) X-Google-Smtp-Source: AJdET5dbwv5H8Ik9Vx0th/DBPhA0MNkDv96f3cv3JlTdE4ju0lr3eky5LYHH0NstAmh0Wp3h6thL X-Received: by 2002:a62:4c6:: with SMTP id 189-v6mr13463405pfe.110.1541968570085; Sun, 11 Nov 2018 12:36:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541968570; cv=none; d=google.com; s=arc-20160816; b=uhD+QAQpWlAa45oGQ6Zihlo9DvLRFHpnkkBXQADpPN1sxhRBxENXAWUskQvKe0WgkL 1Iel2/DtwZaNlycCS40si3Qb9ud6a5CzpdcXExz1C0Bv8zIGTNDdXfHZM+Vx2m04r+z1 XOaAh9N5hVNj/b6ghI8wjToFwYqgMgaqX9qq5rqkSrtBTputUy9SFsPudWWtDrDY2Qs/ wDNWLW717iLsa16R5XdQup1MA5RITxA5s9y097DqYJDs28uovagkfEHxxClECX8NrLyi fv0LkOyhBuUU1Y28oMX+mdToX0lLJ+X7+3HzBGZ2uL4rwdHcrhhkdMvoy89Z5SbojIyI UVpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=nbCTyAs7NeCk5f++F42NCSSLao8UXOmTitJL3TlD6SA=; b=PWKF+nFAqbKSMyIXdaYalVWWMw3v/PN4Q7pvebmQQ+qMXuqdmUedCYwzIvxl5mZhuv 4Jax4kGHamGjMaE+eyD1/ewbkqm+RwyJcXdrXuXXZ3fLJc+mgZj2bPigBTzDz902LTBO OzVSeMwTiEhS5+e/ugeLuiilfruatzd0u2KStsL8ttUi+TAtvcbl1NdrLIlB8vvEgtYv VHOnIZPYx2BfLZIXG/z+9c7NmRtPVhrgoTHUHDF2rhguEENTYkLXj89eJlTwvJxyWlVJ 3SXfR5CWN5PMAkRWlpfGFcXtu18YqGqfPlFMAI7Lni5vi40aQQ6CRB7AskQJ1fqTKcnq VL/w== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 22si14313852pgr.356.2018.11.11.12.35.55; Sun, 11 Nov 2018 12:36:10 -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; 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 S1731482AbeKLGYx (ORCPT + 99 others); Mon, 12 Nov 2018 01:24:53 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:49916 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730055AbeKLFsN (ORCPT ); Mon, 12 Nov 2018 00:48:13 -0500 Received: from [192.168.4.242] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1gLvsZ-0000oU-9K; Sun, 11 Nov 2018 19:58:43 +0000 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1gLvsV-0001iA-Td; Sun, 11 Nov 2018 19:58:39 +0000 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Greg Kroah-Hartman" , "Jann Horn" Date: Sun, 11 Nov 2018 19:49:05 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 240/366] ibmasm: don't write out of bounds in read handler In-Reply-To: X-SA-Exim-Connect-IP: 192.168.4.242 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.61-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Jann Horn commit a0341fc1981a950c1e902ab901e98f60e0e243f3 upstream. This read handler had a lot of custom logic and wrote outside the bounds of the provided buffer. This could lead to kernel and userspace memory corruption. Just use simple_read_from_buffer() with a stack buffer. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Jann Horn Signed-off-by: Greg Kroah-Hartman Signed-off-by: Ben Hutchings --- drivers/misc/ibmasm/ibmasmfs.c | 27 +++------------------------ 1 file changed, 3 insertions(+), 24 deletions(-) --- a/drivers/misc/ibmasm/ibmasmfs.c +++ b/drivers/misc/ibmasm/ibmasmfs.c @@ -507,35 +507,14 @@ static int remote_settings_file_close(st static ssize_t remote_settings_file_read(struct file *file, char __user *buf, size_t count, loff_t *offset) { void __iomem *address = (void __iomem *)file->private_data; - unsigned char *page; - int retval; int len = 0; unsigned int value; - - if (*offset < 0) - return -EINVAL; - if (count == 0 || count > 1024) - return 0; - if (*offset != 0) - return 0; - - page = (unsigned char *)__get_free_page(GFP_KERNEL); - if (!page) - return -ENOMEM; + char lbuf[20]; value = readl(address); - len = sprintf(page, "%d\n", value); - - if (copy_to_user(buf, page, len)) { - retval = -EFAULT; - goto exit; - } - *offset += len; - retval = len; + len = snprintf(lbuf, sizeof(lbuf), "%d\n", value); -exit: - free_page((unsigned long)page); - return retval; + return simple_read_from_buffer(buf, count, offset, lbuf, len); } static ssize_t remote_settings_file_write(struct file *file, const char __user *ubuff, size_t count, loff_t *offset)