Skip to content

Commit a30a9fd

Browse files
committed
apparmor: fix af_unix auditing to include all address information
The auditing of addresses currently doesn't include the source address and mixes source and foreign/peer under the same audit name. Fix this so source is always addr, and the foreign/peer is peer_addr. Fixes: c05e705 ("apparmor: add fine grained af_unix mediation") Signed-off-by: John Johansen <[email protected]>
1 parent bc6e5f6 commit a30a9fd

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

security/apparmor/af_unix.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -584,8 +584,8 @@ static int unix_peer_perm(const struct cred *subj_cred,
584584
struct aa_profile *profile;
585585
DEFINE_AUDIT_SK(ad, op, subj_cred, sk);
586586

587-
ad.net.addr = peer_addr;
588-
ad.net.addrlen = peer_addrlen;
587+
ad.net.peer.addr = peer_addr;
588+
ad.net.peer.addrlen = peer_addrlen;
589589

590590
return fn_for_each_confined(label, profile,
591591
profile_peer_perm(profile, request, sk,

security/apparmor/include/audit.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@ struct apparmor_audit_data {
140140
int type, protocol;
141141
void *addr;
142142
int addrlen;
143+
struct {
144+
void *addr;
145+
int addrlen;
146+
} peer;
143147
} net;
144148
};
145149
};

security/apparmor/net.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,15 @@ static void audit_unix_sk_addr(struct audit_buffer *ab, const char *str,
9999
{
100100
const struct unix_sock *u = unix_sk(sk);
101101

102-
if (u && u->addr)
103-
audit_unix_addr(ab, str, u->addr->name, u->addr->len);
104-
else
102+
if (u && u->addr) {
103+
int addrlen;
104+
struct sockaddr_un *addr = aa_sunaddr(u, &addrlen);
105+
106+
audit_unix_addr(ab, str, addr, addrlen);
107+
} else {
105108
audit_unix_addr(ab, str, NULL, 0);
109+
110+
}
106111
}
107112

108113
/* audit callback for net specific fields */
@@ -137,17 +142,16 @@ void audit_net_cb(struct audit_buffer *ab, void *va)
137142
}
138143
}
139144
if (ad->common.u.net->family == PF_UNIX) {
140-
if ((ad->request & ~NET_PEER_MASK) && ad->net.addr)
145+
if (ad->net.addr || !ad->common.u.net->sk)
141146
audit_unix_addr(ab, "addr",
142147
unix_addr(ad->net.addr),
143148
ad->net.addrlen);
144149
else
145150
audit_unix_sk_addr(ab, "addr", ad->common.u.net->sk);
146151
if (ad->request & NET_PEER_MASK) {
147-
if (ad->net.addr)
148-
audit_unix_addr(ab, "peer_addr",
149-
unix_addr(ad->net.addr),
150-
ad->net.addrlen);
152+
audit_unix_addr(ab, "peer_addr",
153+
unix_addr(ad->net.peer.addr),
154+
ad->net.peer.addrlen);
151155
}
152156
}
153157
if (ad->peer) {

0 commit comments

Comments
 (0)