V1 Remove SELinux dependencies from linux-audit via LSM
Subsystems (2)
RFC PATCH 1/1 V1 Remove SELinux dependencies from linux-audit via LSM
From: Casey Schaufler <[email protected]>
This patch removes SELinux specific code from the kernel auditing system, replacing it with LSM hook invocations that perform the functions appropriate to those behaviors.
The LSM interface is extended to provide interfaces for a module to add audit filters. Interfaces are added to get secids from inodes and ipcs.
The audit code is revised to call these hooks instead of the SELinux functions. This requires some structure definitions to change header files.
The SELinux code is changed to export the old interfaces as LSM hooks instead of doing so directly. The SELinux specific audit filter code has been moved into the SELinux module.
---
I hope for some suggestions regarding how appropriate the header file changes I've made are. My confidence level in them is fairly low. Also, in my haste to get some feedback the testing has been limited. There are three projects (SELinux, audit, and LSM) whose code I've changed, and I expect there may be differences of opinion about what's right, what's wrong, and how to go about reconciling the differences. I see this as the start.
Thank you.
diff -uprN -X linux-2.6.22-base/Documentation/dontdiff linux-2.6.22-base/include/linux/audit.h linux-2.6.22-audit/include/linux/audit.h
--- linux-2.6.22-base/include/linux/audit.h 2007-07-08 16:32:17.000000000 -0700
+++ linux-2.6.22-audit/include/linux/audit.h 2007-08-01 21:55:10.000000000
-0700
@@ -321,20 +321,63 @@ struct audit_rule { /* for AUDIT_LIST,
#ifdef __KERNEL__
#include <linux/sched.h>
-struct audit_sig_info {
- uid_t uid;
- pid_t pid;
- char ctx[0];
-};
-
struct audit_buffer;
struct audit_context;
+struct audit_parent;
struct inode;
struct netlink_skb_parms;
struct linux_binprm;
struct mq_attr;
struct mqstat;
+struct audit_sig_info {
+ uid_t uid;
+ pid_t pid;
+ char ctx[0];
+};
+
+struct audit_watch {
+ atomic_t count; /* reference count */
+ char *path; /* insertion path */
+ dev_t dev; /* associated superblock device */
+ unsigned long ino; /* associated inode number */
+ struct audit_parent *parent; /* associated parent */
+ struct list_head wlist; /* entry in parent->watches list */
+ struct list_head rules; /* associated rules */
+};
+
+struct audit_field {
+ u32 type;
+ u32 val;
+ u32 op;
+ char *se_str;
+ struct selinux_audit_rule *se_rule;
+};
+
+struct audit_krule {
+ int vers_ops;
+ u32 flags;
+ u32 listnr;
+ u32 action;
+ u32 mask[AUDIT_BITMASK_SIZE];
+ u32 buflen; /* for data alloc on list rules */
+ u32 field_count;
+ char *filterkey; /* ties events to rules */
+ struct audit_field *fields;
+ struct audit_field *arch_f; /* quick access to arch field */
+ struct audit_field *inode_f; /* quick access to an inode field */
+ struct audit_watch *watch; /* associated watch */
+ struct list_head rlist; /* entry in audit_watch.rules list */
+};
+
+struct audit_entry {
+ struct list_head list;
+ struct rcu_head rcu;
+ struct audit_krule rule;
+};
+
+extern int audit_rule_update_callout(void); +
#define AUDITSC_INVALID 0
#define AUDITSC_SUCCESS 1
#define AUDITSC_FAILURE 2
diff -uprN -X linux-2.6.22-base/Documentation/dontdiff linux-2.6.22-base/include/linux/security.h linux-2.6.22-audit/include/linux/security.h
--- linux-2.6.22-base/include/linux/security.h 2007-07-08 16:32:17.000000000
-0700
+++ linux-2.6.22-audit/include/linux/security.h 2007-08-01 20:14:18.000000000
-0700
@@ -35,6 +35,8 @@
#include <net/flow.h>
struct ctl_table;
+struct audit_krule;
+struct selinux_audit_rule;
/*
* These functions are in security/capability.c and are used
@@ -1328,6 +1330,16 @@ struct security_operations {
int (*setprocattr)(struct task_struct *p, char *name, void *value, size_t
size);
int (*secid_to_secctx)(u32 secid, char **secdata, u32 *seclen); void (*release_secctx)(char *secdata, u32 seclen);
+ void (*inode_getsecid) (const struct inode *inode, u32 *secid);
+ void (*ipc_getsecid) (struct kern_ipc_perm *p, u32 *secid);
+ int (*audit_rule_supplied) (struct audit_krule *rule);
+ int (*audit_rule_match) (u32 sid, u32 field, u32 op,
+ struct selinux_audit_rule *rule,
+ struct audit_context *actx);
+ int (*audit_rule_init) (u32 field, u32 op, char *rulestr,
+ struct selinux_audit_rule **rule);
+ void (*audit_rule_free) (struct selinux_audit_rule *rule);
+
#ifdef CONFIG_SECURITY_NETWORK
int (*unix_stream_connect) (struct socket * sock,
@@ -2122,6 +2134,44 @@ static inline void security_release_secc
return security_ops->release_secctx(secdata, seclen);
}
+static inline void security_inode_getsecid(const struct inode *inode,
+ u32 *secid)
+{
+ security_ops->inode_getsecid(inode, secid);
+ return;
+}
+
+static inline void security_ipc_getsecid(struct kern_ipc_perm *p, u32 *secid) +{
+ security_ops->ipc_getsecid(p, secid);
+ return;
+}
+
+static inline int security_audit_rule_supplied(struct audit_krule *rule) +{
+ return security_ops->audit_rule_supplied(rule);
+}
+
+static inline int security_audit_rule_match(u32 sid, u32 field, u32 op,
+ struct selinux_audit_rule *rule, + struct audit_context *actx)
+{
+ return security_ops->audit_rule_match(sid, field, op, rule, actx);
+}
+
+static inline int security_audit_rule_init(u32 field, u32 op, char *rulestr,
+ struct selinux_audit_rule **rule)
+{
+ return security_ops->audit_rule_init(field, op, rulestr, rule);
+}
+
+static inline void security_audit_rule_free(struct selinux_audit_rule *rule) +{
+ security_ops->audit_rule_free(rule);
+ return;
+}
+
+
/* prototypes */
extern int security_init (void);
extern int register_security (struct security_operations *ops);
@@ -2796,6 +2846,39 @@ static inline int security_secid_to_secc
static inline void security_release_secctx(char *secdata, u32 seclen) {
}
+
+static inline void security_inode_getsecid(const struct inode *inode,
+ u32 *secid);
+{
+}
+
+static inline void security_ipc_getsecid(struct kern_ipc_perm *p, u32 *secid) +{
+}
+
+static inline int security_audit_rule_supplied(struct audit_krule *rule) +{
+ return 0;
+}
+
+static inline int security_audit_rule_match(u32 sid, u32 field, u32 op,
+ struct selinux_audit_rule *rule,
+ struct audit_context *actx)
+{
+ return;
+}
+
+static inline int security_audit_rule_init(u32 field, u32 op, char *rulestr,
+ struct selinux_audit_rule **rule)
+{
+ return 0;
+}
+
+static inline void security_audit_rule_free(struct selinux_audit_rule *rule) +{
+ return;
+}
+
#endif /* CONFIG_SECURITY */
#ifdef CONFIG_SECURITY_NETWORK
diff -uprN -X linux-2.6.22-base/Documentation/dontdiff linux-2.6.22-base/include/linux/selinux.h linux-2.6.22-audit/include/linux/selinux.h
--- linux-2.6.22-base/include/linux/selinux.h 2007-07-08 16:32:17.000000000
-0700
+++ linux-2.6.22-audit/include/linux/selinux.h 2007-08-01 12:21:16.000000000
-0700
@@ -60,16 +60,6 @@ int selinux_audit_rule_match(u32 sid, u3
struct audit_context *actx);
/**
- * selinux_audit_set_callback - set the callback for policy reloads.
- * @callback: the function to call when the policy is reloaded
- *
- * This sets the function callback function that will update the rules
- * upon policy reloads. This callback should rebuild all existing rules
- * using selinux_audit_rule_init().
- */
-void selinux_audit_set_callback(int (*callback)(void)); -
-/**
* selinux_sid_to_string - map a security context ID to a string * @sid: security context ID to be converted. * @ctx: address of context string to be returned
@@ -151,11 +141,6 @@ static inline int selinux_audit_rule_mat
return 0;
}
-static inline void selinux_audit_set_callback(int (*callback)(void)) -{
- return;
-}
-
static inline int selinux_sid_to_string(u32 sid, char **ctx, u32 *ctxlen)
{
*ctx = NULL;diff -uprN -X linux-2.6.22-base/Documentation/dontdiff linux-2.6.22-base/kernel/audit.c linux-2.6.22-audit/kernel/audit.c
kernel/audit.c +9 -13
@@ -252,7 +252,7 @@ static int audit_set_rate_limit(int limiif (sid) {char *ctx =NULL ;u32 len; -if ((rc =selinux_sid_to_string (sid, &ctx, &len)) ==0 ) { +if ((rc =security_secid_to_secctx (sid, &ctx, &len)) ==0 ) { audit_log(NULL, GFP_KERNEL, AUDIT_CONFIG_CHANGE, "audit_rate_limit=%d old=%d by auid=%u" " subj=%s res=%d",
@@ -287,7 +287,7 @@ static int audit_set_backlog_limit(int lif (sid) {char *ctx =NULL ;u32 len; -if ((rc =selinux_sid_to_string (sid, &ctx, &len)) ==0 ) { +if ((rc =security_secid_to_secctx (sid, &ctx, &len)) ==0 ) { audit_log(NULL, GFP_KERNEL, AUDIT_CONFIG_CHANGE, "audit_backlog_limit=%d old=%d by auid=%u" " subj=%s res=%d",
@@ -325,7 +325,7 @@ static int audit_set_enabled(int state,if (sid) {char *ctx =NULL ;u32 len; -if ((rc =selinux_sid_to_string (sid, &ctx, &len)) ==0 ) { +if ((rc =security_secid_to_secctx (sid, &ctx, &len)) ==0 ) { audit_log(NULL, GFP_KERNEL, AUDIT_CONFIG_CHANGE, "audit_enabled=%d old=%d by auid=%u" " subj=%s res=%d",
@@ -365,7 +365,7 @@ static int audit_set_failure(int state,if (sid) {char *ctx =NULL ;u32 len; -if ((rc =selinux_sid_to_string (sid, &ctx, &len)) ==0 ) { +if ((rc =security_secid_to_secctx (sid, &ctx, &len)) ==0 ) { audit_log(NULL, GFP_KERNEL, AUDIT_CONFIG_CHANGE, "audit_failure=%d old=%d by auid=%u" " subj=%s res=%d",
@@ -590,7 +590,7 @@ static int audit_receive_msg(struct sk_bif (status_get->mask &AUDIT_STATUS_PID ) {int old = audit_pid;if (sid) { -if ((err =selinux_sid_to_string ( +if ((err =security_secid_to_secctx ( sid, &ctx, &len)))return err;else
@@ -628,7 +628,7 @@ static int audit_receive_msg(struct sk_b"user pid=%d uid=%u auid=%u" , pid, uid, loginuid);if (sid) { -if (selinux_sid_to_string ( +if (security_secid_to_secctx ( sid, &ctx, &len)) {audit_log_format (ab," ssid=%u" , sid);
@@ -657,7 +657,7 @@ static int audit_receive_msg(struct sk_b"pid=%d uid=%u auid=%u" , pid, uid, loginuid);if (sid) { -if (selinux_sid_to_string ( +if (security_secid_to_secctx ( sid, &ctx, &len)) {audit_log_format (ab," ssid=%u" , sid);
@@ -691,7 +691,7 @@ static int audit_receive_msg(struct sk_b"pid=%d uid=%u auid=%u" , pid, uid, loginuid);if (sid) { -if (selinux_sid_to_string ( +if (security_secid_to_secctx ( sid, &ctx, &len)) {audit_log_format (ab," ssid=%u" , sid);
@@ -714,7 +714,7 @@ static int audit_receive_msg(struct sk_b loginuid, sid);break ;case AUDIT_SIGNAL_INFO : - err =selinux_sid_to_string (audit_sig_sid, &ctx, &len); + err =security_secid_to_secctx (audit_sig_sid, &ctx, &len);if (err)return err; sig_data =kmalloc (sizeof (*sig_data) + len,GFP_KERNEL );
@@ -805,10 +805,6 @@ static int __init audit_init(void) audit_initialized =1 ; audit_enabled = audit_default; -/* Register the callback with selinux. This callback will be invoked -* when a new policy is loaded. */ -selinux_audit_set_callback (&selinux_audit_rule_update); -audit_log (NULL ,GFP_KERNEL ,AUDIT_KERNEL ,"initialized" );#ifdef CONFIG_AUDITSYSCALL
diff -uprN -X linux-2.6.22-base/Documentation/dontdiff linux-2.6.22-base/kernel/auditfilter.c linux-2.6.22-audit/kernel/auditfilter.c
kernel/auditfilter.c +16 -40
121 lines not on this page · raw message
diff -uprN -X linux-2.6.22-base/Documentation/dontdiff linux-2.6.22-base/kernel/audit.h linux-2.6.22-audit/kernel/audit.h
kernel/audit.h +0 -41
53 lines not on this page · raw message
diff -uprN -X linux-2.6.22-base/Documentation/dontdiff linux-2.6.22-base/kernel/auditsc.c linux-2.6.22-audit/kernel/auditsc.c
kernel/auditsc.c +4 -5
@@ -406,10 +406,10 @@ static int audit_filter_rules(struct taslogged upon error */ if (f->se_rule) {if (need_sid) { -selinux_get_task_sid (tsk, &sid); +security_task_getsecid (tsk, &sid); need_sid =0 ; } - result =selinux_audit_rule_match (sid, f->type, + result =security_audit_rule_match (sid, f->type, f->op, f->se_rule, ctx);
@@ -425,12 +425,12 @@ static int audit_filter_rules(struct tasif (f->se_rule) {/* Find files that match */ if (name) { - result =selinux_audit_rule_match ( + result =security_audit_rule_match ( name->osid, f->type, f->op, f->se_rule, ctx); }else if (ctx) {for (j =0 ; j < ctx->name_count; j++) { -if (selinux_audit_rule_match ( +if (security_audit_rule_match ( ctx->names[j].osid, f->type, f->op, f->se_rule, ctx)) {
@@ -446,7 +446,7 @@ static int audit_filter_rules(struct tas aux = aux->next) {if (aux->type ==AUDIT_IPC ) {struct audit_aux_data_ipcctl *axi = (void *)aux; - if (selinux_audit_rule_match(axi->osid, f->type, f->op, f->se_rule,
ctx)) {
+ if (security_audit_rule_match(axi->osid, f->type, f->op, f->se_rule,
ctx)) {
++result; break;
}
@@ -759,11 +759,11 @@ void audit_log_task_context(struct audit
int error;
u32 sid;
- selinux_get_task_sid(current, &sid);
+ security_task_getsecid(current, &sid);
if (!sid)
return;
- error = selinux_sid_to_string(sid, &ctx, &len);
+ error = security_secid_to_secctx(sid, &ctx, &len);
if (error) {
if (error != -EINVAL)
goto error_path;
@@ -823,7 +823,7 @@ static int audit_log_pid_context(struct
if (!ab)
return 1;
- if (selinux_sid_to_string(sid, &s, &len)) {
+ if (security_secid_to_secctx(sid, &s, &len)) {
audit_log_format(ab, "opid=%d obj=(none)", pid); rc = 1;
} else
@@ -954,7 +954,7 @@ static void audit_log_exit(struct audit_
if (axi->osid != 0) {
char *ctx = NULL;
u32 len;
- if (selinux_sid_to_string(
+ if (security_secid_to_secctx(
axi->osid, &ctx, &len)) {
audit_log_format(ab, " osid=%u",
axi->osid);
@@ -1081,7 +1081,7 @@ static void audit_log_exit(struct audit_
if (n->osid != 0) {
char *ctx = NULL;
u32 len;
- if (selinux_sid_to_string(
+ if (security_secid_to_secctx(
n->osid, &ctx, &len)) { audit_log_format(ab, " osid=%u", n->osid); call_panic = 2;
@@ -1369,7 +1369,7 @@ static void audit_copy_inode(struct audi
name->uid = inode->i_uid; name->gid = inode->i_gid; name->rdev = inode->i_rdev;
- selinux_get_inode_sid(inode, &name->osid);
+ security_inode_getsecid(inode, &name->osid);
}
/**
@@ -1787,7 +1787,7 @@ int __audit_ipc_obj(struct kern_ipc_perm
ax->uid = ipcp->uid;
ax->gid = ipcp->gid;
ax->mode = ipcp->mode;
- selinux_get_ipc_sid(ipcp, &ax->osid);
+ security_ipc_getsecid(ipcp, &ax->osid);
ax->d.type = AUDIT_IPC;
ax->d.next = context->aux;
@@ -1948,7 +1948,7 @@ void __audit_ptrace(struct task_struct *
struct audit_context *context = current->audit_context;
context->target_pid = t->pid;
- selinux_get_task_sid(t, &context->target_sid);
+ security_task_getsecid(t, &context->target_sid);
}
/**
@@ -2005,7 +2005,7 @@ int __audit_signal_info(int sig, struct
audit_sig_uid = ctx->loginuid;
else
audit_sig_uid = tsk->uid;
- selinux_get_task_sid(tsk, &audit_sig_sid);
+ security_task_getsecid(tsk, &audit_sig_sid);
}
if (!audit_signals) /* audit_context checked in wrapper */
@@ -2015,7 +2015,7 @@ int __audit_signal_info(int sig, struct
* in audit_context */
if (!ctx->target_pid) {
ctx->target_pid = t->tgid;
- selinux_get_task_sid(t, &ctx->target_sid);
+ security_task_getsecid(t, &ctx->target_sid);
return 0;
}
@@ -2032,7 +2032,7 @@ int __audit_signal_info(int sig, struct
BUG_ON(axp->pid_count > AUDIT_AUX_PIDS);
axp->target_pid[axp->pid_count] = t->tgid;
- selinux_get_task_sid(t, &axp->target_sid[axp->pid_count]);
+ security_task_getsecid(t, &axp->target_sid[axp->pid_count]);
axp->pid_count++;
return 0;
@@ -2060,12 +2060,12 @@ void audit_core_dumps(long signr)
audit_log_format(ab, "auid=%u uid=%u gid=%u",
audit_get_loginuid(current->audit_context), current->uid, current->gid);
- selinux_get_task_sid(current, &sid);
+ security_task_getsecid(current, &sid);
if (sid) {
char *ctx = NULL;
u32 len;
- if (selinux_sid_to_string(sid, &ctx, &len))
+ if (security_secid_to_secctx(sid, &ctx, &len))
audit_log_format(ab, " ssid=%u", sid);
else
audit_log_format(ab, " subj=%s", ctx);
diff -uprN -X linux-2.6.22-base/Documentation/dontdiff linux-2.6.22-base/security/selinux/hooks.c linux-2.6.22-audit/security/selinux/hooks.c
--- linux-2.6.22-base/security/selinux/hooks.c 2007-07-08 16:32:17.000000000
-0700
+++ linux-2.6.22-audit/security/selinux/hooks.c 2007-08-01 21:42:32.000000000
-0700
@@ -4656,6 +4656,30 @@ static void selinux_release_secctx(char
kfree(secdata);
}
+static int selinux_audit_rule_supplied(struct audit_krule *rule) +{
+ int i;
+
+ for (i = 0; i < rule->field_count; i++) {
+ struct audit_field *f = &rule->fields[i];
+ switch (f->type) {
+ case AUDIT_SUBJ_USER:
+ case AUDIT_SUBJ_ROLE:
+ case AUDIT_SUBJ_TYPE:
+ case AUDIT_SUBJ_SEN:
+ case AUDIT_SUBJ_CLR:
+ case AUDIT_OBJ_USER:
+ case AUDIT_OBJ_ROLE:
+ case AUDIT_OBJ_TYPE:
+ case AUDIT_OBJ_LEV_LOW:
+ case AUDIT_OBJ_LEV_HIGH:
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
#ifdef CONFIG_KEYS
static int selinux_key_alloc(struct key *k, struct task_struct *tsk,
@@ -4838,6 +4862,12 @@ static struct security_operations selinu
.secid_to_secctx = selinux_secid_to_secctx,
.release_secctx = selinux_release_secctx,
+ .inode_getsecid = selinux_get_inode_sid,
+ .ipc_getsecid = selinux_get_ipc_sid,
+ .audit_rule_supplied = selinux_audit_rule_supplied,
+ .audit_rule_match = selinux_audit_rule_match,
+ .audit_rule_init = selinux_audit_rule_init,
+ .audit_rule_free = selinux_audit_rule_free,
.unix_stream_connect = selinux_socket_unix_stream_connect,
.unix_may_send = selinux_socket_unix_may_send,
diff -uprN -X linux-2.6.22-base/Documentation/dontdiff linux-2.6.22-base/security/selinux/ss/services.c linux-2.6.22-audit/security/selinux/ss/services.c
--- linux-2.6.22-base/security/selinux/ss/services.c 2007-07-08
16:32:17.000000000 -0700
+++ linux-2.6.22-audit/security/selinux/ss/services.c 2007-08-01
17:48:17.000000000 -0700
@@ -2214,7 +2214,7 @@ out:
return match;
}
-static int (*aurule_callback)(void) = NULL;
+static int (*aurule_callback)(void) = audit_rule_update_callout;
static int aurule_avc_callback(u32 event, u32 ssid, u32 tsid,
u16 class, u32 perms, u32 *retained)
@@ -2239,11 +2239,6 @@ static int __init aurule_init(void)
}
__initcall(aurule_init);
-void selinux_audit_set_callback(int (*callback)(void)) -{
- aurule_callback = callback;
-}
-
#ifdef CONFIG_NETLABEL
/*
* NetLabel cache structure
Casey Schaufler
[email protected]
Quoted 14 lines · --- Casey Schaufler
From: Casey Schaufler <[email protected]>
This patch removes SELinux specific code from the kernel auditing system, replacing it with LSM hook invocations that perform the functions appropriate to those behaviors.
The LSM interface is extended to provide interfaces for a module to add audit filters. Interfaces are added to get secids from inodes and ipcs.
The audit code is revised to call these hooks instead of the SELinux functions. This requires some structure definitions to change header files.
Quoted 7 lines
The SELinux code is changed to export the old interfaces as LSM hooks instead of doing so directly. The SELinux specific audit filter code has been moved into the SELinux module.
Signed-off-by Casey Schaufler <[email protected]>---
Forgot to include: The patch is relative to 2.6.22.
Casey Schaufler
[email protected]
Quoted 5 lines · Casey Schaufler
From: Casey Schaufler <[email protected]>
This patch removes SELinux specific code from the kernel auditing system, replacing it with LSM hook invocations that perform the functions appropriate to those behaviors.
(patch was whitespace damaged)
Quoted 8 lines
The LSM interface is extended to provide interfaces for a module to add audit filters. Interfaces are added to get secids from inodes and ipcs.
The audit code is revised to call these hooks instead of the SELinux functions. This requires some structure definitions to change header files.
Quoted 7 lines
The SELinux code is changed to export the old interfaces as LSM hooks instead of doing so directly. The SELinux specific audit filter code has been moved into the SELinux module.
Signed-off-by Casey Schaufler <[email protected]>---
Missing diffstat -p1 output.
Quoted 19 lines
I hope for some suggestions regarding how appropriate the header file changes I've made are. My confidence level in them is fairly low. Also, in my haste to get some feedback the testing has been limited. There are three projects (SELinux, audit, and LSM) whose code I've changed, and I expect there may be differences of opinion about what's right, what's wrong, and how to go about reconciling the differences. I see this as the start.
Thank you.
diff -uprN -X linux-2.6.22-base/Documentation/dontdiff
linux-2.6.22-base/include/linux/security.hlinux-2.6.22-audit/include/linux/security.h
---linux-2.6.22-base/include/linux/security.h2007-07-08 16:32:17.000000000
-0700
+++linux-2.6.22-audit/include/linux/security.h2007-08-01 20:14:18.000000000
-0700
Review line 39
Quoted 5 lines
(quoted diff) +2
-0@@ -35,6 +35,8 @@ #include <net/flow.h> struct ctl_table; +struct audit_krule; +struct selinux_audit_rule;
selinux_audit_rule in LSM interface?
Review struct security_operations { · line 1338
Quoted 12 lines
(quoted diff) +5
-0/* * These functions are in security/capability.c and are used@@ -1328,6 +1330,16 @@ struct security_operations { int (*setprocattr)(struct task_struct *p, char *name, void *value, size_t size); int (*secid_to_secctx)(u32 secid, char **secdata, u32 *seclen); void (*release_secctx)(char *secdata, u32 seclen); + void (*inode_getsecid) (const struct inode *inode, u32 *secid); + void (*ipc_getsecid) (struct kern_ipc_perm *p, u32 *secid); + int (*audit_rule_supplied) (struct audit_krule *rule); + int (*audit_rule_match) (u32 sid, u32 field, u32 op, + struct selinux_audit_rule *rule,
Ditto.
Quoted 14 lines
(quoted diff) +5
-0+ struct audit_context *actx); + int (*audit_rule_init) (u32 field, u32 op, char *rulestr, + struct selinux_audit_rule **rule); + void (*audit_rule_free) (struct selinux_audit_rule *rule); + #ifdef CONFIG_SECURITY_NETWORKint (
*unix_stream_connect) (struct socket * sock,diff -uprN -X linux-2.6.22-base/Documentation/dontdiff
linux-2.6.22-base/kernel/audit.clinux-2.6.22-audit/kernel/audit.c
kernel/audit.c static int audit_set_rate_limit(int limi · line 258
Quoted 8 lines
kernel/audit.c +1
-1@@ -252,7 +252,7 @@ static int audit_set_rate_limit(int limiif (sid) {char *ctx =NULL ;u32 len; -if ((rc =selinux_sid_to_string (sid, &ctx, &len)) ==0 ) { +if ((rc =security_secid_to_secctx (sid, &ctx, &len)) ==0 ) { audit_log(NULL, GFP_KERNEL, AUDIT_CONFIG_CHANGE, "audit_rate_limit=%d old=%d by auid=%u" " subj=%s res=%d",
If you do that, then you also need to use security_secctx_release() to free ctx rather than direct kfree.
Also, the sid passed to this (and other functions) came from NETLINK_CB(skb).sid, which was set by netlink_sendmsg() with a direct call to selinux_get_task_sid. So if you convert these calls to using LSM hooks w/o changing netlink to do likewise, you could end up with a mismatch (sid provided by selinux, defaulting to 0 when selinux disabled; secid_to_secctx hook provided by your module).
kernel/auditfilter.c line 32
Quoted 9 lines
diff -uprN -X linux-2.6.22-base/Documentation/dontdiff
linux-2.6.22-base/kernel/auditfilter.clinux-2.6.22-audit/kernel/auditfilter.ckernel/auditfilter.c +1
-0@@ -29,6 +29,7 @@#include <linux/sched.h> #include <linux/inotify.h> #include <linux/selinux.h> +#include <linux/security.h>
Shouldn't you be removing #include <linux/selinux.h> from all of the audit code? That will help you catch all lingering references to selinux-specific references as well.
kernel/auditfilter.c static inline int audit_add_rule(struct · line 1215
Quoted 7 lines
kernel/auditfilter.c +2
-1@@ -1210,7 +1211,8 @@ static inline int audit_add_rule(structstruct audit_entry *e;struct audit_field *inode_f = entry->rule.inode_f;struct audit_watch *watch = entry->rule.watch; -struct nameidata *ndp, *ndw; +struct nameidata *ndp =NULL ; +struct nameidata *ndw =NULL ;
Not related to your changes, and seems to already be present in git (but without splitting into two lines).
Quoted 8 lines
diff -uprN -X linux-2.6.22-base/Documentation/dontdiff
linux-2.6.22-base/security/selinux/hooks.clinux-2.6.22-audit/security/selinux/hooks.c
---linux-2.6.22-base/security/selinux/hooks.c2007-07-08 16:32:17.000000000
-0700
+++linux-2.6.22-audit/security/selinux/hooks.c2007-08-01 21:42:32.000000000
-0700
kernel/auditfilter.c static struct security_operations selinu · line 4870
Quoted 9 lines
kernel/auditfilter.c +6
-0@@ -4838,6 +4862,12 @@ static struct security_operations selinu .secid_to_secctx = selinux_secid_to_secctx, .release_secctx = selinux_release_secctx, + .inode_getsecid = selinux_get_inode_sid, + .ipc_getsecid = selinux_get_ipc_sid, + .audit_rule_supplied = selinux_audit_rule_supplied, + .audit_rule_match = selinux_audit_rule_match, + .audit_rule_init = selinux_audit_rule_init, + .audit_rule_free = selinux_audit_rule_free,
So I'd then expect you to also remove the function prototypes from include/linux/selinux.h unless there is some other caller, and move the functions from selinux/exports.c to selinux/hooks.c and make them static. And drop the selinux_enabled check from them, as the hook function will only be registered if SELinux is enabled.
Signature · 2 lines
Stephen Smalley National Security Agency
Quoted 8 lines · --- Stephen Smalley
Quoted 5 lines · Casey Schaufler
From: Casey Schaufler <[email protected]>
This patch removes SELinux specific code from the kernel auditing system, replacing it with LSM hook invocations that perform the functions appropriate to those behaviors.
(patch was whitespace damaged)
Bugger. I know what I did wrong. Sorry.
Quoted 12 lines
Quoted 12 lines
The LSM interface is extended to provide interfaces for a module to add audit filters. Interfaces are added to get secids from inodes and ipcs.
The audit code is revised to call these hooks instead of the SELinux functions. This requires some structure definitions to change header files.
The SELinux code is changed to export the old interfaces as LSM hooks instead of doing so directly. The SELinux specific audit filter code has been moved into the SELinux module.
Quoted 5 lines
Quoted 3 lines
Signed-off-by Casey Schaufler <[email protected]>---
Missing diffstat -p1 output.
include/linux/audit.h | 55 ++++++++++++++++++++++++--- include/linux/security.h | 83 +++++++++++++++++++++++++++++++++++++++++ include/linux/selinux.h | 15 ------- kernel/audit.c | 22 ++++------ kernel/audit.h | 41 -------------------- kernel/auditfilter.c | 56 +++++++-------------------- kernel/auditsc.c | 36 ++++++++--------- security/selinux/hooks.c | 30 ++++++++++++++ security/selinux/ss/services.c | 7 --- 9 files changed, 206 insertions(+), 139 deletions(-)
Quoted 23 lines
Quoted 8 lines
I hope for some suggestions regarding how appropriate the header file changes I've made are. My confidence level in them is fairly low. Also, in my haste to get some feedback the testing has been limited. There are three projects (SELinux, audit, and LSM) whose code I've changed, and I expect there may be differences of opinion about what's right, what's wrong, and how to go about reconciling the differences. I see this as the start.
Quoted 7 lines
Thank you.
diff -uprN -X linux-2.6.22-base/Documentation/dontdiff
linux-2.6.22-base/include/linux/security.hlinux-2.6.22-audit/include/linux/security.h
---linux-2.6.22-base/include/linux/security.h2007-07-0816:32:17.000000000
Quoted 2 lines
-0700
+++linux-2.6.22-audit/include/linux/security.h2007-08-0120:14:18.000000000
Quoted 4 lines
-0700
(quoted diff) +0
-0@@ -35,6 +35,8 @@ #include <net/flow.h>
Quoted 5 lines
Review line 39
Quoted 3 lines
(quoted diff) +2
-0struct ctl_table; +struct audit_krule; +struct selinux_audit_rule;
selinux_audit_rulein LSM interface?
The structure needs a new name. Any objections to audit_rule_lsm? I'd suggest security_audit_rule, but that doesn't say anything about where to look to see how it gets used.
Quoted 26 lines
Review struct security_operations { · line 1330
Quoted 5 lines
(quoted diff) +0
-0/* * These functions are in security/capability.c and are used@@ -1328,6 +1330,16 @@ struct security_operations { int (*setprocattr)(struct task_struct *p, char *name, void *value,
size_tReview struct security_operations { · line 1338
Quoted 8 lines
(quoted diff) +5
-0size); int (*secid_to_secctx)(u32 secid, char **secdata, u32 *seclen); void (*release_secctx)(char *secdata, u32 seclen); + void (*inode_getsecid) (const struct inode *inode, u32 *secid); + void (*ipc_getsecid) (struct kern_ipc_perm *p, u32 *secid); + int (*audit_rule_supplied) (struct audit_krule *rule); + int (*audit_rule_match) (u32 sid, u32 field, u32 op, + struct selinux_audit_rule *rule,Ditto.
Quoted 8 lines
(quoted diff) +5
-0+ struct audit_context *actx); + int (*audit_rule_init) (u32 field, u32 op, char *rulestr, + struct selinux_audit_rule **rule); + void (*audit_rule_free) (struct selinux_audit_rule *rule); + #ifdef CONFIG_SECURITY_NETWORKint (
*unix_stream_connect) (struct socket * sock,
Quoted 16 lines
kernel/audit.c static int audit_set_rate_limit(int limi · line 258
Quoted 13 lines
diff -uprN -X linux-2.6.22-base/Documentation/dontdiff
linux-2.6.22-base/kernel/audit.clinux-2.6.22-audit/kernel/audit.ckernel/audit.c +1
-1@@ -252,7 +252,7 @@ static int audit_set_rate_limit(int limiif (sid) {char *ctx =NULL ;u32 len; -if ((rc =selinux_sid_to_string (sid, &ctx, &len)) ==0 ) { +if ((rc =security_secid_to_secctx (sid, &ctx, &len)) ==0 ) { audit_log(NULL, GFP_KERNEL, AUDIT_CONFIG_CHANGE, "audit_rate_limit=%d old=%d by auid=%u" " subj=%s res=%d",If you do that, then you also need to use
security_secctx_release()to free ctx rather than direct kfree.
Indeed. Done.
Quoted 6 lines
Also, the sid passed to this (and other functions) came from NETLINK_CB(skb).sid, which was set by
netlink_sendmsg()with a direct call toselinux_get_task_sid. So if you convert these calls to using LSM hooks w/o changing netlink to do likewise, you could end up with a mismatch (sid provided by selinux, defaulting to 0 when selinux disabled;secid_to_secctxhook provided by your module).
Yup. You are correct. Fixed.
Quoted 7 lines
Quoted 2 lines
diff -uprN -X linux-2.6.22-base/Documentation/dontdiff
linux-2.6.22-base/kernel/auditfilter.c
linux-2.6.22-audit/kernel/auditfilter.cQuoted 1 line
---
linux-2.6.22-base/kernel/auditfilter.c2007-07-08 16:32:17.000000000-0700
Quoted 1 line
+++
linux-2.6.22-audit/kernel/auditfilter.c2007-08-01 20:22:36.000000000-0700
Quoted 9 lines
kernel/audit.c line 32
Quoted 5 lines
kernel/audit.c +1
-0@@ -29,6 +29,7 @@#include <linux/sched.h> #include <linux/inotify.h> #include <linux/selinux.h> +#include <linux/security.h> Shouldn't you be removing #include <
linux/selinux.h> from all of the audit code? That will help you catch all lingering references to selinux-specific references as well.
Yes.
Quoted 10 lines
kernel/audit.c static inline int audit_add_rule(struct · line 1215
Quoted 7 lines
kernel/audit.c +2
-1@@ -1210,7 +1211,8 @@ static inline int audit_add_rule(structstruct audit_entry *e;struct audit_field *inode_f = entry->rule.inode_f;struct audit_watch *watch = entry->rule.watch; -struct nameidata *ndp, *ndw; +struct nameidata *ndp =NULL ; +struct nameidata *ndw =NULL ;Not related to your changes, and seems to already be present in git (but without splitting into two lines).
Warnings are bad enough when they're in remote bits of code, when they show up in code I'm whacking on they tend to disappear. I'll put them back together to reduce merge issues.
Quoted 11 lines
Quoted 4 lines
diff -uprN -X linux-2.6.22-base/Documentation/dontdiff
linux-2.6.22-base/security/selinux/hooks.clinux-2.6.22-audit/security/selinux/hooks.c
---linux-2.6.22-base/security/selinux/hooks.c2007-07-0816:32:17.000000000
Quoted 2 lines
-0700
+++linux-2.6.22-audit/security/selinux/hooks.c2007-08-0121:42:32.000000000
Quoted 3 lines
-0700
kernel/audit.c +0
-0@@ -4838,6 +4862,12 @@ static struct security_operations selinu
Quoted 14 lines
kernel/audit.c static struct security_operations selinu · line 4870
Quoted 8 lines
kernel/audit.c +6
-0.secid_to_secctx = selinux_secid_to_secctx, .release_secctx = selinux_release_secctx, + .inode_getsecid = selinux_get_inode_sid, + .ipc_getsecid = selinux_get_ipc_sid, + .audit_rule_supplied = selinux_audit_rule_supplied, + .audit_rule_match = selinux_audit_rule_match, + .audit_rule_init = selinux_audit_rule_init, + .audit_rule_free = selinux_audit_rule_free,So I'd then expect you to also remove the function prototypes from
include/linux/selinux.hunless there is some other caller, and move the functions fromselinux/exports.ctoselinux/hooks.cand make them static. And drop theselinux_enabledcheck from them, as the hook function will only be registered if SELinux is enabled.
If that's the way you'd like the SELinux code arranged, that's what I'll do.
Quoted 3 lines
Signature · 2 lines
Stephen Smalley National Security Agency
Thank you for the helpful comments.
Casey Schaufler
[email protected]
Quoted 18 lines · --- Casey Schaufler
Quoted 12 lines
Quoted 4 lines
diff -uprN -X linux-2.6.22-base/Documentation/dontdiff
linux-2.6.22-base/include/linux/security.hlinux-2.6.22-audit/include/linux/security.h
---linux-2.6.22-base/include/linux/security.h2007-07-0816:32:17.000000000
Quoted 2 lines
-0700
+++linux-2.6.22-audit/include/linux/security.h2007-08-0120:14:18.000000000
Quoted 4 lines
-0700
(quoted diff) +0
-0@@ -35,6 +35,8 @@ #include <net/flow.h>Quoted 5 lines
Review line 39
Quoted 3 lines
(quoted diff) +2
-0struct ctl_table; +struct audit_krule; +struct selinux_audit_rule;
selinux_audit_rulein LSM interface?
Quoted 3 lines
The structure needs a new name. Any objections to
audit_rule_lsm? I'd suggestsecurity_audit_rule, but that doesn't say anything about where to look to see how it gets used.
Actually, it's worse than that because an selinux_audit_rule really is SELinux specific. Any problem with making the security_audit_rule interfaces use a void * ? The audit code appears to be accomodating.
Casey Schaufler
[email protected]
Quoted 20 lines · Casey Schaufler
Quoted 18 lines · --- Casey Schaufler
Quoted 17 lines
Quoted 4 lines
diff -uprN -X linux-2.6.22-base/Documentation/dontdiff
linux-2.6.22-base/include/linux/security.hlinux-2.6.22-audit/include/linux/security.h
---linux-2.6.22-base/include/linux/security.h2007-07-0816:32:17.000000000
Quoted 2 lines
-0700
+++linux-2.6.22-audit/include/linux/security.h2007-08-0120:14:18.000000000
Review line 39
Quoted 7 lines
-0700
(quoted diff) +2
-0@@ -35,6 +35,8 @@ #include <net/flow.h> struct ctl_table; +struct audit_krule; +struct selinux_audit_rule;
selinux_audit_rulein LSM interface?
Quoted 7 lines
Quoted 3 lines
The structure needs a new name. Any objections to
audit_rule_lsm? I'd suggestsecurity_audit_rule, but that doesn't say anything about where to look to see how it gets used.Actually, it's worse than that because an
selinux_audit_rulereally is SELinux specific. Any problem with making thesecurity_audit_ruleinterfaces use a void * ? The audit code appears to be accomodating.
The struct is already opaque outside of the security module, so you can just rename it and implement your own version of the struct in your module.
Signature · 2 lines
Stephen Smalley National Security Agency
Quoted 25 lines · --- Stephen Smalley
Quoted 24 lines · Casey Schaufler
Quoted 21 lines · --- Casey Schaufler
Quoted 12 lines
Quoted 4 lines
diff -uprN -X linux-2.6.22-base/Documentation/dontdiff
linux-2.6.22-base/include/linux/security.hlinux-2.6.22-audit/include/linux/security.h
---linux-2.6.22-base/include/linux/security.h2007-07-0816:32:17.000000000
Quoted 2 lines
-0700
+++linux-2.6.22-audit/include/linux/security.h2007-08-0120:14:18.000000000
Quoted 4 lines
-0700
(quoted diff) +0
-0@@ -35,6 +35,8 @@ #include <net/flow.h>Quoted 5 lines
Review line 39
Quoted 3 lines
(quoted diff) +2
-0struct ctl_table; +struct audit_krule; +struct selinux_audit_rule;
selinux_audit_rulein LSM interface?The structure needs a new name. Any objections to
audit_rule_lsm? I'd suggestsecurity_audit_rule, but that doesn't say anything about where to look to see how it gets used.
Quoted 7 lines
Quoted 3 lines
Actually, it's worse than that because an
selinux_audit_rulereally is SELinux specific. Any problem with making thesecurity_audit_ruleinterfaces use a void * ? The audit code appears to be accomodating.The struct is already opaque outside of the security module, so you can just rename it and implement your own version of the struct in your module.
Oh so true in the module. The LSM interfaces (security_audit_rule_xxx) themselves don't care what it is and it will differ between modules, so a void * seems correct there.
Casey Schaufler
[email protected]