Skip to contentSkip to conversation

selinux: vsock: Set SID for socket returned by accept()

PATCH Applied David Brazdil 2 participants 3 messages Mar 19, 2021

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 selinux: vsock: Set SID for socket returned by accept()

For AF_VSOCK, accept() currently returns sockets that are unlabelled. Other socket families derive the child's SID from the SID of the parent and the SID of the incoming packet. This is typically done as the connected socket is placed in the queue that accept() removes from.

Reuse the existing 'security_sk_clone' hook to copy the SID from the parent (server) socket to the child. There is no packet SID in this case.

Fixes d021c344051a ("VSOCK: Introduce VM Sockets")

---
Tested on Android AOSP and Fedora 33 with v5.12-rc3. Unit test is available here:
https://github.com/SELinuxProject/selinux-testsuite/pull/75

Changes since v1:
* reuse security_sk_clone instead of adding a new hook

 net/vmw_vsock/af_vsock.c | 1 +
 1 file changed, 1 insertion(+)
net/vmw_vsock/af_vsock.c +1 -0
index 5546710d8ac1..bc7fb9bf3351 100644
@@ -755,6 +755,7 @@ static struct sock *__vsock_create(struct net *net,
 		vsk->buffer_size = psk->buffer_size;
 		vsk->buffer_min_size = psk->buffer_min_size;
 		vsk->buffer_max_size = psk->buffer_max_size;
+		security_sk_clone(parent, sk);
 	} else {
 		vsk->trusted = ns_capable_noaudit(&init_user_ns, CAP_NET_ADMIN);
 		vsk->owner = get_current_cred();
Signature · 1 line
2.31.0.rc2.261.g7f71774620-goog
#1 lore raw
Quoted 10 lines · David Brazdil

For AF_VSOCK, accept() currently returns sockets that are unlabelled. Other socket families derive the child's SID from the SID of the parent and the SID of the incoming packet. This is typically done as the connected socket is placed in the queue that accept() removes from.

Reuse the existing 'security_sk_clone' hook to copy the SID from the parent (server) socket to the child. There is no packet SID in this case.

Fixes d021c344051a ("VSOCK: Introduce VM Sockets")
Quoted 27 lines

---
Tested on Android AOSP and Fedora 33 with v5.12-rc3. Unit test is available here:
https://github.com/SELinuxProject/selinux-testsuite/pull/75

Changes since v1:
* reuse security_sk_clone instead of adding a new hook

 net/vmw_vsock/af_vsock.c | 1 +
 1 file changed, 1 insertion(+)
net/vmw_vsock/af_vsock.c +1 -0
index 5546710d8ac1..bc7fb9bf3351 100644
@@ -755,6 +755,7 @@ static struct sock *__vsock_create(struct net *net,
 		vsk->buffer_size = psk->buffer_size;
 		vsk->buffer_min_size = psk->buffer_min_size;
 		vsk->buffer_max_size = psk->buffer_max_size;
+		security_sk_clone(parent, sk);
 	} else {
 		vsk->trusted = ns_capable_noaudit(&init_user_ns, CAP_NET_ADMIN);
 		vsk->owner = get_current_cred();
Signature · 1 line
2.31.0.rc2.261.g7f71774620-goog
#2 lore raw
In reply to David Brazdil
This patch was applied to netdev/net.git (refs/heads/master):

Hello:

This patch was applied to netdev/net.git (refs/heads/master):

Quoted 10 lines · On Fri, 19 Mar 2021 13:05:41 +0000 you wrote:

For AF_VSOCK, accept() currently returns sockets that are unlabelled. Other socket families derive the child's SID from the SID of the parent and the SID of the incoming packet. This is typically done as the connected socket is placed in the queue that accept() removes from.

Reuse the existing 'security_sk_clone' hook to copy the SID from the parent (server) socket to the child. There is no packet SID in this case.

[...]

Here is the summary with links:
- [v2] selinux: vsock: Set SID for socket returned by accept()

    https://git.kernel.org/netdev/net/c/1f935e8e72ec

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html