Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit e86cac0

Browse files
goongascschaufler
authored andcommitted
smack: unix sockets: fix accept()ed socket label
When a process accept()s connection from a unix socket (either stream or seqpacket) it gets the socket with the label of the connecting process. For example, if a connecting process has a label 'foo', the accept()ed socket will also have 'in' and 'out' labels 'foo', regardless of the label of the listener process. This is because kernel creates unix child sockets in the context of the connecting process. I do not see any obvious way for the listener to abuse alien labels coming with the new socket, but, to be on the safe side, it's better fix new socket labels. Signed-off-by: Konstantin Andreev <andreev@swemel.ru> Signed-off-by: Casey Schaufler <casey@schaufler-ca.com>
1 parent 2fe209d commit e86cac0

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

security/smack/smack_lsm.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3846,12 +3846,18 @@ static int smack_unix_stream_connect(struct sock *sock,
38463846
}
38473847
}
38483848

3849-
/*
3850-
* Cross reference the peer labels for SO_PEERSEC.
3851-
*/
38523849
if (rc == 0) {
3850+
/*
3851+
* Cross reference the peer labels for SO_PEERSEC.
3852+
*/
38533853
nsp->smk_packet = ssp->smk_out;
38543854
ssp->smk_packet = osp->smk_out;
3855+
3856+
/*
3857+
* new/child/established socket must inherit listening socket labels
3858+
*/
3859+
nsp->smk_out = osp->smk_out;
3860+
nsp->smk_in = osp->smk_in;
38553861
}
38563862

38573863
return rc;

0 commit comments

Comments
 (0)