Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp2379335ybb; Sat, 21 Mar 2020 20:58:26 -0700 (PDT) X-Google-Smtp-Source: ADFU+vsZMfAG48nt+hTZlBCj13kpAtz7IHI+Cr2iGTEZGa1ZUwKSENbLSa811lM0pKB3KTfe1shH X-Received: by 2002:a05:6830:12d0:: with SMTP id a16mr13261443otq.218.1584849506692; Sat, 21 Mar 2020 20:58:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584849506; cv=none; d=google.com; s=arc-20160816; b=xV5vGT5qFxn0+qqL2cFQxIgRFQvEc/j7sm+/PxvId+LrBmp4eavZJSlKXNtK2rJ6P+ x5TkEV4bhj20dBMMCO5VvRNfAtb+gIskVyyCIkcwtmPZuumFOAIwfpR+fydGbaadnUrg zsUlatwcBiT+aYaCji7ZpjUvcbkbozeJbb39TKHykBadfV6E9qhYeSY0VpdGDPnHZCYc xkdfStfJxqzwqKoTzQcmlPVVGxBtJzEZUpWkomG4VQgC4CGytT1cei5mCY+QVgx/OlLG vAt4bWOT+foIR266DONtK1MqZSKBQtIcLdhmq1MiWdTG+Q/jgVaSCA8awK7ekkZMt02z Chqg== 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:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=awfVKPjUNY918ZHnCFLYpU9yVM1GGQ5ihPPY9iU03SY=; b=XfjmTUUzTw/nOXu6XHNvlFbx7Rqfzooet2xOTX7WVWkH4KOcGqWzS2FJyqY2Rn9r3T 1wU5yZfale6VgY2kJ5DLnjMrl8WuqdKTuDdI/c+FeVeA1xxG0s0FpQT8nw/u464TYcey JMHtWdTsG8d+usmVVkFnD9Nr63vwXiALXYWyJN+/WpqrXcniCLt6QswD55yYajpRzT3t O3gueRf6o4MpyQOgTuOkRAdWxhmR9yYvi6kkdMbizMDtGe1ZoSLMOM0LkwKXYyvHx/Dn 164t4TIHyJfSEzDtJQw9UFjFdEy0gku4BoA0ng+HkRtFYyMG3KPr0utMArGBTbl7fwlm 4bMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=EN2BNrlC; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g8si5374778otk.163.2020.03.21.20.58.03; Sat, 21 Mar 2020 20:58:26 -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=EN2BNrlC; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728236AbgCVD4X (ORCPT + 99 others); Sat, 21 Mar 2020 23:56:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:39600 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727916AbgCVD4W (ORCPT ); Sat, 21 Mar 2020 23:56:22 -0400 Received: from sol.localdomain (c-107-3-166-239.hsd1.ca.comcast.net [107.3.166.239]) (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 99DBC206F9; Sun, 22 Mar 2020 03:56:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1584849381; bh=gEc6ll7k79SRCcvS6bS5pbS5Jt64kHUc3E7gUSK61Ho=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=EN2BNrlCb/Q42OYuKnxqahlx5WoCaHSKqlejwHpr/DZeD9Q2d298cKCbT0A9tRZ1p ZTdg3+7c+9amjHC+3wshxvi/KuFZhG8YZp7gJJ0lXMs5zdZy4xT//gCqPOp9wK7yuj CToyyyZtMKnvxs5Zo3cikHjwQ8F05T2LUZOWLc+s= Date: Sat, 21 Mar 2020 20:56:20 -0700 From: Eric Biggers To: Andrew Morton Cc: linux-fsdevel@vger.kernel.org, viro@zeniv.linux.org.uk, glider@google.com, arnd@arndb.de, gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, rafael@kernel.org, syzbot+fcab69d1ada3e8d6f06b@syzkaller.appspotmail.com, syzkaller-bugs@googlegroups.com Subject: Re: [PATCH] libfs: fix infoleak in simple_attr_read() Message-ID: <20200322035620.GB111151@sol.localdomain> References: <20200308023849.988264-1-ebiggers@kernel.org> <20200313164511.GB907@sol.localdomain> <20200318163940.GB2334@sol.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200318163940.GB2334@sol.localdomain> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Mar 18, 2020 at 09:39:40AM -0700, Eric Biggers wrote: > On Fri, Mar 13, 2020 at 09:45:11AM -0700, Eric Biggers wrote: > > On Sat, Mar 07, 2020 at 06:38:49PM -0800, Eric Biggers wrote: > > > From: Eric Biggers > > > > > > 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 > > > --- > > > fs/libfs.c | 8 +++++--- > > > 1 file changed, 5 insertions(+), 3 deletions(-) > > > > > > diff --git a/fs/libfs.c b/fs/libfs.c > > > index c686bd9caac6..3759fbacf522 100644 > > > --- a/fs/libfs.c > > > +++ b/fs/libfs.c > > > @@ -891,7 +891,7 @@ int simple_attr_open(struct inode *inode, struct file *file, > > > { > > > 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 *file, char __user *buf, > > > 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) > > > -- > > > 2.25.1 > > > > Any comments on this? Al, seems this is something you should pick up? > > > > - Eric > > Ping. > Andrew, can you consider taking this patch? Al has been ignoring it, and this seems like a fairly important fix. This bug affects many (most?) debugfs files, and it affects years old kernels too not just recent ones. Thanks, - Eric