[lxc-devel] [lxc/stable-2.0] caps: check uid and euid

brauner on Github lxc-bot at linuxcontainers.org
Fri Feb 8 14:18:18 UTC 2019


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 525 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20190208/e25e22b8/attachment.bin>
-------------- next part --------------
From 8d18e582f87998e2ae1d7ce8729467d1721c20ac Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Fri, 8 Feb 2019 15:11:46 +0100
Subject: [PATCH] caps: check uid and euid

When we are running inside of a user namespace getuid() will return a
non-zero uid. So let's check euid as well to make sure we correctly drop
capabilities

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 src/lxc/caps.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/src/lxc/caps.c b/src/lxc/caps.c
index 5638c712e..1346ec74f 100644
--- a/src/lxc/caps.c
+++ b/src/lxc/caps.c
@@ -154,8 +154,7 @@ int lxc_ambient_caps_up(void)
 	int last_cap = CAP_LAST_CAP;
 	char *cap_names = NULL;
 
-	/* When we are run as root, we don't want to play with the capabilities. */
-	if (!getuid())
+	if (!getuid() || geteuid())
 		return 0;
 
 	caps = cap_get_proc();
@@ -222,8 +221,7 @@ int lxc_ambient_caps_down(void)
 	cap_t caps;
 	cap_value_t cap;
 
-	/* When we are run as root, we don't want to play with the capabilities. */
-	if (!getuid())
+	if (!getuid() || geteuid())
 		return 0;
 
 	ret = prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_CLEAR_ALL, 0, 0, 0);


More information about the lxc-devel mailing list