all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Filip Schauer <f.schauer@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH container v2 1/2] add deny read/write options for device passthrough
Date: Wed, 24 Jul 2024 19:18:56 +0200	[thread overview]
Message-ID: <20240724171857.432913-2-f.schauer@proxmox.com> (raw)
In-Reply-To: <20240724171857.432913-1-f.schauer@proxmox.com>

Add the deny_read and deny_write options for device passthrough, to
restrict container access to devices.

Signed-off-by: Filip Schauer <f.schauer@proxmox.com>
---
 src/PVE/LXC.pm        | 13 ++++++++++++-
 src/PVE/LXC/Config.pm | 12 ++++++++++++
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm
index 65d0fa8..6e2b048 100644
--- a/src/PVE/LXC.pm
+++ b/src/PVE/LXC.pm
@@ -651,7 +651,18 @@ sub update_lxc_config {
 	my $major = PVE::Tools::dev_t_major($rdev);
 	my $minor = PVE::Tools::dev_t_minor($rdev);
 	my $device_type_char = S_ISBLK($mode) ? 'b' : 'c';
-	$raw .= "lxc.cgroup2.devices.allow = $device_type_char $major:$minor rw\n";
+	my $allow_perms = $device->{deny_read} ? "" : "r";
+	my $deny_perms = $device->{deny_read} ? "r" : "";
+	$allow_perms .= $device->{deny_write} ? "" : "w";
+	$deny_perms .= $device->{deny_write} ? "w" : "";
+
+	if ($allow_perms) {
+	    $raw .= "lxc.cgroup2.devices.allow = $device_type_char $major:$minor $allow_perms\n";
+	}
+
+	if ($deny_perms) {
+	    $raw .= "lxc.cgroup2.devices.deny = $device_type_char $major:$minor $deny_perms\n";
+	}
     });
 
     # WARNING: DO NOT REMOVE this without making sure that loop device nodes
diff --git a/src/PVE/LXC/Config.pm b/src/PVE/LXC/Config.pm
index 1664a35..b37f84d 100644
--- a/src/PVE/LXC/Config.pm
+++ b/src/PVE/LXC/Config.pm
@@ -962,6 +962,18 @@ my $dev_desc = {
 	minimum => 0,
 	description => 'Group ID to be assigned to the device node',
     },
+    deny_read => {
+	optional => 1,
+	type => 'boolean',
+	description => 'Deny the container to read from the device',
+	default => 0,
+    },
+    deny_write => {
+	optional => 1,
+	type => 'boolean',
+	description => 'Deny the container to write to the device',
+	default => 0,
+    },
 };
 
 for (my $i = 0; $i < $MAX_DEVICES; $i++) {
-- 
2.39.2



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


  reply	other threads:[~2024-07-24 17:19 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-24 17:18 [pve-devel] [PATCH container/manager v2 0/2] " Filip Schauer
2024-07-24 17:18 ` Filip Schauer [this message]
2024-07-24 17:18 ` [pve-devel] [PATCH manager v2 2/2] ui: lxc: add readonly option " Filip Schauer
2024-09-06 12:14 ` [pve-devel] [PATCH container/manager v2 0/2] add deny read/write options " Fiona Ebner
2024-09-06 17:01   ` Thomas Lamprecht
2024-09-09 12:52     ` Filip Schauer

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=20240724171857.432913-2-f.schauer@proxmox.com \
    --to=f.schauer@proxmox.com \
    --cc=pve-devel@lists.proxmox.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal