From: Francis Laniel <flaniel@linux.microsoft.com>
To: linux-kernel@vger.kernel.org
Cc: Serge Hallyn <serge@hallyn.com>,
linux-security-module@vger.kernel.org,
Francis Laniel <flaniel@linux.microsoft.com>
Subject: [RFC PATCH v1 2/2] kernel/ksysfs.c: Add capabilities attribute.
Date: Mon, 27 Dec 2021 21:55:00 +0100 [thread overview]
Message-ID: <20211227205500.214777-3-flaniel@linux.microsoft.com> (raw)
In-Reply-To: <20211227205500.214777-1-flaniel@linux.microsoft.com>
This new read-only attribute prints the capabilities values with their names:
0 CAP_CHOWN
1 CAP_DAC_OVERRIDE
...
39 CAP_BPF
Signed-off-by: Francis Laniel <flaniel@linux.microsoft.com>
---
kernel/ksysfs.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
index 35859da8bd4f..7d39794a55bc 100644
--- a/kernel/ksysfs.c
+++ b/kernel/ksysfs.c
@@ -182,6 +182,23 @@ static ssize_t rcu_normal_store(struct kobject *kobj,
KERNEL_ATTR_RW(rcu_normal);
#endif /* #ifndef CONFIG_TINY_RCU */
+static ssize_t capabilities_show(struct kobject *unused0,
+ struct kobj_attribute *unused1, char *buf)
+{
+ int at = 0;
+ int i;
+
+ for (i = 0; i < CAP_LAST_CAP; i++) {
+ if (at >= PAGE_SIZE)
+ return at;
+
+ at += sysfs_emit_at(buf, at, "%d\t%s\n", i, cap_strings[i]);
+ }
+
+ return at;
+}
+KERNEL_ATTR_RO(capabilities);
+
/*
* Make /sys/kernel/notes give the raw contents of our kernel .notes section.
*/
@@ -229,6 +246,7 @@ static struct attribute * kernel_attrs[] = {
&rcu_expedited_attr.attr,
&rcu_normal_attr.attr,
#endif
+ &capabilities_attr.attr,
NULL
};
--
2.30.2
next prev parent reply other threads:[~2021-12-27 20:55 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-27 20:54 [RFC PATCH v1 0/2] Add capabilities file to sysfs Francis Laniel
2021-12-27 20:54 ` [RFC PATCH v1 1/2] capability: Add cap_strings Francis Laniel
2021-12-27 22:26 ` Casey Schaufler
2021-12-28 13:27 ` Francis Laniel
2022-01-14 0:39 ` Serge E. Hallyn
2022-01-17 14:14 ` Francis Laniel
2021-12-27 20:55 ` Francis Laniel [this message]
2021-12-27 22:22 ` [RFC PATCH v1 0/2] Add capabilities file to sysfs Casey Schaufler
2021-12-28 13:34 ` Francis Laniel
2021-12-29 1:26 ` Casey Schaufler
2021-12-29 20:56 ` Francis Laniel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211227205500.214777-3-flaniel@linux.microsoft.com \
--to=flaniel@linux.microsoft.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=serge@hallyn.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.