Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3357380pxb; Mon, 17 Jan 2022 18:29:34 -0800 (PST) X-Google-Smtp-Source: ABdhPJw1fh6nCZvuyU0NqJJr4UOw/NJVOC4DvthiIpLBPqO4JGpnPc7burHiLMdhn29d4ZPiI7vf X-Received: by 2002:a63:2c4a:: with SMTP id s71mr21660668pgs.97.1642472974282; Mon, 17 Jan 2022 18:29:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642472974; cv=none; d=google.com; s=arc-20160816; b=S7zvG27SOABgrTXW1V8C3XY1AULxWbd47LgmeliJo8oSs+9gXLkBU9pAW9xBaPiKEw pcLx1TdD54VxtxKO/ovp+IQfYSRTI7UAYQPYRzkBYehguDIGPFQxZKF7Shfuv2elKU9m SSloTpxG6FkdUJjyjPGyju0vrxjcu+XopUu5oa55EYuFaNXJ5uZ1vMlQytxgfkbWH1jq PLwfQJsmUQ+s4v4JhaGdqPWOHTm/HEGktpWdo0CwkVzov1UKY3KJJp/2aZInh3gdf6IH n9HDqvVYb0e3+ZiYrgs5CItB9+axIEedvd7Oin3ycqnunrn5cFuP60/X5jrhc2/f99EL zvzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=21h2IU25StSfVm+H1A8EsuYeCqu3xLP7bthO+pzdaTY=; b=wvKRLTivJsa+wqSooluGN68OZg8oamDE+zT+apZI1/gKc14CWRK/4QGwg/SHCFjii+ PdcHGVoQFFNIkYHgt8E7hVoZEqsXJKpIwf2DNcf9oyZU1H95z3+VwnyVRYIXQN/1FFHb 80nq/q9N+KOHp3OH3i5VE4mOgMvMJH5D21oJj5GpsfjAKLX2uRC6RRDaO/sgweMG6T12 WXpRBA1EUyv3Rm2GxUHYsB1tjIDe7qpB8doOFvQEzw2SVngVgxsPFLB2pKJXPGwmTXbK TZNhBsvYSC5Yg7SiCqrifEwDvDalhmSZqf5x2DjBqEe/bnSwZ3wwxe2YV38/+d340sod Feig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=XvJHVtjv; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o8si16513873pgq.15.2022.01.17.18.29.22; Mon, 17 Jan 2022 18:29:34 -0800 (PST) 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; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=XvJHVtjv; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238061AbiAQONd (ORCPT + 99 others); Mon, 17 Jan 2022 09:13:33 -0500 Received: from linux.microsoft.com ([13.77.154.182]:54228 "EHLO linux.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236448AbiAQON0 (ORCPT ); Mon, 17 Jan 2022 09:13:26 -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 ED07A20B9135; Mon, 17 Jan 2022 06:13:23 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com ED07A20B9135 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1642428805; bh=21h2IU25StSfVm+H1A8EsuYeCqu3xLP7bthO+pzdaTY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XvJHVtjvEb0KCB6u4zmB6B/NN5V6AUu3oGF6oUeP9RdOl/s/OBkjgfxXJtrjS4NKH cGBRcG4rjxZZqATKDRhmg3eGQAPfGCEaHq68w10ow8miw+8RfepegGUCmAFVUsUvrH CD65BJ8AdGT9EWPAb6J5lXasZkdocfzUrLoRvVFc= 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 v2 2/2] kernel/ksysfs.c: Add capabilities attribute. Date: Mon, 17 Jan 2022 15:12:54 +0100 Message-Id: <20220117141254.46278-3-flaniel@linux.microsoft.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220117141254.46278-1-flaniel@linux.microsoft.com> References: <20220117141254.46278-1-flaniel@linux.microsoft.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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