From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
stable@vger.kernel.org,
syzbot+fcab69d1ada3e8d6f06b@syzkaller.appspotmail.com,
Alexander Potapenko <glider@google.com>,
Eric Biggers <ebiggers@google.com>,
Kees Cook <keescook@chromium.org>
Subject: [PATCH 5.6 18/23] libfs: fix infoleak in simple_attr_read()
Date: Tue, 31 Mar 2020 10:59:30 +0200 [thread overview]
Message-ID: <20200331085316.284532826@linuxfoundation.org> (raw)
In-Reply-To: <20200331085308.098696461@linuxfoundation.org>
From: Eric Biggers <ebiggers@google.com>
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 <fcntl.h>
#include <stdio.h>
#include <unistd.h>
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 <glider@google.com>
Fixes: acaefc25d21f ("[PATCH] libfs: add simple attribute files")
Cc: stable@vger.kernel.org
Signed-off-by: Eric Biggers <ebiggers@google.com>
Acked-by: Kees Cook <keescook@chromium.org>
Link: https://lore.kernel.org/r/20200308023849.988264-1-ebiggers@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
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)
next prev parent reply other threads:[~2020-03-31 9:01 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-31 8:59 [PATCH 5.6 00/23] 5.6.1-rc1 review Greg Kroah-Hartman
2020-03-31 8:59 ` [PATCH 5.6 01/23] bpf: Undo incorrect __reg_bound_offset32 handling Greg Kroah-Hartman
2020-03-31 8:59 ` [PATCH 5.6 02/23] USB: serial: option: add support for ASKEY WWHC050 Greg Kroah-Hartman
2020-03-31 8:59 ` [PATCH 5.6 03/23] USB: serial: option: add BroadMobi BM806U Greg Kroah-Hartman
2020-03-31 8:59 ` [PATCH 5.6 04/23] USB: serial: option: add Wistron Neweb D19Q1 Greg Kroah-Hartman
2020-03-31 8:59 ` [PATCH 5.6 05/23] USB: cdc-acm: restore capability check order Greg Kroah-Hartman
2020-03-31 8:59 ` [PATCH 5.6 06/23] USB: serial: io_edgeport: fix slab-out-of-bounds read in edge_interrupt_callback Greg Kroah-Hartman
2020-03-31 8:59 ` [PATCH 5.6 07/23] usb: musb: fix crash with highmen PIO and usbmon Greg Kroah-Hartman
2020-03-31 8:59 ` [PATCH 5.6 08/23] media: flexcop-usb: fix endpoint sanity check Greg Kroah-Hartman
2020-03-31 8:59 ` [PATCH 5.6 09/23] media: usbtv: fix control-message timeouts Greg Kroah-Hartman
2020-03-31 8:59 ` [PATCH 5.6 10/23] staging: kpc2000: prevent underflow in cpld_reconfigure() Greg Kroah-Hartman
2020-03-31 8:59 ` [PATCH 5.6 11/23] staging: rtl8188eu: Add ASUS USB-N10 Nano B1 to device table Greg Kroah-Hartman
2020-03-31 8:59 ` [PATCH 5.6 12/23] staging: wlan-ng: fix ODEBUG bug in prism2sta_disconnect_usb Greg Kroah-Hartman
2020-03-31 8:59 ` [PATCH 5.6 13/23] staging: wlan-ng: fix use-after-free Read in hfa384x_usbin_callback Greg Kroah-Hartman
2020-03-31 8:59 ` [PATCH 5.6 14/23] staging: wfx: add proper "compatible" string Greg Kroah-Hartman
2020-03-31 8:59 ` [PATCH 5.6 15/23] staging: wfx: fix init/remove vs IRQ race Greg Kroah-Hartman
2020-03-31 8:59 ` [PATCH 5.6 16/23] staging: wfx: annotate nested gc_list vs tx queue locking Greg Kroah-Hartman
2020-03-31 8:59 ` [PATCH 5.6 17/23] ahci: Add Intel Comet Lake H RAID PCI ID Greg Kroah-Hartman
2020-03-31 8:59 ` Greg Kroah-Hartman [this message]
2020-03-31 8:59 ` [PATCH 5.6 19/23] media: ov519: add missing endpoint sanity checks Greg Kroah-Hartman
2020-03-31 8:59 ` [PATCH 5.6 20/23] media: dib0700: fix rc endpoint lookup Greg Kroah-Hartman
2020-03-31 8:59 ` [PATCH 5.6 21/23] media: stv06xx: add missing descriptor sanity checks Greg Kroah-Hartman
2020-03-31 8:59 ` [PATCH 5.6 22/23] media: xirlink_cit: " Greg Kroah-Hartman
2020-03-31 8:59 ` [PATCH 5.6 23/23] media: v4l2-core: fix a use-after-free bug of sd->devnode Greg Kroah-Hartman
2020-03-31 18:07 ` [PATCH 5.6 00/23] 5.6.1-rc1 review Naresh Kamboju
2020-03-31 18:20 ` Linus Torvalds
2020-03-31 19:29 ` Arnaldo Carvalho de Melo
2020-03-31 23:18 ` Daniel Díaz
2020-04-01 12:40 ` Arnaldo Carvalho de Melo
2020-04-01 13:45 ` Daniel Díaz
2020-04-01 14:34 ` Arnaldo Carvalho de Melo
2020-04-01 15:07 ` Daniel Díaz
2020-04-04 8:41 ` [tip: perf/urgent] perf python: Fix clang detection to strip out options passed in $CC tip-bot2 for Arnaldo Carvalho de Melo
2020-03-31 19:32 ` [PATCH 5.6 00/23] 5.6.1-rc1 review shuah
2020-04-01 8:19 ` Greg Kroah-Hartman
2020-03-31 20:02 ` Vitor Massaru Iha
2020-04-01 2:25 ` Guenter Roeck
2020-04-01 8:20 ` Greg Kroah-Hartman
2020-04-01 3:06 ` Woody Suwalski
2020-04-01 5:51 ` Greg Kroah-Hartman
2020-04-01 5:53 ` Greg Kroah-Hartman
2020-04-01 11:06 ` Woody Suwalski
2020-04-01 11:18 ` Greg Kroah-Hartman
2020-04-01 15:40 ` shuah
2020-04-01 16:10 ` Greg Kroah-Hartman
2020-04-01 8:57 ` Jon Hunter
2020-04-01 9:33 ` Greg Kroah-Hartman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200331085316.284532826@linuxfoundation.org \
--to=gregkh@linuxfoundation.org \
--cc=ebiggers@google.com \
--cc=glider@google.com \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=syzbot+fcab69d1ada3e8d6f06b@syzkaller.appspotmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).