Skip to content

Commit

Permalink
smack: unix sockets: fix accept()ed socket label
Browse files Browse the repository at this point in the history
BugLink: https://bugs.launchpad.net/bugs/2085849

[ Upstream commit e86cac0 ]

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 <[email protected]>
Signed-off-by: Casey Schaufler <[email protected]>
Signed-off-by: Sasha Levin <[email protected]>
Signed-off-by: Manuel Diewald <[email protected]>
Signed-off-by: Roxana Nicolescu <[email protected]>
  • Loading branch information
goongas authored and mehmetb0 committed Nov 9, 2024
1 parent 4f68c36 commit 580ae54
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions security/smack/smack_lsm.c
Original file line number Diff line number Diff line change
Expand Up @@ -3874,12 +3874,18 @@ static int smack_unix_stream_connect(struct sock *sock,
}
}

/*
* Cross reference the peer labels for SO_PEERSEC.
*/
if (rc == 0) {
/*
* Cross reference the peer labels for SO_PEERSEC.
*/
nsp->smk_packet = ssp->smk_out;
ssp->smk_packet = osp->smk_out;

/*
* new/child/established socket must inherit listening socket labels
*/
nsp->smk_out = osp->smk_out;
nsp->smk_in = osp->smk_in;
}

return rc;
Expand Down

0 comments on commit 580ae54

Please sign in to comment.