Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp3281984ybb; Tue, 31 Mar 2020 02:02:12 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvKMdUoDfpEE3D3jaB0gKKRja6HC+qhdydtSFCPaBEdu6Gm+Bv0B3T6GTgZceUOam7qFaHV X-Received: by 2002:a9d:6c45:: with SMTP id g5mr12236314otq.347.1585645331969; Tue, 31 Mar 2020 02:02:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585645331; cv=none; d=google.com; s=arc-20160816; b=HM94EdxIoML+OK6NIycSyUYtGjVRMjQ3JXX72I4lshClkrm7hSubxkZoTZfEhHbu1W dd4ebFanZ7x9sJ7GQU/XgFdrVy0iTeZaQiV7fXLjqevnx8k0+dFoiU7R4ue1O3lvMfSA zxmnr1MGX4fC2M97S7oh5a9K8ENuU8H7AmFFvJ62bUqBvBH77mtx2CvkKXaSsrP3XQcv I2JxLn6jSmvyi1QFp+1wzLjCnJ3PHzcAV10xWqzvQyO9l2B4Fwv9qMQt0oyAmDWaJst9 qas5KTY3Im/W2Rfrb7RuRJijXvc815Cqe2HanOIZL+JASbQDlVNwVD0TcEqMT5Wk2aBM G3JA== 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=12okNxUu7HkiaWWb3T3IAe2MzmQCi6AFGwV/MD8hFMA=; b=yj11C3oGDsYur1/5dqE07aWxzBvH4RVaUrayB5lYGQ0ZX9zB737pLRPssVLvIuOgHf 5pjHSkQVL3I0117c34jLompBfowxIFQG76Gzy4vNaveYwnMwJKpAMkn1HI1VYaqDb9JI j9Omfy7Wt5QTdK0nH/6cb/mm0DuGIEU1KyQL2MwyZhvak4fjG0TqexIavNAqHbwSZs73 Lird2l/ErUDbH/ktPo8adyw3vPl8FZseVoiwru1Y1yMHK/L8S6G1kWIfrYrNmY3hiDv3 /FWjwfWtKuMGnVfrQeMoeQ3ukWLWVx2YFyZv2VdMliT4m5oq6As3EZHtDhwqLxcwIrsK Fdcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=bKvV6ihg; 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 w83si6876404oie.244.2020.03.31.02.01.59; Tue, 31 Mar 2020 02:02:11 -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; dkim=pass header.i=@kernel.org header.s=default header.b=bKvV6ihg; 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 S1730284AbgCaJBU (ORCPT + 99 others); Tue, 31 Mar 2020 05:01:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:40370 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730529AbgCaJBQ (ORCPT ); Tue, 31 Mar 2020 05:01:16 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 3819420848; Tue, 31 Mar 2020 09:01:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1585645275; bh=KvzhaAcLy43FUwrIjwAkHeCXYc3rw3M7R9H8+Ql4ais=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bKvV6ihgVF6p/GHTBXhoACaa6oY2O4W8iIHtWoSSmet1/V6S7xPhFXjgwBUjc7Tp9 WfBqRWKjiz/ig1w9CYDKEtFA4nBD5bTIsvA3V2YBEQtPRJa6Tas7OwRUR+g+ptldKU ra9zKmZvDzuIE/jDR7U65r1tQypvZZQ32UQs2pIY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+fcab69d1ada3e8d6f06b@syzkaller.appspotmail.com, Alexander Potapenko , Eric Biggers , Kees Cook Subject: [PATCH 5.6 18/23] libfs: fix infoleak in simple_attr_read() Date: Tue, 31 Mar 2020 10:59:30 +0200 Message-Id: <20200331085316.284532826@linuxfoundation.org> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200331085308.098696461@linuxfoundation.org> References: <20200331085308.098696461@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: Eric Biggers commit a65cab7d7f05c2061a3e2490257d3086ff3202c6 upstream. Reading from a debugfs file at a nonzero position, without first reading at position 0, leaks uninitialized memory to userspace. It's a bit tricky to do this, since lseek() and pread() aren't allowed on these files, and write() doesn't update the position on them. But writing to them with splice() *does* update the position: #define _GNU_SOURCE 1 #include #include #include int main() { int pipes[2], fd, n, i; char buf[32]; pipe(pipes); write(pipes[1], "0", 1); fd = open("/sys/kernel/debug/fault_around_bytes", O_RDWR); splice(pipes[0], NULL, fd, NULL, 1, 0); n = read(fd, buf, sizeof(buf)); for (i = 0; i < n; i++) printf("%02x", buf[i]); printf("\n"); } Output: 5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a30 Fix the infoleak by making simple_attr_read() always fill simple_attr::get_buf if it hasn't been filled yet. Reported-by: syzbot+fcab69d1ada3e8d6f06b@syzkaller.appspotmail.com Reported-by: Alexander Potapenko Fixes: acaefc25d21f ("[PATCH] libfs: add simple attribute files") Cc: stable@vger.kernel.org Signed-off-by: Eric Biggers Acked-by: Kees Cook Link: https://lore.kernel.org/r/20200308023849.988264-1-ebiggers@kernel.org Signed-off-by: Greg Kroah-Hartman --- fs/libfs.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) --- a/fs/libfs.c +++ b/fs/libfs.c @@ -891,7 +891,7 @@ int simple_attr_open(struct inode *inode { struct simple_attr *attr; - attr = kmalloc(sizeof(*attr), GFP_KERNEL); + attr = kzalloc(sizeof(*attr), GFP_KERNEL); if (!attr) return -ENOMEM; @@ -931,9 +931,11 @@ ssize_t simple_attr_read(struct file *fi if (ret) return ret; - if (*ppos) { /* continued read */ + if (*ppos && attr->get_buf[0]) { + /* continued read */ size = strlen(attr->get_buf); - } else { /* first read */ + } else { + /* first read */ u64 val; ret = attr->get(attr->data, &val); if (ret)