Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp684555yba; Wed, 3 Apr 2019 17:35:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqy/yILF/Q4dam9vuDFU0d1yxUhIdC+pY1z2Qf2ABoGlLPkBuh4kpStR211lRxX5a2w59j+b X-Received: by 2002:a63:6142:: with SMTP id v63mr2798888pgb.342.1554338127902; Wed, 03 Apr 2019 17:35:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554338127; cv=none; d=google.com; s=arc-20160816; b=j+OrLHgTYCaUwqY41JhQtVUiCLgtaYSTfM9bGlyRRBKBMPsVN1T3hm773Z8W9l8jn1 yAELQmZP5qX9dXLVGRd2meZQXw/ZVKHhBHH9DCOIW6WgntWFKf8doEN9hJ2A3QdmXqP4 PdqG4WAD0FVU5Ur7/kUn0QJ5jdVZyoQkAvmwRv4JbG3W4zowG4p1VzA7V2DdkwMnHfoh QFrZC8iOhQh5AcszZlM1xVebI5njQi0m5DmaxENcgiotU1iRibYbJgntPHiswoeRnQOw rTUVhWG1PeIuOKMC8Cxf4GhgGKEC39oqIOE4yRQ+cf03LlNk72X/XwIiN5/Qs01PC3EX k0xQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:references :mime-version:message-id:in-reply-to:date:dkim-signature; bh=oJN/8vrOD8P2EbLKMtCZWob1U7HL7tDO5O5Qy0qbLZY=; b=gaDG8xazhWO/pIay0wa7nK7uajHTMs4TcbYApIA5Dd+XhXBhhTE3dMK8PANZY2/SVK xIwHqwWFFCPNlKU/Unto5k4g8fCOukTB7qg8abnoNHJdcWEkas6VHZUdLcAuINF/GPKV qkm2G+UtfHINE/oOhupqFRrMCQ7xCh5kIGtz3Xz+/7GZLRIwPdyqQhVlZ72pphhAItPO S3GaJX0ze2UrWzplFHvShC/ekMI420aePNZ3sH6g8ph4iQksElCEsnMnIEfvm4CNZTuT BaEm0CKizmhtixT0Qp22+1nc8j6BHMbh+dzykfzWtpGz+RbU6aI7MBa1knaGKRgVmfLJ o8gw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ZrR284Sv; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j11si14705071pfh.47.2019.04.03.17.35.13; Wed, 03 Apr 2019 17:35:27 -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=@google.com header.s=20161025 header.b=ZrR284Sv; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728688AbfDDAeH (ORCPT + 99 others); Wed, 3 Apr 2019 20:34:07 -0400 Received: from mail-qt1-f202.google.com ([209.85.160.202]:48844 "EHLO mail-qt1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728678AbfDDAeF (ORCPT ); Wed, 3 Apr 2019 20:34:05 -0400 Received: by mail-qt1-f202.google.com with SMTP id 54so790913qtn.15 for ; Wed, 03 Apr 2019 17:34:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=oJN/8vrOD8P2EbLKMtCZWob1U7HL7tDO5O5Qy0qbLZY=; b=ZrR284SvWcC7W7DKhrssZkI3UOeYBGUqL32MCAYDqsPO6wWcT70fQ17WUOFw6skt14 cz9Of0GbzyW5RkL5N0bOWU/UPd/Jt9jpsTPPV6e3jpgNBE6bBMq4h51fDkALLFqPg4oG gQ93oDF/DPrxKjE4COy8qk3nV0qDGS7Wb209mnJBR7U73e86HgdnC+2B2WarfuBohgpe eWPT05bF/kBEDq6oU1AcSg9rajqGC2V7tGOKGNeyaoKWO0ntauwei7Ups4PU2yf+pHU4 6nOoS8gk3GS3kvfGxSCLkzw5f+x8DT70rDUabPzitghw7iDMJu5AIazyzvoArmh5bKyy z5ow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=oJN/8vrOD8P2EbLKMtCZWob1U7HL7tDO5O5Qy0qbLZY=; b=W1tRWIQErNOtftVtP4kqklhC8I9JDNBd4YaS/G4CFePp2zCG+Lcbw4ob17kJbDty0w +4BubcSPuzuvyOO4ojkFenpdDn9ZiDHcSPyD95tGh4aMwjN87UC44Unt/7kqUSIsVRhj hHUqzofIN7fSQPQUscZgwG+fos53E1FWuzgbPFpu32wyCiJsc8s+F2LkL0hQGYykFGAY NqllRUaXo/e6TeeWYyQpwzjaY67egKDHBvpWQ2EVBNFlZPZMCA78Za6niRc/T26jUXYN waAZiEsDOaFXiu+J2qk1ivDhwOygrTUPuS/L/oIAwnZPYUj79lgw4DSpTry7QOlnsZ7/ 1GDA== X-Gm-Message-State: APjAAAVOqxd+tf7mwIObw+J7mlae2rft70uf5WWebpplXW6zu/IHNmWF uKq0gqCUckLNY6sPEJmLTLacZBaaCZ0HaBnz2E6T6A== X-Received: by 2002:ac8:1812:: with SMTP id q18mr498916qtj.29.1554338044162; Wed, 03 Apr 2019 17:34:04 -0700 (PDT) Date: Wed, 3 Apr 2019 17:32:49 -0700 In-Reply-To: <20190404003249.14356-1-matthewgarrett@google.com> Message-Id: <20190404003249.14356-28-matthewgarrett@google.com> Mime-Version: 1.0 References: <20190404003249.14356-1-matthewgarrett@google.com> X-Mailer: git-send-email 2.21.0.392.gf8f6787159e-goog Subject: [PATCH V32 27/27] tracefs: Restrict tracefs when the kernel is locked down From: Matthew Garrett To: jmorris@namei.org Cc: linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, dhowells@redhat.com, linux-api@vger.kernel.org, luto@kernel.org, Matthew Garrett , Matthew Garrett , Steven Rostedt Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Tracefs may release more information about the kernel than desirable, so restrict it when the kernel is locked down in confidentiality mode by preventing open(). Signed-off-by: Matthew Garrett Cc: Steven Rostedt --- fs/tracefs/inode.c | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/fs/tracefs/inode.c b/fs/tracefs/inode.c index 7098c49f3693..576327ffd9d1 100644 --- a/fs/tracefs/inode.c +++ b/fs/tracefs/inode.c @@ -31,6 +31,21 @@ static struct vfsmount *tracefs_mount; static int tracefs_mount_count; static bool tracefs_registered; +static int default_open_file(struct inode *inode, struct file *filp) +{ + struct dentry *dentry = filp->f_path.dentry; + struct file_operations *real_fops; + + if (!dentry) + return -EINVAL; + + if (kernel_is_locked_down("tracefs", LOCKDOWN_CONFIDENTIALITY)) + return -EPERM; + + real_fops = dentry->d_fsdata; + return real_fops->open(inode, filp); +} + static ssize_t default_read_file(struct file *file, char __user *buf, size_t count, loff_t *ppos) { @@ -50,6 +65,13 @@ static const struct file_operations tracefs_file_operations = { .llseek = noop_llseek, }; +static const struct file_operations tracefs_proxy_file_operations = { + .read = default_read_file, + .write = default_write_file, + .open = default_open_file, + .llseek = noop_llseek, +}; + static struct tracefs_dir_ops { int (*mkdir)(const char *name); int (*rmdir)(const char *name); @@ -225,6 +247,12 @@ static int tracefs_apply_options(struct super_block *sb) return 0; } +static void tracefs_destroy_inode(struct inode *inode) +{ + if S_ISREG(inode->i_mode) + kfree(inode->i_fop); +} + static int tracefs_remount(struct super_block *sb, int *flags, char *data) { int err; @@ -260,6 +288,7 @@ static int tracefs_show_options(struct seq_file *m, struct dentry *root) static const struct super_operations tracefs_super_operations = { .statfs = simple_statfs, + .destroy_inode = tracefs_destroy_inode, .remount_fs = tracefs_remount, .show_options = tracefs_show_options, }; @@ -393,6 +422,7 @@ struct dentry *tracefs_create_file(const char *name, umode_t mode, { struct dentry *dentry; struct inode *inode; + struct file_operations *proxy_fops; if (!(mode & S_IFMT)) mode |= S_IFREG; @@ -406,8 +436,16 @@ struct dentry *tracefs_create_file(const char *name, umode_t mode, if (unlikely(!inode)) return failed_creating(dentry); + proxy_fops = kzalloc(sizeof(struct file_operations), GFP_KERNEL); + if (!proxy_fops) + return failed_creating(dentry); + + dentry->d_fsdata = fops ? (void *)fops : + (void *)&tracefs_file_operations; + memcpy(proxy_fops, dentry->d_fsdata, sizeof(struct file_operations)); + proxy_fops->open = default_open_file; inode->i_mode = mode; - inode->i_fop = fops ? fops : &tracefs_file_operations; + inode->i_fop = proxy_fops; inode->i_private = data; d_instantiate(dentry, inode); fsnotify_create(dentry->d_parent->d_inode, dentry); -- 2.21.0.392.gf8f6787159e-goog