Signed-off-by: Marc-André Lureau <marcandre.lureau@xxxxxxxxxx>
---
include/linux/virtio_vsock.h | 2 ++
net/vmw_vsock/virtio_transport_common.c | 9 +++++++++
2 files changed, 11 insertions(+)
diff --git a/include/linux/virtio_vsock.h b/include/linux/virtio_vsock.h
index 35d7eedb5e8e..2445bece9216 100644
--- a/include/linux/virtio_vsock.h
+++ b/include/linux/virtio_vsock.h
@@ -69,6 +69,8 @@ struct virtio_transport {
/* Takes ownership of the packet */
int (*send_pkt)(struct virtio_vsock_pkt *pkt);
+ /* Set peercreds on socket created after listen recv */
+ void (*copy_peercred)(struct sock *sk, struct virtio_vsock_pkt *pkt);
};
ssize_t
diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c
index 59ee1be5a6dd..611d25e80723 100644
--- a/net/vmw_vsock/virtio_transport_common.c
+++ b/net/vmw_vsock/virtio_transport_common.c
@@ -1194,6 +1194,15 @@ virtio_transport_recv_listen(struct sock *sk, struct virtio_vsock_pkt *pkt,
return -ENOMEM;
}
+ if (t->copy_peercred) {
+ t->copy_peercred(child, pkt);
+ } else {
+ put_pid(child->sk_peer_pid);
+ child->sk_peer_pid = NULL;
+ put_cred(child->sk_peer_cred);
+ child->sk_peer_cred = NULL;
+ }
+