Skip to content

Commit 12557dc

Browse files
committed
apparmor: move lib definitions into separate lib include
Signed-off-by: John Johansen <john.johansen@canonical.com>
1 parent 8486adf commit 12557dc

5 files changed

Lines changed: 99 additions & 82 deletions

File tree

Lines changed: 2 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* AppArmor security module
33
*
4-
* This file contains AppArmor basic global and lib definitions
4+
* This file contains AppArmor basic global
55
*
66
* Copyright (C) 1998-2008 Novell/SUSE
77
* Copyright 2009-2010 Canonical Ltd.
@@ -15,10 +15,7 @@
1515
#ifndef __APPARMOR_H
1616
#define __APPARMOR_H
1717

18-
#include <linux/slab.h>
19-
#include <linux/fs.h>
20-
21-
#include "match.h"
18+
#include <linux/types.h>
2219

2320
/*
2421
* Class of mediation types in the AppArmor policy db
@@ -43,79 +40,4 @@ extern bool aa_g_logsyscall;
4340
extern bool aa_g_paranoid_load;
4441
extern unsigned int aa_g_path_max;
4542

46-
/*
47-
* DEBUG remains global (no per profile flag) since it is mostly used in sysctl
48-
* which is not related to profile accesses.
49-
*/
50-
51-
#define AA_DEBUG(fmt, args...) \
52-
do { \
53-
if (aa_g_debug && printk_ratelimit()) \
54-
printk(KERN_DEBUG "AppArmor: " fmt, ##args); \
55-
} while (0)
56-
57-
#define AA_ERROR(fmt, args...) \
58-
do { \
59-
if (printk_ratelimit()) \
60-
printk(KERN_ERR "AppArmor: " fmt, ##args); \
61-
} while (0)
62-
63-
/* Flag indicating whether initialization completed */
64-
extern int apparmor_initialized __initdata;
65-
66-
/* fn's in lib */
67-
char *aa_split_fqname(char *args, char **ns_name);
68-
void aa_info_message(const char *str);
69-
void *__aa_kvmalloc(size_t size, gfp_t flags);
70-
71-
static inline void *kvmalloc(size_t size)
72-
{
73-
return __aa_kvmalloc(size, 0);
74-
}
75-
76-
static inline void *kvzalloc(size_t size)
77-
{
78-
return __aa_kvmalloc(size, __GFP_ZERO);
79-
}
80-
81-
/* returns 0 if kref not incremented */
82-
static inline int kref_get_not0(struct kref *kref)
83-
{
84-
return atomic_inc_not_zero(&kref->refcount);
85-
}
86-
87-
/**
88-
* aa_strneq - compare null terminated @str to a non null terminated substring
89-
* @str: a null terminated string
90-
* @sub: a substring, not necessarily null terminated
91-
* @len: length of @sub to compare
92-
*
93-
* The @str string must be full consumed for this to be considered a match
94-
*/
95-
static inline bool aa_strneq(const char *str, const char *sub, int len)
96-
{
97-
return !strncmp(str, sub, len) && !str[len];
98-
}
99-
100-
/**
101-
* aa_dfa_null_transition - step to next state after null character
102-
* @dfa: the dfa to match against
103-
* @start: the state of the dfa to start matching in
104-
*
105-
* aa_dfa_null_transition transitions to the next state after a null
106-
* character which is not used in standard matching and is only
107-
* used to separate pairs.
108-
*/
109-
static inline unsigned int aa_dfa_null_transition(struct aa_dfa *dfa,
110-
unsigned int start)
111-
{
112-
/* the null transition only needs the string's null terminator byte */
113-
return aa_dfa_next(dfa, start, 0);
114-
}
115-
116-
static inline bool mediated_filesystem(struct dentry *dentry)
117-
{
118-
return !(dentry->d_sb->s_flags & MS_NOUSER);
119-
}
120-
12143
#endif /* __APPARMOR_H */

‎security/apparmor/include/lib.h‎

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
* AppArmor security module
3+
*
4+
* This file contains AppArmor lib definitions
5+
*
6+
* 2017 Canonical Ltd.
7+
*
8+
* This program is free software; you can redistribute it and/or
9+
* modify it under the terms of the GNU General Public License as
10+
* published by the Free Software Foundation, version 2 of the
11+
* License.
12+
*/
13+
14+
#ifndef __AA_LIB_H
15+
#define __AA_LIB_H
16+
17+
#include <linux/slab.h>
18+
#include <linux/fs.h>
19+
20+
#include "match.h"
21+
22+
/*
23+
* DEBUG remains global (no per profile flag) since it is mostly used in sysctl
24+
* which is not related to profile accesses.
25+
*/
26+
27+
#define AA_DEBUG(fmt, args...) \
28+
do { \
29+
if (aa_g_debug) \
30+
pr_debug_ratelimited("AppArmor: " fmt, ##args); \
31+
} while (0)
32+
33+
#define AA_ERROR(fmt, args...) \
34+
pr_err_ratelimited("AppArmor: " fmt, ##args)
35+
36+
/* Flag indicating whether initialization completed */
37+
extern int apparmor_initialized __initdata;
38+
39+
/* fn's in lib */
40+
char *aa_split_fqname(char *args, char **ns_name);
41+
void aa_info_message(const char *str);
42+
void *__aa_kvmalloc(size_t size, gfp_t flags);
43+
44+
static inline void *kvmalloc(size_t size)
45+
{
46+
return __aa_kvmalloc(size, 0);
47+
}
48+
49+
static inline void *kvzalloc(size_t size)
50+
{
51+
return __aa_kvmalloc(size, __GFP_ZERO);
52+
}
53+
54+
/* returns 0 if kref not incremented */
55+
static inline int kref_get_not0(struct kref *kref)
56+
{
57+
return atomic_inc_not_zero(&kref->refcount);
58+
}
59+
60+
/**
61+
* aa_strneq - compare null terminated @str to a non null terminated substring
62+
* @str: a null terminated string
63+
* @sub: a substring, not necessarily null terminated
64+
* @len: length of @sub to compare
65+
*
66+
* The @str string must be full consumed for this to be considered a match
67+
*/
68+
static inline bool aa_strneq(const char *str, const char *sub, int len)
69+
{
70+
return !strncmp(str, sub, len) && !str[len];
71+
}
72+
73+
/**
74+
* aa_dfa_null_transition - step to next state after null character
75+
* @dfa: the dfa to match against
76+
* @start: the state of the dfa to start matching in
77+
*
78+
* aa_dfa_null_transition transitions to the next state after a null
79+
* character which is not used in standard matching and is only
80+
* used to separate pairs.
81+
*/
82+
static inline unsigned int aa_dfa_null_transition(struct aa_dfa *dfa,
83+
unsigned int start)
84+
{
85+
/* the null transition only needs the string's null terminator byte */
86+
return aa_dfa_next(dfa, start, 0);
87+
}
88+
89+
static inline bool mediated_filesystem(struct dentry *dentry)
90+
{
91+
return !(dentry->d_sb->s_flags & MS_NOUSER);
92+
}
93+
94+
#endif /* AA_LIB_H */

‎security/apparmor/include/policy.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "capability.h"
2828
#include "domain.h"
2929
#include "file.h"
30+
#include "lib.h"
3031
#include "resource.h"
3132

3233
extern const char *const aa_profile_mode_names[];

‎security/apparmor/lib.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
#include "include/audit.h"
2121
#include "include/apparmor.h"
22-
22+
#include "include/lib.h"
2323

2424
/**
2525
* aa_split_fqname - split a fqname into a profile and namespace name

‎security/apparmor/match.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include <linux/err.h>
2121
#include <linux/kref.h>
2222

23-
#include "include/apparmor.h"
23+
#include "include/lib.h"
2424
#include "include/match.h"
2525

2626
#define base_idx(X) ((X) & 0xffffff)

0 commit comments

Comments
 (0)