Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp231599ybm; Thu, 28 May 2020 01:05:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzbKQa5L3SGKy2Jge3r66HyD97y4zceN9F0TUIe0+MRNDFsIkQv6hwBwX11IO7XTvRQgxjt X-Received: by 2002:a05:6402:4c6:: with SMTP id n6mr1761540edw.264.1590653118926; Thu, 28 May 2020 01:05:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590653118; cv=none; d=google.com; s=arc-20160816; b=oA32fD1NPy7wcKRgnIcsKtknU26PO75DQKGnWK6fVLofMIxeJT9vn25uOSJEqvmfQx 060NLLWkUfEExubWrz/ep4dr8bNvPNRu4gq5Xt6oklGWoJrtWoMqFf+7+CRaw/I6q5Hh KFNJGBYbbeJN/lepEiXEucR0ZwopkHwhfQdpP/jAUbsji8AthFiQCKPcPyFO32uXrkeB +1vmzzsrrAGNXjLI0VqjdFDY6sBTgSSKs/0bYh9iLVAAYpQueJA7Na3xtV6SjRySDBeD WpydY/KerC1LBMxSTeKbjwRYG2gkmFFHSWu69gH3pc864iZ81apKC+rQmLrmsyNy1CMj yvmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=2lG5L0sAdLO1p6xg9bGhKT7JEJhhPThQZb5Qo3c/f98=; b=zjy+D1AhqADp78Irm+tWm0rtaVMd3R9B3hZlxFE+a3VYO8iBiDatFB8Of7HobkrfTi c18DdO9lywxEjVUKkxWwNTrpNhGtyAfKkfBR59PJ26AnQnFaTQ90WO1vZ2Q8oMrdq6hQ hxoUbXRkFqv6IMcJLZ6OCDXxxjOg7Y3yXAjuHurIesbeY1wNYYilcsz+SDrjFHuXMkbM ByfHPBiaGt3OMf/6VJJ6Fe6qPeCZ3bdVCrWJNj7ieoqzJoxLtUC7P7fCywLeHrhKq2FW MNqWL+BUufW6/Bge1Y25vu8vQ7BhrD8iaHdU4DBo/UJif/zduF8e2qCotq5vEN6wycQC 8dKQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=sony.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z8si3085030ejf.525.2020.05.28.01.04.55; Thu, 28 May 2020 01:05:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=sony.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726086AbgE1IAu (ORCPT + 99 others); Thu, 28 May 2020 04:00:50 -0400 Received: from seldsegrel01.sonyericsson.com ([37.139.156.29]:3526 "EHLO SELDSEGREL01.sonyericsson.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725882AbgE1IAt (ORCPT ); Thu, 28 May 2020 04:00:49 -0400 From: Peter Enderborg To: Greg Kroah-Hartman , , "Rafael J . Wysocki" , Andrew Morton CC: Peter Enderborg Subject: [PATCH] debugfs: Add mount restriction option Date: Thu, 28 May 2020 10:00:31 +0200 Message-ID: <20200528080031.24149-1-peter.enderborg@sony.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain X-SEG-SpamProfiler-Analysis: v=2.3 cv=VdGJw2h9 c=1 sm=1 tr=0 a=Jtaq2Av1iV2Yg7i8w6AGMw==:117 a=sTwFKg_x9MkA:10 a=z6gsHLkEAAAA:8 a=Cn-iF0jY07eQLtR_xsEA:9 a=d-OLMTCWyvARjPbQ-enb:22 X-SEG-SpamProfiler-Score: 0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Since debugfs include sensitive information it need to be treated carefully. But it also has many very useful debug functions for userspace. With this option we can have same configuration for system with need of debugfs and a way to turn it off. It is needed new kernel command line parameter to be activated. Signed-off-by: Peter Enderborg --- fs/debugfs/inode.c | 17 ++++++++++++++++- lib/Kconfig.debug | 10 ++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c index b7f2e971ecbc..bde37dab77e0 100644 --- a/fs/debugfs/inode.c +++ b/fs/debugfs/inode.c @@ -786,10 +786,25 @@ bool debugfs_initialized(void) } EXPORT_SYMBOL_GPL(debugfs_initialized); +static int allow_debugfs; + +static int __init debugfs_kernel(char *str) +{ + if (str && !strcmp(str, "true")) + allow_debugfs = true; + + return 0; + +} +early_param("debugfs", debugfs_kernel); + static int __init debugfs_init(void) { int retval; - +#ifdef CONFIG_DEBUG_FS_MOUNT_RESTRICTED + if (!allow_debugfs) + return -EPERM; +#endif retval = sysfs_create_mount_point(kernel_kobj, "debug"); if (retval) return retval; diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index 21d9c5f6e7ec..d3a3338740d2 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -443,6 +443,16 @@ config DEBUG_FS If unsure, say N. +config DEBUG_FS_MOUNT_RESTRICTED + bool "Debug Filesystem mount restricted" + depends on DEBUG_FS + help + This is an additional restriction for mounting debugfs. It allows + the kernel to have debugfs compiled, but requires that kernel command + line has a debugfs parameter to register as a filesystem. + + If unsure, say N. + source "lib/Kconfig.kgdb" source "lib/Kconfig.ubsan" -- 2.26.2