Skip to contentSkip to conversation

libxl: fix build on rather old systems

PATCH In review Juergen Gross 6 participants 18 messages Jan 11, 2019 – Jan 16, 2019 6 messages not in the archive

lore
Share & tools
lore
#1 lore raw
In reply to a message not in the archive
Quoted 5 lines · Jan Beulich

CLONE_NEWIPC has been introduced in Linux 2.6.19 only (and into glibc at around that time as well). Cope with it being undefined as well as with the underlying kernel not knowing of it.

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

Nacked-by NAK
#2 lore raw

Juergen Gross writes ("Re: [PATCH] libxl: fix build on rather old systems"):

Quoted 8 lines · Jan Beulich
Quoted 5 lines

CLONE_NEWIPC has been introduced in Linux 2.6.19 only (and into glibc at around that time as well). Cope with it being undefined as well as with the underlying kernel not knowing of it.

I know I am too slow with this, but for the record:

On two grounds:

1. This situation should be handled by disabling the dm restrict feature, not silently falling back to lower protection.

2. Style, #ifdeffery.

I don't agree that the unshare of the IPC namespace is a `nice to have'. Without it, a rogue qemu might be able to do a number of bad things.

Background: AIUI in kernels without CLONE_NEWIPC, the IPC namespace is shared with the network namespace. But of course what matters is what the *runtime* kernel supports, not the build-time kernel.

Ian.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#4 lore raw

PATCH 2/2 libxl: fix build (missing CLONE_NEWIPC) on astonishingly old systems

In reply to Ian Jackson

CLONE_NEWIPC was introduced in Linux 2.6.19, on the 29th of November 2006, which was 12 years, 1 month, and 14 days ago.

Nevertheless apparently some people are trying to build Xen on systems whose kernel headers are that old. Placate these people by providing a fallback #define for CLONE_NEWIPC.

The actual binary value will of course remain constant, because of the kernel API promise, so this is and will be correct on all platforms where the CLONE_NEWIPC is supported. (Even if for some reason we miss the right #includes.)

Of course at runtime this value will not work on older kernels. It will be rejected as unknown. However on those kernels we do not want to support dm_restrict, and an attempt to use it will fail. It is OK for the failure to be a messy EINVAL syscall failure. (The IPC namespace unshare is necessary to avoid a suborned deprivileged qemu from causing trouble with shm, sem, etc.)

CC Wei Liu <[email protected]>
CC Juergen Gross <[email protected]>
CC Jan Beulich <[email protected]>
---
 tools/libxl/libxl_linux.c | 8 ++++++++
 1 file changed, 8 insertions(+)
tools/libxl/libxl_linux.c +8 -0
index 6475cca64b..51539ade20 100644
@@ -18,6 +18,14 @@
 #include <sys/resource.h>
 #include "libxl_internal.h"
 
+
+/* Workarounds for Linux-specific lacks can go here: */
+
+#ifndef CLONE_XNEWIPC /* Available as of Linux 2.6.19 / glibc 2.8 */
+# define CLONE_NEWIPC 0x08000000
+#endif
+
+
 int libxl__try_phy_backend(mode_t st_mode)
 {
     if (S_ISBLK(st_mode) || S_ISREG(st_mode)) {
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#3 lore raw

PATCH 1/2 Revert "libxl: fix build on rather old systems"

In reply to Ian Jackson

This reverts commit 1bce5f9baf0f4a4e50722f32b44afe4fdefc6b35.

This situation should be handled by disabling the dm restrict feature, not silently falling back to lower protection.

Also this #ifdeffery is bad style.

---
 tools/libxl/libxl_linux.c | 16 ++--------------
 1 file changed, 2 insertions(+), 14 deletions(-)
tools/libxl/libxl_linux.c +2 -14
index a4c2f28dbf..6475cca64b 100644
@@ -334,24 +334,12 @@ int libxl__local_dm_preexec_restrict(libxl__gc *gc)
     unsigned i;
 
     /* Unshare mount and IPC namespaces.  These are unused by QEMU. */
-    r = unshare(CLONE_NEWNS);
+    r = unshare(CLONE_NEWNS | CLONE_NEWIPC);
     if (r) {
-        LOGE(ERROR, "libxl: Mount namespace unshare failed");
+        LOGE(ERROR, "libxl: Mount and IPC namespace unfailed");
         return ERROR_FAIL;
     }
 
-#ifndef CLONE_NEWIPC /* Available as of Linux 2.6.19 / glibc 2.8 */
-# define CLONE_NEWIPC 0x08000000
-#endif
-    r = unshare(CLONE_NEWIPC);
-    if (r) {
-        if (r && errno != EINVAL) {
-            LOGE(ERROR, "libxl: IPC namespace unshare failed");
-            return ERROR_FAIL;
-        }
-        LOG(WARN, "libxl: IPC namespace unshare unavailable");
-    }
-
     /* Set various "easy" rlimits */
     for (i = 0; rlimits[i].resource != RLIMIT_NLIMITS; i++) {
         struct rlimit rlim;
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#5 lore raw

Re: [PATCH 2/2] libxl: fix build (missing CLONE_NEWIPC) on astonishingly old systems

In reply to Ian Jackson
Quoted 1 line · Ian Jackson

+#ifndef CLONE_XNEWIPC /* Available as of Linux 2.6.19 / glibc 2.8 */

There's a strange X here, but not below.

Quoted 1 line

+# define CLONE_NEWIPC 0x08000000

Signature · 6 lines
Anthony PERARD

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#6 lore raw

Re: [PATCH 2/2] libxl: fix build (missing CLONE_NEWIPC) on astonishingly old systems

Anthony PERARD writes ("Re: [Xen-devel] [PATCH 2/2] libxl: fix build (missing CLONE_NEWIPC) on astonishingly old systems"):

Quoted 4 lines · Ian Jackson
Quoted 1 line

+#ifndef CLONE_XNEWIPC /* Available as of Linux 2.6.19 / glibc 2.8 */

There's a strange X here, but not below.

Erk, that's wrong.

Ian.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#7 lore raw

PATCH v2 2/2 libxl: fix build (missing CLONE_NEWIPC) on astonishingly old systems

In reply to Anthony PERARD

CLONE_NEWIPC was introduced in Linux 2.6.19, on the 29th of November 2006, which was 12 years, 1 month, and 14 days ago.

Nevertheless apparently some people are trying to build Xen on systems whose kernel headers are that old. Placate these people by providing a fallback #define for CLONE_NEWIPC.

The actual binary value will of course remain constant, because of the kernel API promise, so this is and will be correct on all platforms where the CLONE_NEWIPC is supported. (Even if for some reason we miss the right #includes.)

Of course at runtime this value will not work on older kernels. It will be rejected as unknown. However on those kernels we do not want to support dm_restrict, and an attempt to use it will fail. It is OK for the failure to be a messy EINVAL syscall failure. (The IPC namespace unshare is necessary to avoid a suborned deprivileged qemu from causing trouble with shm, sem, etc.)

CC Wei Liu <[email protected]>
CC Juergen Gross <[email protected]>
CC Jan Beulich <[email protected]>

---
v2: Get rid of spurious X

---
 tools/libxl/libxl_linux.c | 8 ++++++++
 1 file changed, 8 insertions(+)
tools/libxl/libxl_linux.c +8 -0
index 6475cca64b..59dd945bc1 100644
@@ -18,6 +18,14 @@
 #include <sys/resource.h>
 #include "libxl_internal.h"
 
+
+/* Workarounds for Linux-specific lacks can go here: */
+
+#ifndef CLONE_NEWIPC /* Available as of Linux 2.6.19 / glibc 2.8 */
+# define CLONE_NEWIPC 0x08000000
+#endif
+
+
 int libxl__try_phy_backend(mode_t st_mode)
 {
     if (S_ISBLK(st_mode) || S_ISREG(st_mode)) {
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#13 lore raw

Re: [PATCH v2 2/2] libxl: fix build (missing CLONE_NEWIPC) on astonishingly old systems

In reply to a message not in the archive
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 11.01.19 at 20:23, <[email protected]> wrote:

CLONE_NEWIPC was introduced in Linux 2.6.19, on the 29th of November 2006, which was 12 years, 1 month, and 14 days ago.

Thanks for the very precise counting, the latter part which will be wrong - even if just slightly - by the time you commit it ;-)

Quoted 11 lines

Nevertheless apparently some people are trying to build Xen on systems whose kernel headers are that old. Placate these people by providing a fallback #define for CLONE_NEWIPC.

The actual binary value will of course remain constant, because of the kernel API promise, so this is and will be correct on all platforms where the CLONE_NEWIPC is supported. (Even if for some reason we miss the right #includes.)

Of course at runtime this value will not work on older kernels. It will be rejected as unknown.

Sadly the situation is more complicated: The check to disallow unknown flags was introduced only in 2.6.17 [1], and apparently never backported to 2.6.16 or older stable trees despite the description talking about it going into 2.6.16. Since it didn't matter in my variant of the workaround, I didn't mention this.

Of course a pretty reasonable position to take would be to consider the 2.6.18-based XenoLinux tree a "baseline", beyond which we don't care about undesirable behavior here.

Jan

[1] 06f9d4f94a unshare: Error if passed unsupported flags

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#14 lore raw

Re: [PATCH v2 2/2] libxl: fix build (missing CLONE_NEWIPC) on astonishingly old systems

Quoted 25 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 11.01.19 at 20:23, <[email protected]> wrote:

CLONE_NEWIPC was introduced in Linux 2.6.19, on the 29th of November 2006, which was 12 years, 1 month, and 14 days ago.

Thanks for the very precise counting, the latter part which will be wrong - even if just slightly - by the time you commit it ;-)

Quoted 11 lines

Nevertheless apparently some people are trying to build Xen on systems whose kernel headers are that old. Placate these people by providing a fallback #define for CLONE_NEWIPC.

The actual binary value will of course remain constant, because of the kernel API promise, so this is and will be correct on all platforms where the CLONE_NEWIPC is supported. (Even if for some reason we miss the right #includes.)

Of course at runtime this value will not work on older kernels. It will be rejected as unknown.

Sadly the situation is more complicated: The check to disallow unknown flags was introduced only in 2.6.17 [1], and apparently never backported to 2.6.16 or older stable trees despite the description talking about it going into 2.6.16. Since it didn't matter in my variant of the workaround, I didn't mention this.

Quoted 3 lines

Of course a pretty reasonable position to take would be to consider the 2.6.18-based XenoLinux tree a "baseline", beyond which we don't care about undesirable behavior here.

I think using 2.6.18 as baseline is very reasonable.

Wei.

Quoted 6 lines

Jan

[1] 06f9d4f94a unshare: Error if passed unsupported flags

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#15 lore raw

Re: [PATCH v2 2/2] libxl: fix build (missing CLONE_NEWIPC) on astonishingly old systems

Wei Liu writes ("Re: [PATCH v2 2/2] libxl: fix build (missing CLONE_NEWIPC) on astonishingly old systems"):

Quoted 7 lines · Jan Beulich
Quoted 6 lines · On 11.01.19 at 20:23, <[email protected]> wrote:
Quoted 2 lines

CLONE_NEWIPC was introduced in Linux 2.6.19, on the 29th of November 2006, which was 12 years, 1 month, and 14 days ago.

Thanks for the very precise counting, the latter part which will be wrong - even if just slightly - by the time you commit it ;-)

...

Quoted 5 lines
Quoted 5 lines

Sadly the situation is more complicated: The check to disallow unknown flags was introduced only in 2.6.17 [1], and apparently never backported to 2.6.16 or older stable trees despite the description talking about it going into 2.6.16. Since it didn't matter in my variant of the workaround, I didn't mention this.

Good grief.

Quoted 5 lines
Quoted 3 lines

Of course a pretty reasonable position to take would be to consider the 2.6.18-based XenoLinux tree a "baseline", beyond which we don't care about undesirable behavior here.

I think using 2.6.18 as baseline is very reasonable.

I guess we need to write this in the SUPPORT.md statement for dm_restrict.

TBH how about writing somewhere general in SUPPORT.md that "all bets are off if you use Linux before 2.6.18" ? Do we even have a limit anywhere for security supported Linux versions ?

Ian.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#16 lore raw

Re: [PATCH v2 2/2] libxl: fix build (missing CLONE_NEWIPC) on astonishingly old systems

Quoted 19 lines
Quoted 1 line
Quoted 1 line · On 14.01.19 at 15:22, <[email protected]> wrote:

Wei Liu writes ("Re: [PATCH v2 2/2] libxl: fix build (missing CLONE_NEWIPC) on astonishingly old systems"):

Quoted 7 lines · Jan Beulich
Quoted 6 lines · On 11.01.19 at 20:23, <[email protected]> wrote:
Quoted 2 lines

CLONE_NEWIPC was introduced in Linux 2.6.19, on the 29th of November 2006, which was 12 years, 1 month, and 14 days ago.

Thanks for the very precise counting, the latter part which will be wrong - even if just slightly - by the time you commit it ;-)

...

Quoted 5 lines
Quoted 5 lines

Sadly the situation is more complicated: The check to disallow unknown flags was introduced only in 2.6.17 [1], and apparently never backported to 2.6.16 or older stable trees despite the description talking about it going into 2.6.16. Since it didn't matter in my variant of the workaround, I didn't mention this.

Good grief.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

Of course a pretty reasonable position to take would be to consider the 2.6.18-based XenoLinux tree a "baseline", beyond which we don't care about undesirable behavior here.

I think using 2.6.18 as baseline is very reasonable.

I guess we need to write this in the SUPPORT.md statement for dm_restrict.

Ah yes, we should.

Quoted 3 lines

TBH how about writing somewhere general in SUPPORT.md that "all bets are off if you use Linux before 2.6.18" ? Do we even have a limit anywhere for security supported Linux versions ?

I don't think so, and leaving this specific case aside it's also unclear to me why we should.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#17 lore raw

PATCH v3 1/3 docs/features/qemu-deprivilege.pandoc: No support with Linux <2.6.18

In reply to Ian Jackson

Some early kernesl are known not to reject unknown flags to unshare(). There may be other problems.

---
v3: New in this version of the series.

---
 docs/features/qemu-deprivilege.pandoc | 3 +++
 1 file changed, 3 insertions(+)
docs/features/qemu-deprivilege.pandoc +3 -0
index eb05981a83..20d6ac2189 100644
@@ -112,6 +112,9 @@ The following features still need to be implemented:
  * Inserting a new cdrom while the guest is running (xl cdrom-insert)
  * Migration / save / restore
 
+dm_restrict is totally unsupported and may have unexpected security
+problems if used with a dom0 Linux kernel earlier than 2.6.18.
+
 Additionally, getting PCI passthrough to work securely would require a
 significant rework of how passthrough works at the moment.  It may be
 implemented at some point but is not a near-term priority.
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#20 lore raw

PATCH v3 2/3 Revert "libxl: fix build on rather old systems"

In reply to Ian Jackson

This reverts commit 1bce5f9baf0f4a4e50722f32b44afe4fdefc6b35.

This situation should be handled by disabling the dm restrict feature, not silently falling back to lower protection.

Also this #ifdeffery is bad style.

---
 tools/libxl/libxl_linux.c | 16 ++--------------
 1 file changed, 2 insertions(+), 14 deletions(-)
tools/libxl/libxl_linux.c +2 -14
index a4c2f28dbf..6475cca64b 100644
@@ -334,24 +334,12 @@ int libxl__local_dm_preexec_restrict(libxl__gc *gc)
     unsigned i;
 
     /* Unshare mount and IPC namespaces.  These are unused by QEMU. */
-    r = unshare(CLONE_NEWNS);
+    r = unshare(CLONE_NEWNS | CLONE_NEWIPC);
     if (r) {
-        LOGE(ERROR, "libxl: Mount namespace unshare failed");
+        LOGE(ERROR, "libxl: Mount and IPC namespace unfailed");
         return ERROR_FAIL;
     }
 
-#ifndef CLONE_NEWIPC /* Available as of Linux 2.6.19 / glibc 2.8 */
-# define CLONE_NEWIPC 0x08000000
-#endif
-    r = unshare(CLONE_NEWIPC);
-    if (r) {
-        if (r && errno != EINVAL) {
-            LOGE(ERROR, "libxl: IPC namespace unshare failed");
-            return ERROR_FAIL;
-        }
-        LOG(WARN, "libxl: IPC namespace unshare unavailable");
-    }
-
     /* Set various "easy" rlimits */
     for (i = 0; rlimits[i].resource != RLIMIT_NLIMITS; i++) {
         struct rlimit rlim;
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#22 lore raw

PATCH v3 3/3 libxl: fix build (missing CLONE_NEWIPC) on astonishingly old systems

In reply to Ian Jackson

CLONE_NEWIPC was introduced in Linux 2.6.19, on the 29th of November 2006, which was 12 years, 1 month, and 14 days ago.

Nevertheless apparently some people are trying to build Xen on systems whose kernel headers are that old. Placate these people by providing a fallback #define for CLONE_NEWIPC.

The actual binary value will of course remain constant, because of the kernel API promise, so this is and will be correct on all platforms where the CLONE_NEWIPC is supported. (Even if for some reason we miss the right #includes.)

Of course at runtime this value will not work on older kernels. It will be rejected as unknown by anything except some pre-2.6.18 kernels. On those kernels we do not want to support dm_restrict, and an attempt to use it will fail. It is OK for the failure to be a messy EINVAL syscall failure. (The IPC namespace unshare is necessary to avoid a suborned deprivileged qemu from causing trouble with shm, sem, etc.)

On the very old kernels, the feature is totally out of scope. (We are only interested, here, in making the build work, to avoid blocking people who aren't using this feature.)

CC Wei Liu <[email protected]>
CC Juergen Gross <[email protected]>
CC Jan Beulich <[email protected]>

---
v3: Adjust commit message with facts about some even older kernels
v2: Get rid of spurious X

---
 tools/libxl/libxl_linux.c | 8 ++++++++
 1 file changed, 8 insertions(+)
tools/libxl/libxl_linux.c +8 -0
index 6475cca64b..59dd945bc1 100644
@@ -18,6 +18,14 @@
 #include <sys/resource.h>
 #include "libxl_internal.h"
 
+
+/* Workarounds for Linux-specific lacks can go here: */
+
+#ifndef CLONE_NEWIPC /* Available as of Linux 2.6.19 / glibc 2.8 */
+# define CLONE_NEWIPC 0x08000000
+#endif
+
+
 int libxl__try_phy_backend(mode_t st_mode)
 {
     if (S_ISBLK(st_mode) || S_ISREG(st_mode)) {
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Acked-by on v3 1/3
#18 lore raw

Re: [PATCH v3 1/3] docs/features/qemu-deprivilege.pandoc: No support with Linux <2.6.18

In reply to Ian Jackson
Quoted 5 lines · Ian Jackson

Some early kernesl are known not to reject unknown flags to unshare(). There may be other problems.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

Acked-by on v3 2/3
#21 lore raw

Re: [PATCH v3 2/3] Revert "libxl: fix build on rather old systems"

In reply to Ian Jackson
Quoted 8 lines · Ian Jackson

This reverts commit 1bce5f9baf0f4a4e50722f32b44afe4fdefc6b35.

This situation should be handled by disabling the dm restrict feature, not silently falling back to lower protection.

Also this #ifdeffery is bad style.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

Acked-by on v3 3/3
#23 lore raw

Re: [PATCH v3 3/3] libxl: fix build (missing CLONE_NEWIPC) on astonishingly old systems

In reply to Ian Jackson
Quoted 20 lines · Ian Jackson

CLONE_NEWIPC was introduced in Linux 2.6.19, on the 29th of November 2006, which was 12 years, 1 month, and 14 days ago.

Nevertheless apparently some people are trying to build Xen on systems whose kernel headers are that old. Placate these people by providing a fallback #define for CLONE_NEWIPC.

The actual binary value will of course remain constant, because of the kernel API promise, so this is and will be correct on all platforms where the CLONE_NEWIPC is supported. (Even if for some reason we miss the right #includes.)

Of course at runtime this value will not work on older kernels. It will be rejected as unknown by anything except some pre-2.6.18 kernels. On those kernels we do not want to support dm_restrict, and an attempt to use it will fail. It is OK for the failure to be a messy EINVAL syscall failure. (The IPC namespace unshare is necessary to avoid a suborned deprivileged qemu from causing trouble with shm, sem, etc.)

Quoted 9 lines

On the very old kernels, the feature is totally out of scope. (We are only interested, here, in making the build work, to avoid blocking people who aren't using this feature.)

CC Wei Liu <[email protected]>
CC Juergen Gross <[email protected]>
CC Jan Beulich <[email protected]>

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#19 lore raw

Re: [PATCH v3 1/3] docs/features/qemu-deprivilege.pandoc: No support with Linux <2.6.18

In reply to Ian Jackson
Quoted 1 line · Ian Jackson

Some early kernesl are known not to reject unknown flags to

s/kernesl/kernels/

Quoted 4 lines

unshare(). There may be other problems.

For the series:

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel