[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20211021123714.1125384-10-marcandre.lureau@redhat.com>
Date: Thu, 21 Oct 2021 16:37:13 +0400
From: Marc-André Lureau <marcandre.lureau@...hat.com>
To: netdev@...r.kernel.org
Cc: linux-kernel@...r.kernel.org, sgarzare@...hat.com,
davem@...emloft.net, kuba@...nel.org,
Marc-André Lureau <marcandre.lureau@...hat.com>
Subject: [PATCH 09/10] vhost/vsock: implement copy_peercred
Set the socket peercred to the vhost owner.
Signed-off-by: Marc-André Lureau <marcandre.lureau@...hat.com>
---
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
Powered by blists - more mailing lists