From patchwork Thu Mar 26 18:16:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 228743 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8A921C2D0E5 for ; Thu, 26 Mar 2020 18:16:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6214C20719 for ; Thu, 26 Mar 2020 18:16:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1585246594; bh=KLUSq5iw7Z93jzWyigCr90N7a6+kueD+eE8kLHhRWyk=; h=Date:From:To:Subject:List-ID:From; b=ZLaSvX+6JflYI9pfa5vynQfzdQ8Fs+5QXrD30W6dKdyY/XmPZzxc/Xr9jwzVN21DN xokkBFkq5XAk/LTF/s1Ac882GzM/dQfiulFJH9BnbkM25L/gekj9fVk3LpuguNxW0/ p9uCLxSxASDldmaDOdjudx1GtoITmwflofpjble4= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727907AbgCZSQc (ORCPT ); Thu, 26 Mar 2020 14:16:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:60264 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728578AbgCZSQ1 (ORCPT ); Thu, 26 Mar 2020 14:16:27 -0400 Received: from localhost.localdomain (c-71-198-47-131.hsd1.ca.comcast.net [71.198.47.131]) (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 73D522076A; Thu, 26 Mar 2020 18:16:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1585246586; bh=KLUSq5iw7Z93jzWyigCr90N7a6+kueD+eE8kLHhRWyk=; h=Date:From:To:Subject:From; b=NJSPW5mSco+Qyp9MsyvJ8BNj+zEginwsTgjk8l8pUOgPOjYq8Zu5tYOYkumEurt1c 2ppuHOZx3vbJE83RekGWPr2nLTPx6aYOIaAB/ABj2PS5XH30mUTXhHCIgJ+3ZG3xgB DRLBV0INC9LtYWZZu6+bSkln8WueoXyqcx2vvaqc= Date: Thu, 26 Mar 2020 11:16:26 -0700 From: akpm@linux-foundation.org To: arnd@arndb.de, ebiggers@google.com, glider@google.com, gregkh@linuxfoundation.org, keescook@chromium.org, mm-commits@vger.kernel.org, rafael@kernel.org, stable@vger.kernel.org, viro@zeniv.linux.org.uk Subject: [merged] libfs-fix-infoleak-in-simple_attr_read.patch removed from -mm tree Message-ID: <20200326181626.7XXIS_588%akpm@linux-foundation.org> User-Agent: s-nail v14.8.16 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org The patch titled Subject: libfs: fix infoleak in simple_attr_read() has been removed from the -mm tree. Its filename was libfs-fix-infoleak-in-simple_attr_read.patch This patch was dropped because it was merged into mainline or a subsystem tree ------------------------------------------------------ From: Eric Biggers Subject: libfs: fix infoleak in simple_attr_read() 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(" "); } Output: 5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a30 Fix the infoleak by making simple_attr_read() always fill simple_attr::get_buf if it hasn't been filled yet. Link: http://lkml.kernel.org/r/20200308023849.988264-1-ebiggers@kernel.org Fixes: acaefc25d21f ("[PATCH] libfs: add simple attribute files") Signed-off-by: Eric Biggers Reported-by: syzbot+fcab69d1ada3e8d6f06b@syzkaller.appspotmail.com Reported-by: Alexander Potapenko Cc: Al Viro Cc: Arnd Bergmann Cc: Greg Kroah-Hartman Cc: "Rafael J. Wysocki" Cc: Kees Cook Cc: Signed-off-by: Andrew Morton --- fs/libfs.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) --- a/fs/libfs.c~libfs-fix-infoleak-in-simple_attr_read +++ a/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)