Received: by 2002:a17:90a:1609:0:0:0:0 with SMTP id n9csp829692pja; Wed, 1 Apr 2020 09:28:26 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvt4LFmrfQQ1y8odBhQP/J5ML6aKVUh6JPHCaqA7xQB/rOEEXL+eGcrzp7IlgsMPLcElKXJ X-Received: by 2002:a05:6830:22c3:: with SMTP id q3mr18283130otc.152.1585758506561; Wed, 01 Apr 2020 09:28:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585758506; cv=none; d=google.com; s=arc-20160816; b=RHM7ghWfYvrTSsjvNpWZ4PTgwWYMEgS748YmfMnDUmlKxFyBMlMKVlPB3pkvgV0tXj Mog8dyvBa94N3/gDijMn6Q+RoAkkH/MyyMToiFFeWn0xnjxN57GNxMx2D/2G4cjaonoQ KHGYpJtts8MfjWEeulcmMOtM65IAe6HhVREu1sLjaEJepGozD4aUzsDIiFO3HHMQ7xmf 6OUmcXHfr/ARH1CBXGnpISYwhPQbgkogpLZUXg5pYdzpTGZEjVZ5mSkyoDXn4306t4fk KFx0UTyoLdi0h5dXzn0kJ2LX/4tX6jq0ZztqyuGhAfcSdaTD3Rh2m8jdithi2t+mq3vd tlaA== 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=CxWKSie3Clq3yYpMZrRrFjQqm9X67Mlt6eIM11ENzSE=; b=n+TMnACV8D8qGls/PGdVsWWYX37AHPDrjNkZS8lXXpkdX0T43h5j0V6bUqeZvqf4uz La5aOTtIALiKYj+fVpBZ5bT9OJEOwAj6ZXZiwDP2Lo+5nlYBw2K6JOO2iUs18ksUQy08 4DxW96swWc3biLBrZW7+QJT0BOU0gSkYl+sZJojnSQ+iP1XAnAqx+NBt1OI8YEBsU5Pm SJU9NS8ZchMIExkTjYiDPhkgiFWJmf/fydaT2Ez5dnZDRepBtzJr1T+iCdHuJHq481sZ eLsBndWteIyfS3vSvGbHPwZkn/zoaWUSRH4Ha3i0o2gGWTIMAKTH4WYVLxN+fsCUmlic /Tjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=UqnJlHcW; 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 d16si1079064oti.42.2020.04.01.09.28.14; Wed, 01 Apr 2020 09:28: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=UqnJlHcW; 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 S2388007AbgDAQ1S (ORCPT + 99 others); Wed, 1 Apr 2020 12:27:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:52036 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387688AbgDAQ1Q (ORCPT ); Wed, 1 Apr 2020 12:27: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 013BA2137B; Wed, 1 Apr 2020 16:27:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1585758435; bh=hWOZrHvnYSAf5XeSIOQqTauluJyu1ePX9xjyJ1biX1c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UqnJlHcWjFz8kspF76OOFDfawXKo+mkEu9DW3pCCu2z+5OJFviw9eJvGEmbto5foa BoVljqbSSjoptsNpJhSGAClLJ5WDz7pSCk+nx6GmG3Q7CUkCr24kbxOEpsgsCda0sL 7SWvv6rmOb92YudjR7RwyBEUwG4xEJInWvV5vBNQ= 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 4.19 091/116] libfs: fix infoleak in simple_attr_read() Date: Wed, 1 Apr 2020 18:17:47 +0200 Message-Id: <20200401161554.053891127@linuxfoundation.org> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200401161542.669484650@linuxfoundation.org> References: <20200401161542.669484650@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 @@ -802,7 +802,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; @@ -842,9 +842,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)