[PATCH 09/10] vhost/vsock: implement copy_peercred
From: Marc-André Lureau
Date: Thu Oct 21 2021 - 08:38:36 EST
Set the socket peercred to the vhost owner.
Signed-off-by: Marc-André Lureau <marcandre.lureau@xxxxxxxxxx>
---
drivers/vhost/vsock.c | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c
index 3067436cddfc..fb492c53631d 100644
--- a/drivers/vhost/vsock.c
+++ b/drivers/vhost/vsock.c
@@ -308,6 +308,27 @@ vhost_transport_send_pkt(struct virtio_vsock_pkt *pkt)
return len;
}
+static void vhost_transport_copy_peercred(struct sock *sk, struct virtio_vsock_pkt *pkt)
+{
+ struct vhost_vsock *vsock;
+
+ put_pid(sk->sk_peer_pid);
+ sk->sk_peer_pid = NULL;
+ put_cred(sk->sk_peer_cred);
+ sk->sk_peer_cred = NULL;
+
+ rcu_read_lock();
+ vsock = vhost_vsock_get(le64_to_cpu(pkt->hdr.src_cid));
+ if (!vsock)
+ goto out;
+
+ sk->sk_peer_pid = get_pid(vsock->owner_pid);
+ sk->sk_peer_cred = get_cred(vsock->owner_cred);
+
+out:
+ rcu_read_unlock();
+}
+
static int
vhost_transport_cancel_pkt(struct vsock_sock *vsk)
{
@@ -474,6 +495,7 @@ static struct virtio_transport vhost_transport = {
},
.send_pkt = vhost_transport_send_pkt,
+ .copy_peercred = vhost_transport_copy_peercred,
};
static bool vhost_transport_seqpacket_allow(u32 remote_cid)
--
2.33.0.721.g106298f7f9