Skip to contentSkip to conversation

lxc: Fix -c command for lxc-attach

PATCH In review sana kazi 2 participants 2 messages Sep 15, 2021

lore
Share & tools
lore

sana kazi

author
#0 lore raw

PATCH 1/1 lxc: Fix -c command for lxc-attach

Added fix_c_command.patch the -c command seems to be broken because the passed context is ignored and always overwritten by the context specified in the config file.

---
 .../lxc/files/fix_c_command.patch             | 36 +++++++++++++++++++
 recipes-containers/lxc/lxc_4.0.9.bb           |  1 +
 2 files changed, 37 insertions(+)
 create mode 100644 recipes-containers/lxc/files/fix_c_command.patch
recipes-containers/lxc/files/fix_c_command.patch new file +36 -0
new file mode 100644
index 0000000..1ed8daf
@@ -0,0 +1,36 @@
+From 9becf309a81806ef08acf9ca99ab95c1bcfa1f65 Mon Sep 17 00:00:00 2001
+From: Maximilian Blenk <[email protected]>
+Date: Mon, 23 Aug 2021 15:39:28 +0200
+Subject: [PATCH] attach: Fix -c command
+
+Currently, the -c command (to set the selinux context) seems to be
+broken because the passed context is ignored and always overwritten by
+the context specified in the config file. The intention behind the -c
+imho was to be able to manually overwrite this behavior. This patch
+ensures that the selinux context will be set if passed via the command
+line.
+
+Signed-off-by: Maximilian Blenk <[email protected]>
+---
+ src/lxc/tools/lxc_attach.c | 5 ++++-
+ 1 file changed, 4 insertions(+), 1 deletion(-)
+
+Upstream-Status: Backport [https://github.com/lxc/lxc/commit/9becf309a81806ef08acf9ca99ab95c1bcfa1f65.patch]
+Comment: No change in any hunk
+
+diff --git a/src/lxc/tools/lxc_attach.c b/src/lxc/tools/lxc_attach.c
+index 0374d980b4..e6b388b20c 100644
+--- a/src/lxc/tools/lxc_attach.c
++++ b/src/lxc/tools/lxc_attach.c
+@@ -379,7 +379,10 @@ int main(int argc, char *argv[])
+ 		attach_options.gid = my_args.gid;
+ 
+ 	// selinux_context will be NULL if not set
+-	attach_options.lsm_label = selinux_context;
++	if (selinux_context) {
++		attach_options.attach_flags |= LXC_ATTACH_LSM_LABEL;
++		attach_options.lsm_label = selinux_context;
++	}
+ 
+ 	if (command.program) {
+ 		ret = c->attach_run_wait(c, &attach_options, command.program,
recipes-containers/lxc/lxc_4.0.9.bb +1 -0
index 6720733..c45ae5c 100644
@@ -50,6 +50,7 @@ SRC_URI = "http://linuxcontainers.org/downloads/${BPN}/${BPN}-${PV}.tar.gz \
 	file://dnsmasq.conf \
 	file://lxc-net \
         file://enable_seccomp_profile_when_compiled_libseccomp.patch \
+        file://fix_c_command.patch \
 	"
 
 SRC_URI[md5sum] = "365fcca985038910e19a1e0fff15ed07"
Signature · 1 line
2.17.1
#1 lore raw

Since this change is part of lxc 4.0.10, I did the version bump.

At the same time, I switched the recipe to _git (as I've wanted to for a while), so I can more easily debug things.

I had a LOT of issues with the lxc-download template and images servers, but I was able to verify basic functionality.

Can you rebase this series on top of master-next, and resend the second patch ?

Bruce

Quoted 73 lines · sana kazi

Added fix_c_command.patch the -c command seems to be broken because the passed context is ignored and always overwritten by the context specified in the config file.

---
 .../lxc/files/fix_c_command.patch             | 36 +++++++++++++++++++
 recipes-containers/lxc/lxc_4.0.9.bb           |  1 +
 2 files changed, 37 insertions(+)
 create mode 100644 recipes-containers/lxc/files/fix_c_command.patch
recipes-containers/lxc/files/fix_c_command.patch new file +36 -0
new file mode 100644
index 0000000..1ed8daf
@@ -0,0 +1,36 @@
+From 9becf309a81806ef08acf9ca99ab95c1bcfa1f65 Mon Sep 17 00:00:00 2001
+From: Maximilian Blenk <[email protected]>
+Date: Mon, 23 Aug 2021 15:39:28 +0200
+Subject: [PATCH] attach: Fix -c command
+
+Currently, the -c command (to set the selinux context) seems to be
+broken because the passed context is ignored and always overwritten by
+the context specified in the config file. The intention behind the -c
+imho was to be able to manually overwrite this behavior. This patch
+ensures that the selinux context will be set if passed via the command
+line.
+
+Signed-off-by: Maximilian Blenk <[email protected]>
+---
+ src/lxc/tools/lxc_attach.c | 5 ++++-
+ 1 file changed, 4 insertions(+), 1 deletion(-)
+
+Upstream-Status: Backport [https://github.com/lxc/lxc/commit/9becf309a81806ef08acf9ca99ab95c1bcfa1f65.patch]
+Comment: No change in any hunk
+
+diff --git a/src/lxc/tools/lxc_attach.c b/src/lxc/tools/lxc_attach.c
+index 0374d980b4..e6b388b20c 100644
+--- a/src/lxc/tools/lxc_attach.c
++++ b/src/lxc/tools/lxc_attach.c
+@@ -379,7 +379,10 @@ int main(int argc, char *argv[])
+               attach_options.gid = my_args.gid;
+
+       // selinux_context will be NULL if not set
+-      attach_options.lsm_label = selinux_context;
++      if (selinux_context) {
++              attach_options.attach_flags |= LXC_ATTACH_LSM_LABEL;
++              attach_options.lsm_label = selinux_context;
++      }
+
+       if (command.program) {
+               ret = c->attach_run_wait(c, &attach_options, command.program,
recipes-containers/lxc/lxc_4.0.9.bb +1 -1
index 6720733..c45ae5c 100644
@@ -50,6 +50,7 @@ SRC_URI = "http://linuxcontainers.org/downloads/${BPN}/${BPN}-${PV}.tar.gz \
        file://dnsmasq.conf \
        file://lxc-net \
         file://enable_seccomp_profile_when_compiled_libseccomp.patch \
+        file://fix_c_command.patch \
        "
 
 SRC_URI[md5sum] = "365fcca985038910e19a1e0fff15ed07"
--

2.17.1

Signature · 3 lines
- Thou shalt not follow the NULL pointer, for chaos and madness await
thee at its end
- "Use the force Harry" - Gandalf, Star Trek II