From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935276AbdEOSXC (ORCPT ); Mon, 15 May 2017 14:23:02 -0400 Received: from mail-pg0-f68.google.com ([74.125.83.68]:35994 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756337AbdEOSW7 (ORCPT ); Mon, 15 May 2017 14:22:59 -0400 From: Sebastien Buisson X-Google-Original-From: Sebastien Buisson To: linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, selinux@tycho.nsa.gov Cc: serge@hallyn.com, james.l.morris@oracle.com, eparis@parisplace.org, sds@tycho.nsa.gov, paul@paul-moore.com, Sebastien Buisson Subject: [PATCH v4 2/2] selinux: expose policy brief via selinuxfs Date: Tue, 16 May 2017 03:22:43 +0900 Message-Id: <1494872563-12467-2-git-send-email-sbuisson@ddn.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1494872563-12467-1-git-send-email-sbuisson@ddn.com> References: <1494872563-12467-1-git-send-email-sbuisson@ddn.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Expose policy brief via selinuxfs. Signed-off-by: Sebastien Buisson --- security/selinux/selinuxfs.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/security/selinux/selinuxfs.c b/security/selinux/selinuxfs.c index e8fe914..2561f96 100644 --- a/security/selinux/selinuxfs.c +++ b/security/selinux/selinuxfs.c @@ -99,6 +99,7 @@ enum sel_inos { SEL_STATUS, /* export current status using mmap() */ SEL_POLICY, /* allow userspace to read the in kernel policy */ SEL_VALIDATE_TRANS, /* compute validatetrans decision */ + SEL_POLICYBRIEF,/* return policy summary */ SEL_INO_NEXT, /* The next inode number to use */ }; @@ -314,6 +315,29 @@ static ssize_t sel_read_policyvers(struct file *filp, char __user *buf, .llseek = generic_file_llseek, }; +static ssize_t sel_read_policybrief(struct file *filp, char __user *buf, + size_t count, loff_t *ppos) +{ + char *tmpbuf; + size_t len; + ssize_t rc; + + rc = security_policydb_brief(&tmpbuf, &len, true); + if (rc) + return rc; + + rc = simple_read_from_buffer(buf, count, ppos, tmpbuf, len); + + kfree(tmpbuf); + + return rc; +} + +static const struct file_operations sel_policybrief_ops = { + .read = sel_read_policybrief, + .llseek = generic_file_llseek, +}; + /* declaration for sel_write_load */ static int sel_make_bools(void); static int sel_make_classes(void); @@ -1827,6 +1851,8 @@ static int sel_fill_super(struct super_block *sb, void *data, int silent) [SEL_POLICY] = {"policy", &sel_policy_ops, S_IRUGO}, [SEL_VALIDATE_TRANS] = {"validatetrans", &sel_transition_ops, S_IWUGO}, + [SEL_POLICYBRIEF] = {"policybrief", &sel_policybrief_ops, + S_IRUGO}, /* last one */ {""} }; ret = simple_fill_super(sb, SELINUX_MAGIC, selinux_files); -- 1.8.3.1