From: serue@us.ibm.com
To: lkml <linux-kernel@vger.kernel.org>
Cc: Chris Wright <chrisw@osdl.org>,
Stephen Smalley <sds@epoch.ncsc.mil>,
James Morris <jmorris@redhat.com>, Andrew Morton <akpm@osdl.org>,
Michael Halcrow <mhalcrow@us.ibm.com>,
David Safford <safford@watson.ibm.com>,
Reiner Sailer <sailer@us.ibm.com>,
Gerrit Huizenga <gh@us.ibm.com>,
Emily Ratliff <emilyr@us.ibm.com>
Subject: [patch 15/15] lsm stacking v0.3: stacking for digsig
Date: Wed, 27 Jul 2005 13:28:48 -0500 [thread overview]
Message-ID: <20050727182848.GP22483@serge.austin.ibm.com> (raw)
In-Reply-To: <20050727181921.GB22483@serge.austin.ibm.com>
Support stacking in digsig. This patch is on top of the cvs version from
www.sf.net/projects/disec.
[Jul 16] Update to support dynamic unloading by freeing
object->security data at unload.
Signed-off-by: Serge Hallyn <serue@us.ibm.com>
--
digsig.c | 142 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 128 insertions(+), 14 deletions(-)
--- digsig/digsig.c 2005-07-06 08:41:38.000000000 -0500
+++ digsig-patched/digsig.c 2005-07-25 16:08:36.000000000 -0500
@@ -33,6 +33,7 @@
#include <linux/fs.h>
#include <asm/uaccess.h>
#include <linux/security.h>
+#include <linux/security-stack.h>
#include <linux/dcache.h>
#include <linux/kobject.h>
#include <linux/mman.h>
@@ -47,6 +48,8 @@
#include "gnupg/mpi/mpi.h"
#include "gnupg/cipher/rsa-verify.h"
+#define DIGSIG_LSM_ID 0x5AA8
+
#ifdef DIGSIG_DEBUG
#define DIGSIG_MODE 0 /*permissive mode */
#define DIGSIG_BENCH 1
@@ -55,11 +58,11 @@
#define DIGSIG_BENCH 0
#endif
-#define get_inode_security(ino) ((unsigned long)(ino->i_security))
-#define set_inode_security(ino,val) (ino->i_security = (void *)val)
-
-#define get_file_security(file) ((unsigned long)(file->f_security))
-#define set_file_security(file,val) (file->f_security = (void *)val)
+struct digsig_ksec {
+ struct security_list lsm_list;
+ struct list_head chain;
+ unsigned count;
+};
unsigned long int total_jiffies = 0;
@@ -82,6 +85,73 @@ int dsi_cache_buckets = 128;
module_param(dsi_cache_buckets, int, 0);
MODULE_PARM_DESC(dsi_cache_buckets, "Number of cache buckets for signatures validations.\n");
+LIST_HEAD(digsig_del_chain);
+DEFINE_SPINLOCK(digsig_chain_lock);
+
+static int get_file_security(struct file *file)
+{
+ struct digsig_ksec *ksec;
+
+ ksec = security_get_value_type(&file->f_security, DIGSIG_LSM_ID,
+ struct digsig_ksec);
+ if (!ksec)
+ return 0;
+ return ksec->count;
+}
+
+static int set_file_security(struct file *file, int v)
+{
+ struct digsig_ksec *ksec;
+
+ ksec = security_get_value_type(&file->f_security, DIGSIG_LSM_ID,
+ struct digsig_ksec);
+ if (!ksec) {
+ ksec = kmalloc(sizeof(struct digsig_ksec), GFP_KERNEL);
+ if (!ksec)
+ return -ENOMEM;
+ INIT_LIST_HEAD(&ksec->chain);
+ spin_lock(&digsig_chain_lock);
+ list_add_rcu(&ksec->chain, &digsig_del_chain);
+ spin_unlock(&digsig_chain_lock);
+ security_add_value_type(&file->f_security, DIGSIG_LSM_ID,
+ ksec);
+ }
+ ksec->count = v;
+ return 0;
+}
+
+
+static int get_inode_security(struct inode *inode)
+{
+ struct digsig_ksec *ksec;
+
+ ksec = security_get_value_type(&inode->i_security, DIGSIG_LSM_ID,
+ struct digsig_ksec);
+ if (!ksec)
+ return 0;
+ return ksec->count;
+}
+
+static int set_inode_security(struct inode *inode, int v)
+{
+ struct digsig_ksec *ksec;
+
+ ksec = security_get_value_type(&inode->i_security, DIGSIG_LSM_ID,
+ struct digsig_ksec);
+ if (!ksec) {
+ ksec = kmalloc(sizeof(struct digsig_ksec), GFP_KERNEL);
+ if (!ksec)
+ return -ENOMEM;
+ INIT_LIST_HEAD(&ksec->chain);
+ spin_lock(&digsig_chain_lock);
+ list_add(&ksec->chain, &digsig_del_chain);
+ spin_unlock(&digsig_chain_lock);
+ security_add_value_type(&inode->i_security, DIGSIG_LSM_ID,
+ ksec);
+ }
+ ksec->count = v;
+ return 0;
+}
/******************************************************************************
Description :
@@ -342,18 +412,22 @@ static int digsig_deny_write_access(stru
{
struct inode *inode = file->f_dentry->d_inode;
unsigned long isec;
+ int err;
spin_lock(&inode->i_lock);
isec = get_inode_security(inode);
if (atomic_read(&inode->i_writecount) > 0) {
- spin_unlock(&inode->i_lock);
- return -ETXTBSY;
+ err = -ETXTBSY;
+ goto out;
}
set_inode_security(inode, (isec+1));
- set_file_security(file, 1);
- spin_unlock(&inode->i_lock);
+ err = set_file_security(file, 1);
+ if (err)
+ set_inode_security(inode, (isec));
- return 0;
+out:
+ spin_unlock(&inode->i_lock);
+ return err;
}
/*
@@ -379,9 +453,17 @@ static void digsig_allow_write_access(st
*/
static void digsig_file_free_security(struct file *file)
{
- if (file->f_security) {
- digsig_allow_write_access(file);
- }
+ struct digsig_ksec *ksec;
+
+ ksec = security_get_value_type(&file->f_security, DIGSIG_LSM_ID,
+ struct digsig_ksec);
+ if (!ksec)
+ return;
+
+ spin_lock(&digsig_chain_lock);
+ list_del(&ksec->chain);
+ spin_unlock(&digsig_chain_lock);
+ kfree(ksec);
}
/**
@@ -530,7 +612,7 @@ static inline int is_unprotected_file(st
__FUNCTION__, file->f_dentry->d_name.name, exec_time); \
}
-static int digsig_file_mmap(struct file * file, unsigned long prot, unsigned long flags)
+static int digsig_file_mmap(struct file * file, unsigned long reqprot, unsigned long prot, unsigned long flags)
{
struct elf64_hdr *elf64_ex;
struct elf32_hdr *elf32_ex;
@@ -668,8 +750,20 @@ static int digsig_file_mmap(struct file
static void digsig_inode_free_security(struct inode *inode)
{
+ struct digsig_ksec *ksec;
+
if (is_cached_signature(inode))
remove_signature(inode);
+
+ ksec = security_del_value_type(&inode->i_security, DIGSIG_LSM_ID,
+ struct digsig_ksec);
+ if (!ksec)
+ return;
+
+ spin_lock(&digsig_chain_lock);
+ list_del(&ksec->chain);
+ spin_unlock(&digsig_chain_lock);
+ kfree(ksec);
}
static struct security_operations digsig_security_ops = {
@@ -715,6 +809,25 @@ out:
return ret;
}
+static void digsig_free_secchain(void)
+{
+ struct digsig_ksec *ksec, *n;
+
+ list_for_each_entry_safe(ksec, n, &digsig_del_chain, chain) {
+ printk(KERN_NOTICE "free_ichain unlinking %u, %d, %lu\n",
+ ksec->count, ksec->lsm_list.security_id,
+ (unsigned long)ksec->lsm_list.list.pprev);
+ security_unlink_value(&ksec->lsm_list.list);
+ }
+
+ synchronize_rcu();
+ list_for_each_entry_safe(ksec, n, &digsig_del_chain, chain) {
+ printk(KERN_NOTICE "free_ichain freeing 1\n");
+ list_del(&ksec->chain);
+ kfree(ksec);
+ }
+}
+
static void __exit digsig_exit_module(void)
{
DSM_PRINT (DEBUG_INIT, "Deinitializing module\n");
@@ -734,6 +847,7 @@ static void __exit digsig_exit_module(vo
digsig_cleanup_sysfs();
digsig_cleanup_revocation();
digsig_cache_cleanup();
+ digsig_free_secchain();
mpi_free(digsig_public_key[0]);
mpi_free(digsig_public_key[1]);
}
next prev parent reply other threads:[~2005-07-27 19:12 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-07-27 18:17 [patch 0/15] lsm stacking v0.3: intro serue
2005-07-27 18:19 ` [patch 1/15] lsm stacking v0.3: introduce securityfs serue
2005-07-27 18:20 ` [patch 2/15] lsm stacking v0.3: add module * to security_ops serue
2005-07-27 18:21 ` [patch 3/15] lsm stacking v0.3: don't default to dummy_##hook serue
2005-07-27 18:23 ` [patch 4/15] lsm stacking v0.3: swith ->security to hlist serue
2005-07-27 18:24 ` [patch 5/15] lsm stacking v0.3: introduce security_*_value API serue
2005-07-27 18:24 ` [patch 6/15] lsm stacking v0.3: stacker documentation serue
2005-07-27 18:24 ` [patch 7/15] lsm stacking v0.3: actual stacker module serue
2005-07-27 18:25 ` [patch 8/15] lsm stacking v0.3: stackable capabilities lsm serue
2005-07-27 18:26 ` [patch 9/15] lsm stacking v0.3: selinux: update ->security structs serue
2005-07-27 18:26 ` [patch 10/15] lsm stacking v0.3: selinux: use security_*_value API serue
2005-07-27 18:27 ` [patch 11/15] lsm stacking v0.3: selinux: remove secondary support serue
2005-07-27 18:27 ` [patch 12/15] lsm stacking v0.3: hook completeness verification script serue
2005-07-27 18:28 ` [patch 13/15] lsm stacking v0.3: seclvl: update for stacking serue
2005-07-27 18:28 ` [patch 14/15] lsm stacking v0.3: fix security_{del,unlink}_value race serue
2005-07-27 18:28 ` serue [this message]
2005-07-27 19:34 ` [patch 0/15] lsm stacking v0.3: intro James Morris
2005-07-27 19:37 ` James Morris
2005-08-03 16:45 ` [PATCH] Stacker - single-use static slots serue
2005-08-03 17:57 ` Chris Wright
2005-08-03 19:27 ` serue
2005-08-03 19:45 ` Chris Wright
2005-08-03 20:31 ` serge
2005-08-05 15:55 ` James Morris
2005-08-05 17:27 ` serue
2005-08-05 17:34 ` serue
2005-08-10 14:45 ` serue
2005-08-11 7:42 ` James Morris
2005-08-11 21:22 ` serue
2005-08-11 23:02 ` James Morris
2005-07-27 19:54 ` [patch 0/15] lsm stacking v0.3: intro serue
2005-07-30 5:07 ` Tony Jones
2005-07-30 19:02 ` serge
2005-07-30 20:18 ` Tony Jones
2005-07-31 3:22 ` Steve Beattie
2005-07-31 3:44 ` serge
2005-07-31 4:13 ` Tony Jones
2005-07-31 13:37 ` serge
2005-07-31 3:53 ` serge
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=20050727182848.GP22483@serge.austin.ibm.com \
--to=serue@us.ibm.com \
--cc=akpm@osdl.org \
--cc=chrisw@osdl.org \
--cc=emilyr@us.ibm.com \
--cc=gh@us.ibm.com \
--cc=jmorris@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mhalcrow@us.ibm.com \
--cc=safford@watson.ibm.com \
--cc=sailer@us.ibm.com \
--cc=sds@epoch.ncsc.mil \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome