Skip to content

Commit ecfcc53

Browse files
ccie6798xjamesmorris
authored andcommitted
smack: implement logging V3
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 <etienne.basset@numericable.fr> Acked-by: Casey Schaufler <casey@schaufler-ca.com> Acked-by: Eric Paris <eparis@redhat.com> Signed-off-by: James Morris <jmorris@namei.org>
1 parent 6e837fb commit ecfcc53

6 files changed

Lines changed: 618 additions & 112 deletions

File tree

‎Documentation/Smack.txt‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,9 @@ length. Single character labels using special characters, that being anything
184184
other than a letter or digit, are reserved for use by the Smack development
185185
team. Smack labels are unstructured, case sensitive, and the only operation
186186
ever performed on them is comparison for equality. Smack labels cannot
187-
contain unprintable characters or the "/" (slash) character. Smack labels
188-
cannot begin with a '-', which is reserved for special options.
187+
contain unprintable characters, the "/" (slash), the "\" (backslash), the "'"
188+
(quote) and '"' (double-quote) characters.
189+
Smack labels cannot begin with a '-', which is reserved for special options.
189190

190191
There are some predefined labels:
191192

@@ -523,3 +524,18 @@ Smack supports some mount options:
523524

524525
These mount options apply to all file system types.
525526

527+
Smack auditing
528+
529+
If you want Smack auditing of security events, you need to set CONFIG_AUDIT
530+
in your kernel configuration.
531+
By default, all denied events will be audited. You can change this behavior by
532+
writing a single character to the /smack/logging file :
533+
0 : no logging
534+
1 : log denied (default)
535+
2 : log accepted
536+
3 : log denied & accepted
537+
538+
Events are logged as 'key=value' pairs, for each event you at least will get
539+
the subjet, the object, the rights requested, the action, the kernel function
540+
that triggered the event, plus other pairs depending on the type of event
541+
audited.

‎security/Makefile‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ obj-$(CONFIG_SECURITYFS) += inode.o
1616
# Must precede capability.o in order to stack properly.
1717
obj-$(CONFIG_SECURITY_SELINUX) += selinux/built-in.o
1818
obj-$(CONFIG_SECURITY_SMACK) += smack/built-in.o
19+
ifeq ($(CONFIG_AUDIT),y)
20+
obj-$(CONFIG_SECURITY_SMACK) += lsm_audit.o
21+
endif
1922
obj-$(CONFIG_SECURITY_TOMOYO) += tomoyo/built-in.o
2023
obj-$(CONFIG_SECURITY_ROOTPLUG) += root_plug.o
2124
obj-$(CONFIG_CGROUP_DEVICE) += device_cgroup.o

‎security/smack/smack.h‎

Lines changed: 106 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <net/netlabel.h>
2121
#include <linux/list.h>
2222
#include <linux/rculist.h>
23+
#include <linux/lsm_audit.h>
2324

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

182+
/*
183+
* Number of access types used by Smack (rwxa)
184+
*/
185+
#define SMK_NUM_ACCESS_TYPE 4
186+
187+
/*
188+
* Smack audit data; is empty if CONFIG_AUDIT not set
189+
* to save some stack
190+
*/
191+
struct smk_audit_info {
192+
#ifdef CONFIG_AUDIT
193+
struct common_audit_data a;
194+
#endif
195+
};
181196
/*
182197
* These functions are in smack_lsm.c
183198
*/
@@ -186,8 +201,8 @@ struct inode_smack *new_inode_smack(char *);
186201
/*
187202
* These functions are in smack_access.c
188203
*/
189-
int smk_access(char *, char *, int);
190-
int smk_curacc(char *, u32);
204+
int smk_access(char *, char *, int, struct smk_audit_info *);
205+
int smk_curacc(char *, u32, struct smk_audit_info *);
191206
int smack_to_cipso(const char *, struct smack_cipso *);
192207
void smack_from_cipso(u32, char *, char *);
193208
char *smack_from_secid(const u32);
@@ -237,4 +252,93 @@ static inline char *smk_of_inode(const struct inode *isp)
237252
return sip->smk_inode;
238253
}
239254

255+
/*
256+
* logging functions
257+
*/
258+
#define SMACK_AUDIT_DENIED 0x1
259+
#define SMACK_AUDIT_ACCEPT 0x2
260+
extern int log_policy;
261+
262+
void smack_log(char *subject_label, char *object_label,
263+
int request,
264+
int result, struct smk_audit_info *auditdata);
265+
266+
#ifdef CONFIG_AUDIT
267+
268+
/*
269+
* some inline functions to set up audit data
270+
* they do nothing if CONFIG_AUDIT is not set
271+
*
272+
*/
273+
static inline void smk_ad_init(struct smk_audit_info *a, const char *func,
274+
char type)
275+
{
276+
memset(a, 0, sizeof(*a));
277+
a->a.type = type;
278+
a->a.function = func;
279+
}
280+
281+
static inline void smk_ad_setfield_u_tsk(struct smk_audit_info *a,
282+
struct task_struct *t)
283+
{
284+
a->a.u.tsk = t;
285+
}
286+
static inline void smk_ad_setfield_u_fs_path_dentry(struct smk_audit_info *a,
287+
struct dentry *d)
288+
{
289+
a->a.u.fs.path.dentry = d;
290+
}
291+
static inline void smk_ad_setfield_u_fs_path_mnt(struct smk_audit_info *a,
292+
struct vfsmount *m)
293+
{
294+
a->a.u.fs.path.mnt = m;
295+
}
296+
static inline void smk_ad_setfield_u_fs_inode(struct smk_audit_info *a,
297+
struct inode *i)
298+
{
299+
a->a.u.fs.inode = i;
300+
}
301+
static inline void smk_ad_setfield_u_fs_path(struct smk_audit_info *a,
302+
struct path p)
303+
{
304+
a->a.u.fs.path = p;
305+
}
306+
static inline void smk_ad_setfield_u_net_sk(struct smk_audit_info *a,
307+
struct sock *sk)
308+
{
309+
a->a.u.net.sk = sk;
310+
}
311+
312+
#else /* no AUDIT */
313+
314+
static inline void smk_ad_init(struct smk_audit_info *a, const char *func,
315+
char type)
316+
{
317+
}
318+
static inline void smk_ad_setfield_u_tsk(struct smk_audit_info *a,
319+
struct task_struct *t)
320+
{
321+
}
322+
static inline void smk_ad_setfield_u_fs_path_dentry(struct smk_audit_info *a,
323+
struct dentry *d)
324+
{
325+
}
326+
static inline void smk_ad_setfield_u_fs_path_mnt(struct smk_audit_info *a,
327+
struct vfsmount *m)
328+
{
329+
}
330+
static inline void smk_ad_setfield_u_fs_inode(struct smk_audit_info *a,
331+
struct inode *i)
332+
{
333+
}
334+
static inline void smk_ad_setfield_u_fs_path(struct smk_audit_info *a,
335+
struct path p)
336+
{
337+
}
338+
static inline void smk_ad_setfield_u_net_sk(struct smk_audit_info *a,
339+
struct sock *sk)
340+
{
341+
}
342+
#endif
343+
240344
#endif /* _SECURITY_SMACK_H */

0 commit comments

Comments
 (0)