From patchwork Thu Jan 20 18:01:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Francis Laniel X-Patchwork-Id: 12718943 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 92622C433FE for ; Thu, 20 Jan 2022 18:02:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235579AbiATSCF (ORCPT ); Thu, 20 Jan 2022 13:02:05 -0500 Received: from linux.microsoft.com ([13.77.154.182]:56230 "EHLO linux.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236383AbiATSCE (ORCPT ); Thu, 20 Jan 2022 13:02:04 -0500 Received: from machine.home (lfbn-lyo-1-1484-111.w86-207.abo.wanadoo.fr [86.207.51.111]) by linux.microsoft.com (Postfix) with ESMTPSA id DC8B320B6C63; Thu, 20 Jan 2022 10:02:02 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com DC8B320B6C63 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1642701723; bh=6xz6uaU76DS1ybDsguQGFWxlyQHqLuGZP4ocj7YYaYE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jUcjAgQLc71hgx4OLjRWL9cox0XqQg49FKtuaTicAN2uGZFr5JOV6RNVKo7gNDS60 80V96MZ6rVZMNSMduhjKJQHYCcJKX4CzHU7DtCCEQEXLXopb2uaFK2I6OYCQYFwGvC Py61c28hP/7xcQCX6sd25eutt3tPtlU5/a3htxYg= From: Francis Laniel To: linux-kernel@vger.kernel.org Cc: linux-security-module@vger.kernel.org, Serge Hallyn , Casey Schaufler , Francis Laniel Subject: [RFC PATCH v3 1/2] capability: Add cap_string. Date: Thu, 20 Jan 2022 19:01:15 +0100 Message-Id: <20220120180116.167702-2-flaniel@linux.microsoft.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220120180116.167702-1-flaniel@linux.microsoft.com> References: <20220120180116.167702-1-flaniel@linux.microsoft.com> MIME-Version: 1.0 Precedence: bulk List-ID: This string contains on each line the number of the capability associated to its name. For example, first line is: __stringify(CAP_CHOWN) "\tCAP_CHOWN\n" which the preprocessor will replace by: "0\tCAP_CHOWN\n" Signed-off-by: Francis Laniel --- include/uapi/linux/capability.h | 1 + kernel/capability.c | 45 +++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/include/uapi/linux/capability.h b/include/uapi/linux/capability.h index 463d1ba2232a..115f4fef00da 100644 --- a/include/uapi/linux/capability.h +++ b/include/uapi/linux/capability.h @@ -428,5 +428,6 @@ struct vfs_ns_cap_data { #define CAP_TO_INDEX(x) ((x) >> 5) /* 1 << 5 == bits in __u32 */ #define CAP_TO_MASK(x) (1 << ((x) & 31)) /* mask for indexed __u32 */ +extern const char *cap_string; #endif /* _UAPI_LINUX_CAPABILITY_H */ diff --git a/kernel/capability.c b/kernel/capability.c index 46a361dde042..72b0aece4f81 100644 --- a/kernel/capability.c +++ b/kernel/capability.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -27,6 +28,50 @@ const kernel_cap_t __cap_empty_set = CAP_EMPTY_SET; EXPORT_SYMBOL(__cap_empty_set); +const char *cap_string = + __stringify(CAP_CHOWN) "\tCAP_CHOWN\n" + __stringify(CAP_DAC_OVERRIDE) "\tCAP_DAC_OVERRIDE\n" + __stringify(CAP_DAC_READ_SEARCH) "\tCAP_DAC_READ_SEARCH\n" + __stringify(CAP_FOWNER) "\tCAP_FOWNER\n" + __stringify(CAP_FSETID) "\tCAP_FSETID\n" + __stringify(CAP_KILL) "\tCAP_KILL\n" + __stringify(CAP_SETGID) "\tCAP_SETGID\n" + __stringify(CAP_SETUID) "\tCAP_SETUID\n" + __stringify(CAP_SETPCAP) "\tCAP_SETPCAP\n" + __stringify(CAP_LINUX_IMMUTABLE) "\tCAP_LINUX_IMMUTABLE\n" + __stringify(CAP_NET_BIND_SERVICE) "\tCAP_NET_BIND_SERVICE\n" + __stringify(CAP_NET_BROADCAST) "\tCAP_NET_BROADCAST\n" + __stringify(CAP_NET_ADMIN) "\tCAP_NET_ADMIN\n" + __stringify(CAP_NET_RAW) "\tCAP_NET_RAW\n" + __stringify(CAP_IPC_LOCK) "\tCAP_IPC_LOCK\n" + __stringify(CAP_IPC_OWNER) "\tCAP_IPC_OWNER\n" + __stringify(CAP_SYS_MODULE) "\tCAP_SYS_MODULE\n" + __stringify(CAP_SYS_RAWIO) "\tCAP_SYS_RAWIO\n" + __stringify(CAP_SYS_CHROOT) "\tCAP_SYS_CHROOT\n" + __stringify(CAP_SYS_PTRACE) "\tCAP_SYS_PTRACE\n" + __stringify(CAP_SYS_PACCT) "\tCAP_SYS_PACCT\n" + __stringify(CAP_SYS_ADMIN) "\tCAP_SYS_ADMIN\n" + __stringify(CAP_SYS_BOOT) "\tCAP_SYS_BOOT\n" + __stringify(CAP_SYS_NICE) "\tCAP_SYS_NICE\n" + __stringify(CAP_SYS_RESOURCE) "\tCAP_SYS_RESOURCE\n" + __stringify(CAP_SYS_TIME) "\tCAP_SYS_TIME\n" + __stringify(CAP_SYS_TTY_CONFIG) "\tCAP_SYS_TTY_CONFIG\n" + __stringify(CAP_MKNOD) "\tCAP_MKNOD\n" + __stringify(CAP_LEASE) "\tCAP_LEASE\n" + __stringify(CAP_AUDIT_WRITE) "\tCAP_AUDIT_WRITE\n" + __stringify(CAP_AUDIT_CONTROL) "\tCAP_AUDIT_CONTROL\n" + __stringify(CAP_SETFCAP) "\tCAP_SETFCAP\n" + __stringify(CAP_MAC_OVERRIDE) "\tCAP_MAC_OVERRIDE\n" + __stringify(CAP_MAC_ADMIN) "\tCAP_MAC_ADMIN\n" + __stringify(CAP_SYSLOG) "\tCAP_SYSLOG\n" + __stringify(CAP_WAKE_ALARM) "\tCAP_WAKE_ALARM\n" + __stringify(CAP_BLOCK_SUSPEND) "\tCAP_BLOCK_SUSPEND\n" + __stringify(CAP_AUDIT_READ) "\tCAP_AUDIT_READ\n" + __stringify(CAP_PERFMON) "\tCAP_PERFMON\n" + __stringify(CAP_BPF) "\tCAP_BPF\n" + __stringify(CAP_CHECKPOINT_RESTORE) "\tCAP_CHECKPOINT_RESTORE\n" +; + int file_caps_enabled = 1; static int __init file_caps_disable(char *str) From patchwork Thu Jan 20 18:01:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Francis Laniel X-Patchwork-Id: 12718944 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 46D12C433FE for ; Thu, 20 Jan 2022 18:02:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243664AbiATSCK (ORCPT ); Thu, 20 Jan 2022 13:02:10 -0500 Received: from linux.microsoft.com ([13.77.154.182]:56248 "EHLO linux.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238561AbiATSCG (ORCPT ); Thu, 20 Jan 2022 13:02:06 -0500 Received: from machine.home (lfbn-lyo-1-1484-111.w86-207.abo.wanadoo.fr [86.207.51.111]) by linux.microsoft.com (Postfix) with ESMTPSA id 6652520B8010; Thu, 20 Jan 2022 10:02:05 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 6652520B8010 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1642701726; bh=nw21DXI5tw2hIoJNvKpVyoLMBzMbxA4gDPPYMtT2PCw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fErZozI/eGIYLMHCe7f+RAxe+mi/01XEhEB6ltGDnsh2tq8Avao10gdWhvGQLGhCf 03mkLXghDl+WgV8drRQqDK4sPFqQp2Or/zApz6YDm2FYJgyxJ/ua6ZsEnkQ5a2sQ1c 0sJWt8uHR2silGAkqKy+YPRSQ0n5+H6XdFKyzqrM= From: Francis Laniel To: linux-kernel@vger.kernel.org Cc: linux-security-module@vger.kernel.org, Serge Hallyn , Casey Schaufler , Francis Laniel Subject: [RFC PATCH v3 2/2] security/inode.c: Add capabilities file. Date: Thu, 20 Jan 2022 19:01:16 +0100 Message-Id: <20220120180116.167702-3-flaniel@linux.microsoft.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220120180116.167702-1-flaniel@linux.microsoft.com> References: <20220120180116.167702-1-flaniel@linux.microsoft.com> MIME-Version: 1.0 Precedence: bulk List-ID: This new read-only file prints the capabilities values with their names: cat /sys/kernel/security/capabilities 0 CAP_CHOWN 1 CAP_DAC_OVERRIDE ... 40 CAP_CHECKPOINT_RESTORE Signed-off-by: Francis Laniel --- security/inode.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/security/inode.c b/security/inode.c index 6c326939750d..cef78b497bab 100644 --- a/security/inode.c +++ b/security/inode.c @@ -21,6 +21,7 @@ #include #include #include +#include static struct vfsmount *mount; static int mount_count; @@ -328,6 +329,19 @@ static const struct file_operations lsm_ops = { }; #endif +static struct dentry *capabilities_dentry; +static ssize_t capabilities_read(struct file *unused, char __user *buf, + size_t count, loff_t *ppos) +{ + return simple_read_from_buffer(buf, count, ppos, cap_string, + strlen(cap_string)); +} + +static const struct file_operations capabilities_ops = { + .read = capabilities_read, + .llseek = generic_file_llseek, +}; + static int __init securityfs_init(void) { int retval; @@ -345,6 +359,8 @@ static int __init securityfs_init(void) lsm_dentry = securityfs_create_file("lsm", 0444, NULL, NULL, &lsm_ops); #endif + capabilities_dentry = securityfs("capabilities", 0444, NULL, NULL, + capabilities_ops); return 0; } core_initcall(securityfs_init);