summaryrefslogtreecommitdiff
path: root/security
diff options
context:
space:
mode:
authorKonstantin Andreev <andreev@swemel.ru>2024-06-17 01:44:30 +0300
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2024-09-12 11:07:45 +0200
commit09e89a5e11734edad52d8e5b08a0124cb927ba59 (patch)
tree663215971f6dc8afa49f3839089220808dc928e0 /security
parent22d3b037ddc5b31afd9b327ac2ededc49f04ace2 (diff)
downloadlinux-09e89a5e11734edad52d8e5b08a0124cb927ba59.tar.gz
linux-09e89a5e11734edad52d8e5b08a0124cb927ba59.tar.bz2
linux-09e89a5e11734edad52d8e5b08a0124cb927ba59.zip
smack: unix sockets: fix accept()ed socket label
[ Upstream commit e86cac0acdb1a74f608bacefe702f2034133a047 ] 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> Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'security')
-rw-r--r--security/smack/smack_lsm.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
index 25c46b56fae8..1eaf3e075db6 100644
--- a/security/smack/smack_lsm.c
+++ b/security/smack/smack_lsm.c
@@ -3641,12 +3641,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;