Skip to content

Commit 317d9a0

Browse files
committed
apparmor: update query interface to support label queries
Signed-off-by: John Johansen <[email protected]>
1 parent 76a1d26 commit 317d9a0

File tree

1 file changed

+39
-7
lines changed

1 file changed

+39
-7
lines changed

security/apparmor/apparmorfs.c

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "include/context.h"
3434
#include "include/crypto.h"
3535
#include "include/policy_ns.h"
36+
#include "include/label.h"
3637
#include "include/policy.h"
3738
#include "include/policy_ns.h"
3839
#include "include/resource.h"
@@ -629,6 +630,7 @@ static void profile_query_cb(struct aa_profile *profile, struct aa_perms *perms,
629630
tmp = nullperms;
630631
}
631632
aa_apply_modes_to_perms(profile, &tmp);
633+
aa_perms_accum_raw(perms, &tmp);
632634
}
633635

634636

@@ -655,7 +657,9 @@ static ssize_t query_data(char *buf, size_t buf_len,
655657
{
656658
char *out;
657659
const char *key;
660+
struct label_it i;
658661
struct aa_label *label, *curr;
662+
struct aa_profile *profile;
659663
struct aa_data *data;
660664
u32 bytes, blocks;
661665
__le32 outle32;
@@ -690,13 +694,16 @@ static ssize_t query_data(char *buf, size_t buf_len,
690694
out = buf + sizeof(bytes) + sizeof(blocks);
691695

692696
blocks = 0;
693-
if (labels_profile(label)->data) {
694-
data = rhashtable_lookup_fast(labels_profile(label)->data, &key,
695-
labels_profile(label)->data->p);
697+
label_for_each_confined(i, label, profile) {
698+
if (!profile->data)
699+
continue;
700+
701+
data = rhashtable_lookup_fast(profile->data, &key,
702+
profile->data->p);
696703

697704
if (data) {
698-
if (out + sizeof(outle32) + data->size >
699-
buf + buf_len) {
705+
if (out + sizeof(outle32) + data->size > buf +
706+
buf_len) {
700707
aa_put_label(label);
701708
return -EINVAL; /* not enough space */
702709
}
@@ -741,10 +748,12 @@ static ssize_t query_data(char *buf, size_t buf_len,
741748
static ssize_t query_label(char *buf, size_t buf_len,
742749
char *query, size_t query_len, bool view_only)
743750
{
751+
struct aa_profile *profile;
744752
struct aa_label *label, *curr;
745753
char *label_name, *match_str;
746754
size_t label_name_len, match_len;
747755
struct aa_perms perms;
756+
struct label_it i;
748757

749758
if (!query_len)
750759
return -EINVAL;
@@ -770,7 +779,16 @@ static ssize_t query_label(char *buf, size_t buf_len,
770779
return PTR_ERR(label);
771780

772781
perms = allperms;
773-
profile_query_cb(labels_profile(label), &perms, match_str, match_len);
782+
if (view_only) {
783+
label_for_each_in_ns(i, labels_ns(label), label, profile) {
784+
profile_query_cb(profile, &perms, match_str, match_len);
785+
}
786+
} else {
787+
label_for_each(i, label, profile) {
788+
profile_query_cb(profile, &perms, match_str, match_len);
789+
}
790+
}
791+
aa_put_label(label);
774792

775793
return scnprintf(buf, buf_len,
776794
"allow 0x%08x\ndeny 0x%08x\naudit 0x%08x\nquiet 0x%08x\n",
@@ -877,9 +895,12 @@ static int multi_transaction_release(struct inode *inode, struct file *file)
877895
return 0;
878896
}
879897

898+
#define QUERY_CMD_LABEL "label\0"
899+
#define QUERY_CMD_LABEL_LEN 6
880900
#define QUERY_CMD_PROFILE "profile\0"
881901
#define QUERY_CMD_PROFILE_LEN 8
882-
902+
#define QUERY_CMD_LABELALL "labelall\0"
903+
#define QUERY_CMD_LABELALL_LEN 9
883904
#define QUERY_CMD_DATA "data\0"
884905
#define QUERY_CMD_DATA_LEN 5
885906

@@ -922,6 +943,17 @@ static ssize_t aa_write_access(struct file *file, const char __user *ubuf,
922943
len = query_label(t->data, MULTI_TRANSACTION_LIMIT,
923944
t->data + QUERY_CMD_PROFILE_LEN,
924945
count - QUERY_CMD_PROFILE_LEN, true);
946+
} else if (count > QUERY_CMD_LABEL_LEN &&
947+
!memcmp(t->data, QUERY_CMD_LABEL, QUERY_CMD_LABEL_LEN)) {
948+
len = query_label(t->data, MULTI_TRANSACTION_LIMIT,
949+
t->data + QUERY_CMD_LABEL_LEN,
950+
count - QUERY_CMD_LABEL_LEN, true);
951+
} else if (count > QUERY_CMD_LABELALL_LEN &&
952+
!memcmp(t->data, QUERY_CMD_LABELALL,
953+
QUERY_CMD_LABELALL_LEN)) {
954+
len = query_label(t->data, MULTI_TRANSACTION_LIMIT,
955+
t->data + QUERY_CMD_LABELALL_LEN,
956+
count - QUERY_CMD_LABELALL_LEN, false);
925957
} else if (count > QUERY_CMD_DATA_LEN &&
926958
!memcmp(t->data, QUERY_CMD_DATA, QUERY_CMD_DATA_LEN)) {
927959
len = query_data(t->data, MULTI_TRANSACTION_LIMIT,

0 commit comments

Comments
 (0)