Skip to content

Commit 5593a73

Browse files
committed
Merge tag 'apparmor-pr-2021-11-10' of git://git.kernel.org/pub/scm/linux/kernel/git/jj/linux-apparmor
Pull apparmor updates from John Johansen: "Features - use per file locks for transactional queries - update policy management capability checks to work with LSM stacking Bug Fixes: - check/put label on apparmor_sk_clone_security() - fix error check on update of label hname - fix introspection of of task mode for unconfined tasks Cleanups: - avoid -Wempty-body warning - remove duplicated 'Returns:' comments - fix doc warning - remove unneeded one-line hook wrappers - use struct_size() helper in kzalloc() - fix zero-length compiler warning in AA_BUG() - file.h: delete duplicated word - delete repeated words in comments - remove repeated declaration" * tag 'apparmor-pr-2021-11-10' of git://git.kernel.org/pub/scm/linux/kernel/git/jj/linux-apparmor: apparmor: remove duplicated 'Returns:' comments apparmor: remove unneeded one-line hook wrappers apparmor: Use struct_size() helper in kzalloc() apparmor: fix zero-length compiler warning in AA_BUG() apparmor: use per file locks for transactional queries apparmor: fix doc warning apparmor: Remove the repeated declaration apparmor: avoid -Wempty-body warning apparmor: Fix internal policy capable check for policy management apparmor: fix error check security: apparmor: delete repeated words in comments security: apparmor: file.h: delete duplicated word apparmor: switch to apparmor to internal capable check for policy management apparmor: update policy capable checks to use a label apparmor: fix introspection of of task mode for unconfined tasks apparmor: check/put label on apparmor_sk_clone_security()
2 parents dbf4989 + 582122f commit 5593a73

File tree

11 files changed

+90
-66
lines changed

11 files changed

+90
-66
lines changed

security/apparmor/apparmorfs.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -812,8 +812,6 @@ struct multi_transaction {
812812
};
813813

814814
#define MULTI_TRANSACTION_LIMIT (PAGE_SIZE - sizeof(struct multi_transaction))
815-
/* TODO: replace with per file lock */
816-
static DEFINE_SPINLOCK(multi_transaction_lock);
817815

818816
static void multi_transaction_kref(struct kref *kref)
819817
{
@@ -847,10 +845,10 @@ static void multi_transaction_set(struct file *file,
847845
AA_BUG(n > MULTI_TRANSACTION_LIMIT);
848846

849847
new->size = n;
850-
spin_lock(&multi_transaction_lock);
848+
spin_lock(&file->f_lock);
851849
old = (struct multi_transaction *) file->private_data;
852850
file->private_data = new;
853-
spin_unlock(&multi_transaction_lock);
851+
spin_unlock(&file->f_lock);
854852
put_multi_transaction(old);
855853
}
856854

@@ -879,9 +877,10 @@ static ssize_t multi_transaction_read(struct file *file, char __user *buf,
879877
struct multi_transaction *t;
880878
ssize_t ret;
881879

882-
spin_lock(&multi_transaction_lock);
880+
spin_lock(&file->f_lock);
883881
t = get_multi_transaction(file->private_data);
884-
spin_unlock(&multi_transaction_lock);
882+
spin_unlock(&file->f_lock);
883+
885884
if (!t)
886885
return 0;
887886

@@ -1358,7 +1357,7 @@ static int rawdata_open(struct inode *inode, struct file *file)
13581357
struct aa_loaddata *loaddata;
13591358
struct rawdata_f_data *private;
13601359

1361-
if (!policy_view_capable(NULL))
1360+
if (!aa_current_policy_view_capable(NULL))
13621361
return -EACCES;
13631362

13641363
loaddata = __aa_get_loaddata(inode->i_private);
@@ -2114,7 +2113,7 @@ static struct aa_profile *__first_profile(struct aa_ns *root,
21142113

21152114
/**
21162115
* __next_profile - step to the next profile in a profile tree
2117-
* @profile: current profile in tree (NOT NULL)
2116+
* @p: current profile in tree (NOT NULL)
21182117
*
21192118
* Perform a depth first traversal on the profile tree in a namespace
21202119
*
@@ -2265,7 +2264,7 @@ static const struct seq_operations aa_sfs_profiles_op = {
22652264

22662265
static int profiles_open(struct inode *inode, struct file *file)
22672266
{
2268-
if (!policy_view_capable(NULL))
2267+
if (!aa_current_policy_view_capable(NULL))
22692268
return -EACCES;
22702269

22712270
return seq_open(file, &aa_sfs_profiles_op);

security/apparmor/include/file.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ int aa_audit_file(struct aa_profile *profile, struct aa_perms *perms,
167167
* @perms: permission table indexed by the matched state accept entry of @dfa
168168
* @trans: transition table for indexed by named x transitions
169169
*
170-
* File permission are determined by matching a path against @dfa and then
170+
* File permission are determined by matching a path against @dfa and
171171
* then using the value of the accept entry for the matching state as
172172
* an index into @perms. If a named exec transition is required it is
173173
* looked up in the transition table.

security/apparmor/include/label.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,6 @@ struct aa_labelset {
7777
#define __labelset_for_each(LS, N) \
7878
for ((N) = rb_first(&(LS)->root); (N); (N) = rb_next(N))
7979

80-
void aa_labelset_destroy(struct aa_labelset *ls);
81-
void aa_labelset_init(struct aa_labelset *ls);
82-
83-
8480
enum label_flags {
8581
FLAG_HAT = 1, /* profile is a hat */
8682
FLAG_UNCONFINED = 2, /* label unconfined only if all */
@@ -148,6 +144,7 @@ do { \
148144
#define __label_make_stale(X) ((X)->flags |= FLAG_STALE)
149145
#define labels_ns(X) (vec_ns(&((X)->vec[0]), (X)->size))
150146
#define labels_set(X) (&labels_ns(X)->labels)
147+
#define labels_view(X) labels_ns(X)
151148
#define labels_profile(X) ((X)->vec[(X)->size - 1])
152149

153150

security/apparmor/include/lib.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,17 @@
3131

3232
#define AA_WARN(X) WARN((X), "APPARMOR WARN %s: %s\n", __func__, #X)
3333

34-
#define AA_BUG(X, args...) AA_BUG_FMT((X), "" args)
34+
#define AA_BUG(X, args...) \
35+
do { \
36+
_Pragma("GCC diagnostic ignored \"-Wformat-zero-length\""); \
37+
AA_BUG_FMT((X), "" args); \
38+
_Pragma("GCC diagnostic warning \"-Wformat-zero-length\""); \
39+
} while (0)
3540
#ifdef CONFIG_SECURITY_APPARMOR_DEBUG_ASSERTS
3641
#define AA_BUG_FMT(X, fmt, args...) \
3742
WARN((X), "AppArmor WARN %s: (" #X "): " fmt, __func__, ##args)
3843
#else
39-
#define AA_BUG_FMT(X, fmt, args...)
44+
#define AA_BUG_FMT(X, fmt, args...) no_printk(fmt, ##args)
4045
#endif
4146

4247
#define AA_ERROR(fmt, args...) \

security/apparmor/include/policy.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,9 +301,11 @@ static inline int AUDIT_MODE(struct aa_profile *profile)
301301
return profile->audit;
302302
}
303303

304-
bool policy_view_capable(struct aa_ns *ns);
305-
bool policy_admin_capable(struct aa_ns *ns);
304+
bool aa_policy_view_capable(struct aa_label *label, struct aa_ns *ns);
305+
bool aa_policy_admin_capable(struct aa_label *label, struct aa_ns *ns);
306306
int aa_may_manage_policy(struct aa_label *label, struct aa_ns *ns,
307307
u32 mask);
308+
bool aa_current_policy_view_capable(struct aa_ns *ns);
309+
bool aa_current_policy_admin_capable(struct aa_ns *ns);
308310

309311
#endif /* __AA_POLICY_H */

security/apparmor/label.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -425,8 +425,7 @@ struct aa_label *aa_label_alloc(int size, struct aa_proxy *proxy, gfp_t gfp)
425425
AA_BUG(size < 1);
426426

427427
/* + 1 for null terminator entry on vec */
428-
new = kzalloc(sizeof(*new) + sizeof(struct aa_profile *) * (size + 1),
429-
gfp);
428+
new = kzalloc(struct_size(new, vec, size + 1), gfp);
430429
AA_DEBUG("%s (%p)\n", __func__, new);
431430
if (!new)
432431
goto fail;
@@ -1454,7 +1453,7 @@ bool aa_update_label_name(struct aa_ns *ns, struct aa_label *label, gfp_t gfp)
14541453
if (label->hname || labels_ns(label) != ns)
14551454
return res;
14561455

1457-
if (aa_label_acntsxprint(&name, ns, label, FLAGS_NONE, gfp) == -1)
1456+
if (aa_label_acntsxprint(&name, ns, label, FLAGS_NONE, gfp) < 0)
14581457
return res;
14591458

14601459
ls = labels_set(label);
@@ -1704,7 +1703,7 @@ int aa_label_asxprint(char **strp, struct aa_ns *ns, struct aa_label *label,
17041703

17051704
/**
17061705
* aa_label_acntsxprint - allocate a __counted string buffer and print label
1707-
* @strp: buffer to write to. (MAY BE NULL if @size == 0)
1706+
* @strp: buffer to write to.
17081707
* @ns: namespace profile is being viewed from
17091708
* @label: label to view (NOT NULL)
17101709
* @flags: flags controlling what label info is printed

security/apparmor/lsm.c

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,7 +1402,7 @@ static int param_set_aalockpolicy(const char *val, const struct kernel_param *kp
14021402
{
14031403
if (!apparmor_enabled)
14041404
return -EINVAL;
1405-
if (apparmor_initialized && !policy_admin_capable(NULL))
1405+
if (apparmor_initialized && !aa_current_policy_admin_capable(NULL))
14061406
return -EPERM;
14071407
return param_set_bool(val, kp);
14081408
}
@@ -1411,7 +1411,7 @@ static int param_get_aalockpolicy(char *buffer, const struct kernel_param *kp)
14111411
{
14121412
if (!apparmor_enabled)
14131413
return -EINVAL;
1414-
if (apparmor_initialized && !policy_view_capable(NULL))
1414+
if (apparmor_initialized && !aa_current_policy_view_capable(NULL))
14151415
return -EPERM;
14161416
return param_get_bool(buffer, kp);
14171417
}
@@ -1420,7 +1420,7 @@ static int param_set_aabool(const char *val, const struct kernel_param *kp)
14201420
{
14211421
if (!apparmor_enabled)
14221422
return -EINVAL;
1423-
if (apparmor_initialized && !policy_admin_capable(NULL))
1423+
if (apparmor_initialized && !aa_current_policy_admin_capable(NULL))
14241424
return -EPERM;
14251425
return param_set_bool(val, kp);
14261426
}
@@ -1429,7 +1429,7 @@ static int param_get_aabool(char *buffer, const struct kernel_param *kp)
14291429
{
14301430
if (!apparmor_enabled)
14311431
return -EINVAL;
1432-
if (apparmor_initialized && !policy_view_capable(NULL))
1432+
if (apparmor_initialized && !aa_current_policy_view_capable(NULL))
14331433
return -EPERM;
14341434
return param_get_bool(buffer, kp);
14351435
}
@@ -1455,7 +1455,7 @@ static int param_get_aauint(char *buffer, const struct kernel_param *kp)
14551455
{
14561456
if (!apparmor_enabled)
14571457
return -EINVAL;
1458-
if (apparmor_initialized && !policy_view_capable(NULL))
1458+
if (apparmor_initialized && !aa_current_policy_view_capable(NULL))
14591459
return -EPERM;
14601460
return param_get_uint(buffer, kp);
14611461
}
@@ -1526,7 +1526,7 @@ static int param_get_aacompressionlevel(char *buffer,
15261526
{
15271527
if (!apparmor_enabled)
15281528
return -EINVAL;
1529-
if (apparmor_initialized && !policy_view_capable(NULL))
1529+
if (apparmor_initialized && !aa_current_policy_view_capable(NULL))
15301530
return -EPERM;
15311531
return param_get_int(buffer, kp);
15321532
}
@@ -1535,7 +1535,7 @@ static int param_get_audit(char *buffer, const struct kernel_param *kp)
15351535
{
15361536
if (!apparmor_enabled)
15371537
return -EINVAL;
1538-
if (apparmor_initialized && !policy_view_capable(NULL))
1538+
if (apparmor_initialized && !aa_current_policy_view_capable(NULL))
15391539
return -EPERM;
15401540
return sprintf(buffer, "%s", audit_mode_names[aa_g_audit]);
15411541
}
@@ -1548,7 +1548,7 @@ static int param_set_audit(const char *val, const struct kernel_param *kp)
15481548
return -EINVAL;
15491549
if (!val)
15501550
return -EINVAL;
1551-
if (apparmor_initialized && !policy_admin_capable(NULL))
1551+
if (apparmor_initialized && !aa_current_policy_admin_capable(NULL))
15521552
return -EPERM;
15531553

15541554
i = match_string(audit_mode_names, AUDIT_MAX_INDEX, val);
@@ -1563,7 +1563,7 @@ static int param_get_mode(char *buffer, const struct kernel_param *kp)
15631563
{
15641564
if (!apparmor_enabled)
15651565
return -EINVAL;
1566-
if (apparmor_initialized && !policy_view_capable(NULL))
1566+
if (apparmor_initialized && !aa_current_policy_view_capable(NULL))
15671567
return -EPERM;
15681568

15691569
return sprintf(buffer, "%s", aa_profile_mode_names[aa_g_profile_mode]);
@@ -1577,7 +1577,7 @@ static int param_set_mode(const char *val, const struct kernel_param *kp)
15771577
return -EINVAL;
15781578
if (!val)
15791579
return -EINVAL;
1580-
if (apparmor_initialized && !policy_admin_capable(NULL))
1580+
if (apparmor_initialized && !aa_current_policy_admin_capable(NULL))
15811581
return -EPERM;
15821582

15831583
i = match_string(aa_profile_mode_names, APPARMOR_MODE_NAMES_MAX_INDEX,
@@ -1713,7 +1713,7 @@ static int __init alloc_buffers(void)
17131713
static int apparmor_dointvec(struct ctl_table *table, int write,
17141714
void *buffer, size_t *lenp, loff_t *ppos)
17151715
{
1716-
if (!policy_admin_capable(NULL))
1716+
if (!aa_current_policy_admin_capable(NULL))
17171717
return -EPERM;
17181718
if (!apparmor_enabled)
17191719
return -EINVAL;
@@ -1773,32 +1773,16 @@ static unsigned int apparmor_ip_postroute(void *priv,
17731773

17741774
}
17751775

1776-
static unsigned int apparmor_ipv4_postroute(void *priv,
1777-
struct sk_buff *skb,
1778-
const struct nf_hook_state *state)
1779-
{
1780-
return apparmor_ip_postroute(priv, skb, state);
1781-
}
1782-
1783-
#if IS_ENABLED(CONFIG_IPV6)
1784-
static unsigned int apparmor_ipv6_postroute(void *priv,
1785-
struct sk_buff *skb,
1786-
const struct nf_hook_state *state)
1787-
{
1788-
return apparmor_ip_postroute(priv, skb, state);
1789-
}
1790-
#endif
1791-
17921776
static const struct nf_hook_ops apparmor_nf_ops[] = {
17931777
{
1794-
.hook = apparmor_ipv4_postroute,
1778+
.hook = apparmor_ip_postroute,
17951779
.pf = NFPROTO_IPV4,
17961780
.hooknum = NF_INET_POST_ROUTING,
17971781
.priority = NF_IP_PRI_SELINUX_FIRST,
17981782
},
17991783
#if IS_ENABLED(CONFIG_IPV6)
18001784
{
1801-
.hook = apparmor_ipv6_postroute,
1785+
.hook = apparmor_ip_postroute,
18021786
.pf = NFPROTO_IPV6,
18031787
.hooknum = NF_INET_POST_ROUTING,
18041788
.priority = NF_IP6_PRI_SELINUX_FIRST,

security/apparmor/path.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ static int disconnect(const struct path *path, char *buf, char **name,
8383
*
8484
* Returns: %0 else error code if path lookup fails
8585
* When no error the path name is returned in @name which points to
86-
* to a position in @buf
86+
* a position in @buf
8787
*/
8888
static int d_namespace_path(const struct path *path, char *buf, char **name,
8989
int flags, const char *disconnected)

0 commit comments

Comments
 (0)