linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Marc-André Lureau" <marcandre.lureau@redhat.com>
To: netdev@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, sgarzare@redhat.com,
	davem@davemloft.net, kuba@kernel.org,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>
Subject: [PATCH 08/10] vhost/vsock: save owner pid & creds
Date: Thu, 21 Oct 2021 16:37:12 +0400	[thread overview]
Message-ID: <20211021123714.1125384-9-marcandre.lureau@redhat.com> (raw)
In-Reply-To: <20211021123714.1125384-1-marcandre.lureau@redhat.com>

After VHOST_SET_OWNER success, save the owner process credentials.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 drivers/vhost/vsock.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c
index 938aefbc75ec..3067436cddfc 100644
--- a/drivers/vhost/vsock.c
+++ b/drivers/vhost/vsock.c
@@ -58,6 +58,8 @@ struct vhost_vsock {
 
 	u32 guest_cid;
 	bool seqpacket_allow;
+	struct pid *owner_pid;
+	const struct cred *owner_cred;
 };
 
 static u32 vhost_transport_get_local_cid(void)
@@ -774,6 +776,10 @@ static int vhost_vsock_dev_release(struct inode *inode, struct file *file)
 
 	vhost_dev_cleanup(&vsock->dev);
 	kfree(vsock->dev.vqs);
+
+	put_pid(vsock->owner_pid);
+	put_cred(vsock->owner_cred);
+
 	vhost_vsock_free(vsock);
 	return 0;
 }
@@ -851,6 +857,22 @@ static int vhost_vsock_set_features(struct vhost_vsock *vsock, u64 features)
 	return -EFAULT;
 }
 
+static long vhost_vsock_set_owner(struct vhost_vsock *vsock)
+{
+	long r;
+
+	mutex_lock(&vsock->dev.mutex);
+	r = vhost_dev_set_owner(&vsock->dev);
+	if (r)
+		goto out;
+	vsock->owner_pid = get_pid(task_tgid(current));
+	vsock->owner_cred = get_current_cred();
+	vhost_vsock_flush(vsock);
+out:
+	mutex_unlock(&vsock->dev.mutex);
+	return r;
+}
+
 static long vhost_vsock_dev_ioctl(struct file *f, unsigned int ioctl,
 				  unsigned long arg)
 {
@@ -894,6 +916,8 @@ static long vhost_vsock_dev_ioctl(struct file *f, unsigned int ioctl,
 			return -EOPNOTSUPP;
 		vhost_set_backend_features(&vsock->dev, features);
 		return 0;
+	case VHOST_SET_OWNER:
+		return vhost_vsock_set_owner(vsock);
 	default:
 		mutex_lock(&vsock->dev.mutex);
 		r = vhost_dev_ioctl(&vsock->dev, ioctl, argp);
-- 
2.33.0.721.g106298f7f9


  parent reply	other threads:[~2021-10-21 12:38 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-21 12:37 [PATCH 00/10] RFC: SO_PEERCRED for AF_VSOCK Marc-André Lureau
2021-10-21 12:37 ` [PATCH 01/10] sock: move sock_init_peercred() from af_unix Marc-André Lureau
2021-10-21 12:37 ` [PATCH 02/10] sock: move sock_copy_peercred() " Marc-André Lureau
2021-10-21 12:37 ` [PATCH 03/10] vsock: owner field is specific to VMCI Marc-André Lureau
2021-10-26 11:16   ` Stefano Garzarella
2021-10-27  8:13     ` Jorgen Hansen
2021-11-05  8:21       ` Marc-André Lureau
2021-10-21 12:37 ` [PATCH 04/10] sock: add sock_swap_peercred Marc-André Lureau
2021-10-21 12:37 ` [PATCH 05/10] virtio/vsock: add copy_peercred() to virtio_transport Marc-André Lureau
2021-10-26 11:17   ` Stefano Garzarella
2021-10-21 12:37 ` [PATCH 06/10] vsock: set socket peercred Marc-André Lureau
2021-10-26 11:18   ` Stefano Garzarella
2021-10-21 12:37 ` [PATCH 07/10] vsock/loopback: implement copy_peercred() Marc-André Lureau
2021-10-26 11:18   ` Stefano Garzarella
2021-10-21 12:37 ` Marc-André Lureau [this message]
2021-10-21 12:37 ` [PATCH 09/10] vhost/vsock: implement copy_peercred Marc-André Lureau
2021-10-21 12:37 ` [PATCH 10/10] vsock/virtio: clear peer creds on connect Marc-André Lureau
2021-10-21 13:34 ` [PATCH 00/10] RFC: SO_PEERCRED for AF_VSOCK Stefano Garzarella

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211021123714.1125384-9-marcandre.lureau@redhat.com \
    --to=marcandre.lureau@redhat.com \
    --cc=davem@davemloft.net \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=sgarzare@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).