Skip to content

Commit

Permalink
smack: implement logging V3
Browse files Browse the repository at this point in the history
the following patch, add logging of Smack security decisions.
This is of course very useful to understand what your current smack policy does.
As suggested by Casey, it also now forbids labels with ', " or \

It introduces a '/smack/logging' switch :
0: no logging
1: log denied (default)
2: log accepted
3: log denied&accepted

Signed-off-by: Etienne Basset <[email protected]>
Acked-by: Casey Schaufler <[email protected]>
Acked-by: Eric Paris <[email protected]>
Signed-off-by: James Morris <[email protected]>
  • Loading branch information
ccie6798 authored and James Morris committed Apr 13, 2009
1 parent 6e837fb commit ecfcc53
Show file tree
Hide file tree
Showing 6 changed files with 618 additions and 112 deletions.
20 changes: 18 additions & 2 deletions Documentation/Smack.txt
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,9 @@ length. Single character labels using special characters, that being anything
other than a letter or digit, are reserved for use by the Smack development
team. Smack labels are unstructured, case sensitive, and the only operation
ever performed on them is comparison for equality. Smack labels cannot
contain unprintable characters or the "/" (slash) character. Smack labels
cannot begin with a '-', which is reserved for special options.
contain unprintable characters, the "/" (slash), the "\" (backslash), the "'"
(quote) and '"' (double-quote) characters.
Smack labels cannot begin with a '-', which is reserved for special options.

There are some predefined labels:

Expand Down Expand Up @@ -523,3 +524,18 @@ Smack supports some mount options:

These mount options apply to all file system types.

Smack auditing

If you want Smack auditing of security events, you need to set CONFIG_AUDIT
in your kernel configuration.
By default, all denied events will be audited. You can change this behavior by
writing a single character to the /smack/logging file :
0 : no logging
1 : log denied (default)
2 : log accepted
3 : log denied & accepted

Events are logged as 'key=value' pairs, for each event you at least will get
the subjet, the object, the rights requested, the action, the kernel function
that triggered the event, plus other pairs depending on the type of event
audited.
3 changes: 3 additions & 0 deletions security/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ obj-$(CONFIG_SECURITYFS) += inode.o
# Must precede capability.o in order to stack properly.
obj-$(CONFIG_SECURITY_SELINUX) += selinux/built-in.o
obj-$(CONFIG_SECURITY_SMACK) += smack/built-in.o
ifeq ($(CONFIG_AUDIT),y)
obj-$(CONFIG_SECURITY_SMACK) += lsm_audit.o
endif
obj-$(CONFIG_SECURITY_TOMOYO) += tomoyo/built-in.o
obj-$(CONFIG_SECURITY_ROOTPLUG) += root_plug.o
obj-$(CONFIG_CGROUP_DEVICE) += device_cgroup.o
Expand Down
108 changes: 106 additions & 2 deletions security/smack/smack.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <net/netlabel.h>
#include <linux/list.h>
#include <linux/rculist.h>
#include <linux/lsm_audit.h>

/*
* Why 23? CIPSO is constrained to 30, so a 32 byte buffer is
Expand Down Expand Up @@ -178,6 +179,20 @@ struct smack_known {
#define MAY_READWRITE (MAY_READ | MAY_WRITE)
#define MAY_NOT 0

/*
* Number of access types used by Smack (rwxa)
*/
#define SMK_NUM_ACCESS_TYPE 4

/*
* Smack audit data; is empty if CONFIG_AUDIT not set
* to save some stack
*/
struct smk_audit_info {
#ifdef CONFIG_AUDIT
struct common_audit_data a;
#endif
};
/*
* These functions are in smack_lsm.c
*/
Expand All @@ -186,8 +201,8 @@ struct inode_smack *new_inode_smack(char *);
/*
* These functions are in smack_access.c
*/
int smk_access(char *, char *, int);
int smk_curacc(char *, u32);
int smk_access(char *, char *, int, struct smk_audit_info *);
int smk_curacc(char *, u32, struct smk_audit_info *);
int smack_to_cipso(const char *, struct smack_cipso *);
void smack_from_cipso(u32, char *, char *);
char *smack_from_secid(const u32);
Expand Down Expand Up @@ -237,4 +252,93 @@ static inline char *smk_of_inode(const struct inode *isp)
return sip->smk_inode;
}

/*
* logging functions
*/
#define SMACK_AUDIT_DENIED 0x1
#define SMACK_AUDIT_ACCEPT 0x2
extern int log_policy;

void smack_log(char *subject_label, char *object_label,
int request,
int result, struct smk_audit_info *auditdata);

#ifdef CONFIG_AUDIT

/*
* some inline functions to set up audit data
* they do nothing if CONFIG_AUDIT is not set
*
*/
static inline void smk_ad_init(struct smk_audit_info *a, const char *func,
char type)
{
memset(a, 0, sizeof(*a));
a->a.type = type;
a->a.function = func;
}

static inline void smk_ad_setfield_u_tsk(struct smk_audit_info *a,
struct task_struct *t)
{
a->a.u.tsk = t;
}
static inline void smk_ad_setfield_u_fs_path_dentry(struct smk_audit_info *a,
struct dentry *d)
{
a->a.u.fs.path.dentry = d;
}
static inline void smk_ad_setfield_u_fs_path_mnt(struct smk_audit_info *a,
struct vfsmount *m)
{
a->a.u.fs.path.mnt = m;
}
static inline void smk_ad_setfield_u_fs_inode(struct smk_audit_info *a,
struct inode *i)
{
a->a.u.fs.inode = i;
}
static inline void smk_ad_setfield_u_fs_path(struct smk_audit_info *a,
struct path p)
{
a->a.u.fs.path = p;
}
static inline void smk_ad_setfield_u_net_sk(struct smk_audit_info *a,
struct sock *sk)
{
a->a.u.net.sk = sk;
}

#else /* no AUDIT */

static inline void smk_ad_init(struct smk_audit_info *a, const char *func,
char type)
{
}
static inline void smk_ad_setfield_u_tsk(struct smk_audit_info *a,
struct task_struct *t)
{
}
static inline void smk_ad_setfield_u_fs_path_dentry(struct smk_audit_info *a,
struct dentry *d)
{
}
static inline void smk_ad_setfield_u_fs_path_mnt(struct smk_audit_info *a,
struct vfsmount *m)
{
}
static inline void smk_ad_setfield_u_fs_inode(struct smk_audit_info *a,
struct inode *i)
{
}
static inline void smk_ad_setfield_u_fs_path(struct smk_audit_info *a,
struct path p)
{
}
static inline void smk_ad_setfield_u_net_sk(struct smk_audit_info *a,
struct sock *sk)
{
}
#endif

#endif /* _SECURITY_SMACK_H */
Loading

0 comments on commit ecfcc53

Please sign in to comment.