Skip to content

Commit 00aa9d0

Browse files
committed
Merge tag 'apparmor-pr-2022-08-08' of git://git.kernel.org/pub/scm/linux/kernel/git/jj/linux-apparmor
Pull AppArmor updates from John Johansen: "This is mostly cleanups and bug fixes with the one bigger change being Mathew Wilcox's patch to use XArrays instead of the IDR from the thread around the locking weirdness. Features: - Convert secid mapping to XArrays instead of IDR - Add a kernel label to use on kernel objects - Extend policydb permission set by making use of the xbits - Make export of raw binary profile to userspace optional - Enable tuning of policy paranoid load for embedded systems - Don't create raw_sha1 symlink if sha1 hashing is disabled - Allow labels to carry debug flags Cleanups: - Update MAINTAINERS file - Use struct_size() helper in kmalloc() - Move ptrace mediation to more logical task.{h,c} - Resolve uninitialized symbol warnings - Remove redundant ret variable - Mark alloc_unconfined() as static - Update help description of policy hash for introspection - Remove some casts which are no-longer required Bug Fixes: - Fix aa_label_asxprint return check - Fix reference count leak in aa_pivotroot() - Fix memleak in aa_simple_write_to_buffer() - Fix kernel doc comments - Fix absroot causing audited secids to begin with = - Fix quiet_denied for file rules - Fix failed mount permission check error message - Disable showing the mode as part of a secid to secctx - Fix setting unconfined mode on a loaded profile - Fix overlapping attachment computation - Fix undefined reference to `zlib_deflate_workspacesize'" * tag 'apparmor-pr-2022-08-08' of git://git.kernel.org/pub/scm/linux/kernel/git/jj/linux-apparmor: (34 commits) apparmor: Update MAINTAINERS file with new email address apparmor: correct config reference to intended one apparmor: move ptrace mediation to more logical task.{h,c} apparmor: extend policydb permission set by making use of the xbits apparmor: allow label to carry debug flags apparmor: fix overlapping attachment computation apparmor: fix setting unconfined mode on a loaded profile apparmor: Fix some kernel-doc comments apparmor: Mark alloc_unconfined() as static apparmor: disable showing the mode as part of a secid to secctx apparmor: Convert secid mapping to XArrays instead of IDR apparmor: add a kernel label to use on kernel objects apparmor: test: Remove some casts which are no-longer required apparmor: Fix memleak in aa_simple_write_to_buffer() apparmor: fix reference count leak in aa_pivotroot() apparmor: Fix some kernel-doc comments apparmor: Fix undefined reference to `zlib_deflate_workspacesize' apparmor: fix aa_label_asxprint return check apparmor: Fix some kernel-doc comments apparmor: Fix some kernel-doc comments ...
2 parents 0af5cb3 + c269fca commit 00aa9d0

30 files changed

+492
-340
lines changed

MAINTAINERS

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1390,10 +1390,14 @@ F: include/uapi/linux/apm_bios.h
13901390

13911391
APPARMOR SECURITY MODULE
13921392
M: John Johansen <john.johansen@canonical.com>
1393-
L: apparmor@lists.ubuntu.com (subscribers-only, general discussion)
1393+
M: John Johansen <john@apparmor.net>
1394+
L: apparmor@lists.ubuntu.com (moderated for non-subscribers)
13941395
S: Supported
1395-
W: wiki.apparmor.net
1396+
W: apparmor.net
1397+
B: https://gitlab.com/apparmor/apparmor-kernel
1398+
C: irc://irc.oftc.net/apparmor
13961399
T: git git://git.kernel.org/pub/scm/linux/kernel/git/jj/linux-apparmor
1400+
T: https://gitlab.com/apparmor/apparmor-kernel.git
13971401
F: Documentation/admin-guide/LSM/apparmor.rst
13981402
F: security/apparmor/
13991403

security/apparmor/Kconfig

Lines changed: 61 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ config SECURITY_APPARMOR
66
select SECURITY_PATH
77
select SECURITYFS
88
select SECURITY_NETWORK
9-
select ZLIB_INFLATE
10-
select ZLIB_DEFLATE
119
default n
1210
help
1311
This enables the AppArmor security module.
@@ -17,29 +15,6 @@ config SECURITY_APPARMOR
1715

1816
If you are unsure how to answer this question, answer N.
1917

20-
config SECURITY_APPARMOR_HASH
21-
bool "Enable introspection of sha1 hashes for loaded profiles"
22-
depends on SECURITY_APPARMOR
23-
select CRYPTO
24-
select CRYPTO_SHA1
25-
default y
26-
help
27-
This option selects whether introspection of loaded policy
28-
is available to userspace via the apparmor filesystem.
29-
30-
config SECURITY_APPARMOR_HASH_DEFAULT
31-
bool "Enable policy hash introspection by default"
32-
depends on SECURITY_APPARMOR_HASH
33-
default y
34-
help
35-
This option selects whether sha1 hashing of loaded policy
36-
is enabled by default. The generation of sha1 hashes for
37-
loaded policy provide system administrators a quick way
38-
to verify that policy in the kernel matches what is expected,
39-
however it can slow down policy load on some devices. In
40-
these cases policy hashing can be disabled by default and
41-
enabled only if needed.
42-
4318
config SECURITY_APPARMOR_DEBUG
4419
bool "Build AppArmor with debug code"
4520
depends on SECURITY_APPARMOR
@@ -69,6 +44,67 @@ config SECURITY_APPARMOR_DEBUG_MESSAGES
6944
When enabled, various debug messages will be logged to
7045
the kernel message buffer.
7146

47+
config SECURITY_APPARMOR_INTROSPECT_POLICY
48+
bool "Allow loaded policy to be introspected"
49+
depends on SECURITY_APPARMOR
50+
default y
51+
help
52+
This option selects whether introspection of loaded policy
53+
is available to userspace via the apparmor filesystem. This
54+
adds to kernel memory usage. It is required for introspection
55+
of loaded policy, and check point and restore support. It
56+
can be disabled for embedded systems where reducing memory and
57+
cpu is paramount.
58+
59+
config SECURITY_APPARMOR_HASH
60+
bool "Enable introspection of sha1 hashes for loaded profiles"
61+
depends on SECURITY_APPARMOR_INTROSPECT_POLICY
62+
select CRYPTO
63+
select CRYPTO_SHA1
64+
default y
65+
help
66+
This option selects whether introspection of loaded policy
67+
hashes is available to userspace via the apparmor
68+
filesystem. This option provides a light weight means of
69+
checking loaded policy. This option adds to policy load
70+
time and can be disabled for small embedded systems.
71+
72+
config SECURITY_APPARMOR_HASH_DEFAULT
73+
bool "Enable policy hash introspection by default"
74+
depends on SECURITY_APPARMOR_HASH
75+
default y
76+
help
77+
This option selects whether sha1 hashing of loaded policy
78+
is enabled by default. The generation of sha1 hashes for
79+
loaded policy provide system administrators a quick way
80+
to verify that policy in the kernel matches what is expected,
81+
however it can slow down policy load on some devices. In
82+
these cases policy hashing can be disabled by default and
83+
enabled only if needed.
84+
85+
config SECURITY_APPARMOR_EXPORT_BINARY
86+
bool "Allow exporting the raw binary policy"
87+
depends on SECURITY_APPARMOR_INTROSPECT_POLICY
88+
select ZLIB_INFLATE
89+
select ZLIB_DEFLATE
90+
default y
91+
help
92+
This option allows reading back binary policy as it was loaded.
93+
It increases the amount of kernel memory needed by policy and
94+
also increases policy load time. This option is required for
95+
checkpoint and restore support, and debugging of loaded policy.
96+
97+
config SECURITY_APPARMOR_PARANOID_LOAD
98+
bool "Perform full verification of loaded policy"
99+
depends on SECURITY_APPARMOR
100+
default y
101+
help
102+
This options allows controlling whether apparmor does a full
103+
verification of loaded policy. This should not be disabled
104+
except for embedded systems where the image is read only,
105+
includes policy, and has some form of integrity check.
106+
Disabling the check will speed up policy loads.
107+
72108
config SECURITY_APPARMOR_KUNIT_TEST
73109
bool "Build KUnit tests for policy_unpack.c" if !KUNIT_ALL_TESTS
74110
depends on KUNIT=y && SECURITY_APPARMOR

security/apparmor/apparmorfs.c

Lines changed: 58 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "include/policy_ns.h"
3737
#include "include/resource.h"
3838
#include "include/policy_unpack.h"
39+
#include "include/task.h"
3940

4041
/*
4142
* The apparmor filesystem interface used for policy load and introspection
@@ -70,6 +71,7 @@ struct rawdata_f_data {
7071
struct aa_loaddata *loaddata;
7172
};
7273

74+
#ifdef CONFIG_SECURITY_APPARMOR_EXPORT_BINARY
7375
#define RAWDATA_F_DATA_BUF(p) (char *)(p + 1)
7476

7577
static void rawdata_f_data_free(struct rawdata_f_data *private)
@@ -94,9 +96,10 @@ static struct rawdata_f_data *rawdata_f_data_alloc(size_t size)
9496

9597
return ret;
9698
}
99+
#endif
97100

98101
/**
99-
* aa_mangle_name - mangle a profile name to std profile layout form
102+
* mangle_name - mangle a profile name to std profile layout form
100103
* @name: profile name to mangle (NOT NULL)
101104
* @target: buffer to store mangled name, same length as @name (MAYBE NULL)
102105
*
@@ -401,7 +404,7 @@ static struct aa_loaddata *aa_simple_write_to_buffer(const char __user *userbuf,
401404

402405
data->size = copy_size;
403406
if (copy_from_user(data->data, userbuf, copy_size)) {
404-
kvfree(data);
407+
aa_put_loaddata(data);
405408
return ERR_PTR(-EFAULT);
406409
}
407410

@@ -1201,7 +1204,7 @@ SEQ_NS_FOPS(name);
12011204

12021205

12031206
/* policy/raw_data/ * file ops */
1204-
1207+
#ifdef CONFIG_SECURITY_APPARMOR_EXPORT_BINARY
12051208
#define SEQ_RAWDATA_FOPS(NAME) \
12061209
static int seq_rawdata_ ##NAME ##_open(struct inode *inode, struct file *file)\
12071210
{ \
@@ -1294,44 +1297,47 @@ SEQ_RAWDATA_FOPS(compressed_size);
12941297

12951298
static int deflate_decompress(char *src, size_t slen, char *dst, size_t dlen)
12961299
{
1297-
int error;
1298-
struct z_stream_s strm;
1300+
#ifdef CONFIG_SECURITY_APPARMOR_EXPORT_BINARY
1301+
if (aa_g_rawdata_compression_level != 0) {
1302+
int error = 0;
1303+
struct z_stream_s strm;
12991304

1300-
if (aa_g_rawdata_compression_level == 0) {
1301-
if (dlen < slen)
1302-
return -EINVAL;
1303-
memcpy(dst, src, slen);
1304-
return 0;
1305-
}
1305+
memset(&strm, 0, sizeof(strm));
13061306

1307-
memset(&strm, 0, sizeof(strm));
1307+
strm.workspace = kvzalloc(zlib_inflate_workspacesize(), GFP_KERNEL);
1308+
if (!strm.workspace)
1309+
return -ENOMEM;
13081310

1309-
strm.workspace = kvzalloc(zlib_inflate_workspacesize(), GFP_KERNEL);
1310-
if (!strm.workspace)
1311-
return -ENOMEM;
1312-
1313-
strm.next_in = src;
1314-
strm.avail_in = slen;
1311+
strm.next_in = src;
1312+
strm.avail_in = slen;
13151313

1316-
error = zlib_inflateInit(&strm);
1317-
if (error != Z_OK) {
1318-
error = -ENOMEM;
1319-
goto fail_inflate_init;
1320-
}
1314+
error = zlib_inflateInit(&strm);
1315+
if (error != Z_OK) {
1316+
error = -ENOMEM;
1317+
goto fail_inflate_init;
1318+
}
13211319

1322-
strm.next_out = dst;
1323-
strm.avail_out = dlen;
1320+
strm.next_out = dst;
1321+
strm.avail_out = dlen;
13241322

1325-
error = zlib_inflate(&strm, Z_FINISH);
1326-
if (error != Z_STREAM_END)
1327-
error = -EINVAL;
1328-
else
1329-
error = 0;
1323+
error = zlib_inflate(&strm, Z_FINISH);
1324+
if (error != Z_STREAM_END)
1325+
error = -EINVAL;
1326+
else
1327+
error = 0;
13301328

1331-
zlib_inflateEnd(&strm);
1329+
zlib_inflateEnd(&strm);
13321330
fail_inflate_init:
1333-
kvfree(strm.workspace);
1334-
return error;
1331+
kvfree(strm.workspace);
1332+
1333+
return error;
1334+
}
1335+
#endif
1336+
1337+
if (dlen < slen)
1338+
return -EINVAL;
1339+
memcpy(dst, src, slen);
1340+
return 0;
13351341
}
13361342

13371343
static ssize_t rawdata_read(struct file *file, char __user *buf, size_t size,
@@ -1492,10 +1498,12 @@ int __aa_fs_create_rawdata(struct aa_ns *ns, struct aa_loaddata *rawdata)
14921498

14931499
return PTR_ERR(dent);
14941500
}
1501+
#endif /* CONFIG_SECURITY_APPARMOR_EXPORT_BINARY */
1502+
14951503

14961504
/** fns to setup dynamic per profile/namespace files **/
14971505

1498-
/**
1506+
/*
14991507
*
15001508
* Requires: @profile->ns->lock held
15011509
*/
@@ -1522,7 +1530,7 @@ void __aafs_profile_rmdir(struct aa_profile *profile)
15221530
}
15231531
}
15241532

1525-
/**
1533+
/*
15261534
*
15271535
* Requires: @old->ns->lock held
15281536
*/
@@ -1557,6 +1565,7 @@ static struct dentry *create_profile_file(struct dentry *dir, const char *name,
15571565
return dent;
15581566
}
15591567

1568+
#ifdef CONFIG_SECURITY_APPARMOR_EXPORT_BINARY
15601569
static int profile_depth(struct aa_profile *profile)
15611570
{
15621571
int depth = 0;
@@ -1658,7 +1667,7 @@ static const struct inode_operations rawdata_link_abi_iops = {
16581667
static const struct inode_operations rawdata_link_data_iops = {
16591668
.get_link = rawdata_get_link_data,
16601669
};
1661-
1670+
#endif /* CONFIG_SECURITY_APPARMOR_EXPORT_BINARY */
16621671

16631672
/*
16641673
* Requires: @profile->ns->lock held
@@ -1729,15 +1738,17 @@ int __aafs_profile_mkdir(struct aa_profile *profile, struct dentry *parent)
17291738
profile->dents[AAFS_PROF_HASH] = dent;
17301739
}
17311740

1741+
#ifdef CONFIG_SECURITY_APPARMOR_EXPORT_BINARY
17321742
if (profile->rawdata) {
1733-
dent = aafs_create("raw_sha1", S_IFLNK | 0444, dir,
1734-
profile->label.proxy, NULL, NULL,
1735-
&rawdata_link_sha1_iops);
1736-
if (IS_ERR(dent))
1737-
goto fail;
1738-
aa_get_proxy(profile->label.proxy);
1739-
profile->dents[AAFS_PROF_RAW_HASH] = dent;
1740-
1743+
if (aa_g_hash_policy) {
1744+
dent = aafs_create("raw_sha1", S_IFLNK | 0444, dir,
1745+
profile->label.proxy, NULL, NULL,
1746+
&rawdata_link_sha1_iops);
1747+
if (IS_ERR(dent))
1748+
goto fail;
1749+
aa_get_proxy(profile->label.proxy);
1750+
profile->dents[AAFS_PROF_RAW_HASH] = dent;
1751+
}
17411752
dent = aafs_create("raw_abi", S_IFLNK | 0444, dir,
17421753
profile->label.proxy, NULL, NULL,
17431754
&rawdata_link_abi_iops);
@@ -1754,6 +1765,7 @@ int __aafs_profile_mkdir(struct aa_profile *profile, struct dentry *parent)
17541765
aa_get_proxy(profile->label.proxy);
17551766
profile->dents[AAFS_PROF_RAW_DATA] = dent;
17561767
}
1768+
#endif /*CONFIG_SECURITY_APPARMOR_EXPORT_BINARY */
17571769

17581770
list_for_each_entry(child, &profile->base.profiles, base.list) {
17591771
error = __aafs_profile_mkdir(child, prof_child_dir(profile));
@@ -1880,7 +1892,7 @@ static void __aa_fs_list_remove_rawdata(struct aa_ns *ns)
18801892
__aa_fs_remove_rawdata(ent);
18811893
}
18821894

1883-
/**
1895+
/*
18841896
*
18851897
* Requires: @ns->lock held
18861898
*/
@@ -2323,6 +2335,7 @@ static struct aa_sfs_entry aa_sfs_entry_versions[] = {
23232335
AA_SFS_FILE_BOOLEAN("v6", 1),
23242336
AA_SFS_FILE_BOOLEAN("v7", 1),
23252337
AA_SFS_FILE_BOOLEAN("v8", 1),
2338+
AA_SFS_FILE_BOOLEAN("v9", 1),
23262339
{ }
23272340
};
23282341

security/apparmor/audit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ int aa_audit(int type, struct aa_profile *profile, struct common_audit_data *sa,
137137
}
138138
if (AUDIT_MODE(profile) == AUDIT_QUIET ||
139139
(type == AUDIT_APPARMOR_DENIED &&
140-
AUDIT_MODE(profile) == AUDIT_QUIET))
140+
AUDIT_MODE(profile) == AUDIT_QUIET_DENIED))
141141
return aad(sa)->error;
142142

143143
if (KILL_MODE(profile) && type == AUDIT_APPARMOR_DENIED)

security/apparmor/domain.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ static inline unsigned int match_component(struct aa_profile *profile,
119119
* @profile: profile to find perms for
120120
* @label: label to check access permissions for
121121
* @stack: whether this is a stacking request
122-
* @start: state to start match in
122+
* @state: state to start match in
123123
* @subns: whether to do permission checks on components in a subns
124124
* @request: permissions to request
125125
* @perms: perms struct to set
@@ -466,7 +466,7 @@ static struct aa_label *find_attach(const struct linux_binprm *bprm,
466466
* xattrs, or a longer match
467467
*/
468468
candidate = profile;
469-
candidate_len = profile->xmatch_len;
469+
candidate_len = max(count, profile->xmatch_len);
470470
candidate_xattrs = ret;
471471
conflict = false;
472472
}
@@ -1279,7 +1279,6 @@ static int change_profile_perms_wrapper(const char *op, const char *name,
12791279
/**
12801280
* aa_change_profile - perform a one-way profile transition
12811281
* @fqname: name of profile may include namespace (NOT NULL)
1282-
* @onexec: whether this transition is to take place immediately or at exec
12831282
* @flags: flags affecting change behavior
12841283
*
12851284
* Change to new profile @name. Unlike with hats, there is no way

security/apparmor/include/apparmor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ extern enum audit_mode aa_g_audit;
3636
extern bool aa_g_audit_header;
3737
extern bool aa_g_debug;
3838
extern bool aa_g_hash_policy;
39+
extern bool aa_g_export_binary;
3940
extern int aa_g_rawdata_compression_level;
4041
extern bool aa_g_lock_policy;
4142
extern bool aa_g_logsyscall;

0 commit comments

Comments
 (0)