From: Anthony Liguori <aliguori@us.ibm.com>
To: qemu-devel@nongnu.org
Cc: Mark McLoughlin <markmc@redhat.com>,
Anthony Liguori <aliguori@us.ibm.com>,
Arnd Bergmann <arndbergmann@googlemail.com>,
Dustin Kirkland <kirkland@canonical.com>,
Michael Tsirkin <mst@redhat.com>,
Juan Quintela <quintela@redhat.com>
Subject: [Qemu-devel] [PATCH 3/4] Add cap reduction support to enable use as SUID binary
Date: Tue, 3 Nov 2009 18:28:04 -0600 [thread overview]
Message-ID: <1257294485-27015-4-git-send-email-aliguori@us.ibm.com> (raw)
In-Reply-To: <1257294485-27015-1-git-send-email-aliguori@us.ibm.com>
The ideal way to use qemu-bridge-helper is to give it an fscap of using:
setcap cap_net_admin=ep qemu-bridge-helper
Unfortunately, most distros still do not have a mechanism to package files
with fscaps applied. This means they'll have to SUID the qemu-bridge-helper
binary.
To improve security, use libcap to reduce our capability set to just
cap_net_admin, then reduce privileges down to the calling user. This is
hopefully close to equivalent to fscap support from a security perspective.
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
---
configure | 34 ++++++++++++++++++++++++++++++
qemu-bridge-helper.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 90 insertions(+), 0 deletions(-)
diff --git a/configure b/configure
index 7c98257..7c9d3a2 100755
--- a/configure
+++ b/configure
@@ -194,6 +194,7 @@ vnc_tls=""
vnc_sasl=""
xen=""
linux_aio=""
+cap=""
gprof="no"
debug_tcg="no"
@@ -480,6 +481,10 @@ for opt do
;;
--enable-kvm) kvm="yes"
;;
+ --disable-cap) cap="no"
+ ;;
+ --enable-cap) cap="yes"
+ ;;
--enable-profiler) profiler="yes"
;;
--enable-cocoa)
@@ -710,6 +715,8 @@ echo " --disable-vde disable support for vde network"
echo " --enable-vde enable support for vde network"
echo " --disable-linux-aio disable Linux AIO support"
echo " --enable-linux-aio enable Linux AIO support"
+echo " --disable-libcap disable support for libcap"
+echo " --enable-libcap enable support for libcap"
echo " --enable-io-thread enable IO thread"
echo " --disable-blobs disable installing provided firmware blobs"
echo " --kerneldir=PATH look for kernel includes in PATH"
@@ -1108,6 +1115,29 @@ EOF
fi
##########################################
+# cap library probe
+if test "$cap" != "no" ; then
+ cap_libs="-lcap"
+ cat > $TMPC << EOF
+#include <sys/capability.h>
+int main(void)
+{
+ cap_init();
+ return 0;
+}
+EOF
+ if compile_prog "" "$cap_libs" ; then
+ cap=yes
+ libs_tools="$cap_libs $libs_tools"
+ else
+ if test "$cap" = "yes" ; then
+ feature_not_found "cap"
+ fi
+ cap=no
+ fi
+fi
+
+##########################################
# Sound support libraries probe
audio_drv_probe()
@@ -1850,6 +1880,7 @@ echo "fdt support $fdt"
echo "preadv support $preadv"
echo "fdatasync $fdatasync"
echo "uuid support $uuid"
+echo "libcap support $cap"
if test $sdl_too_old = "yes"; then
echo "-> Your SDL version is too old - please upgrade to have SDL support"
@@ -1931,6 +1962,9 @@ fi
if test "$vde" = "yes" ; then
echo "CONFIG_VDE=y" >> $config_host_mak
fi
+if test "$cap" = "yes" ; then
+ echo "CONFIG_LIBCAP=y" >> $config_host_mak
+fi
for card in $audio_card_list; do
def=CONFIG_`echo $card | tr '[:lower:]' '[:upper:]'`
echo "$def=y" >> $config_host_mak
diff --git a/qemu-bridge-helper.c b/qemu-bridge-helper.c
index 0d059ed..73e1c5a 100644
--- a/qemu-bridge-helper.c
+++ b/qemu-bridge-helper.c
@@ -33,6 +33,10 @@
#include "net/tap-linux.h"
+#ifdef CONFIG_LIBCAP
+#include <sys/capability.h>
+#endif
+
#define MAX_ACLS (128)
#define DEFAULT_ACL_FILE CONFIG_QEMU_CONFDIR "/bridge.conf"
@@ -186,6 +190,47 @@ static int send_fd(int c, int fd)
return sendmsg(c, &msg, 0);
}
+#ifdef CONFIG_LIBCAP
+static int drop_privileges(void)
+{
+ cap_t cap;
+ cap_value_t new_caps[] = {CAP_NET_ADMIN};
+
+ cap = cap_init();
+
+ /* set capabilities to be permitted and inheritable. we don't need the
+ * caps to be effective right now as they'll get reset when we seteuid
+ * anyway */
+ cap_set_flag(cap, CAP_PERMITTED, 1, new_caps, CAP_SET);
+ cap_set_flag(cap, CAP_INHERITABLE, 1, new_caps, CAP_SET);
+
+ if (cap_set_proc(cap) == -1) {
+ return -1;
+ }
+
+ cap_free(cap);
+
+ /* reduce our privileges to a normal user */
+ setegid(getgid());
+ seteuid(getuid());
+
+ cap = cap_init();
+
+ /* enable the our capabilities. we marked them as inheritable earlier
+ * which is what allows this to work. */
+ cap_set_flag(cap, CAP_EFFECTIVE, 1, new_caps, CAP_SET);
+ cap_set_flag(cap, CAP_PERMITTED, 1, new_caps, CAP_SET);
+
+ if (cap_set_proc(cap) == -1) {
+ return -1;
+ }
+
+ cap_free(cap);
+
+ return 0;
+}
+#endif
+
int main(int argc, char **argv)
{
struct ifreq ifr;
@@ -199,6 +244,17 @@ int main(int argc, char **argv)
int acl_count = 0;
int i, access_allowed;
+#ifdef CONFIG_LIBCAP
+ /* if we're run from an suid binary, immediately drop privileges preserving
+ * cap_net_admin */
+ if (geteuid() == 0 && getuid() != geteuid()) {
+ if (drop_privileges() == -1) {
+ fprintf(stderr, "failed to drop privileges\n");
+ return 1;
+ }
+ }
+#endif
+
/* parse arguments */
if (argc < 3 || argc > 4) {
fprintf(stderr, "Usage: %s [--use-vnet] BRIDGE FD\n", argv[0]);
--
1.6.2.5
next prev parent reply other threads:[~2009-11-04 0:28 UTC|newest]
Thread overview: 125+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-11-04 0:28 [Qemu-devel] [PATCH 0/4] net-bridge: rootless bridge support for qemu Anthony Liguori
2009-11-04 0:28 ` [Qemu-devel] [PATCH 1/4] Add basic version of bridge helper Anthony Liguori
2009-11-04 0:28 ` [Qemu-devel] [PATCH 2/4] Add access control support to qemu-bridge-helper Anthony Liguori
2009-11-04 13:38 ` [Qemu-devel] [PATCH 2/4] Add access control support toqemu-bridge-helper Krumme, Chris
2009-11-04 14:23 ` Anthony Liguori
2009-11-04 14:37 ` Krumme, Chris
2009-11-05 15:06 ` [Qemu-devel] [PATCH 2/4] Add access control support to qemu-bridge-helper Daniel P. Berrange
2009-11-04 0:28 ` Anthony Liguori [this message]
2009-11-04 0:28 ` [Qemu-devel] [PATCH 4/4] Add support for -net bridge Anthony Liguori
2009-11-04 13:49 ` Krumme, Chris
2009-11-04 14:23 ` Anthony Liguori
2009-11-05 14:41 ` Avi Kivity
2009-11-05 14:45 ` Anthony Liguori
2009-11-05 14:49 ` Avi Kivity
2009-11-06 2:29 ` Jamie Lokier
2009-11-07 17:29 ` David Woodhouse
2009-11-07 22:11 ` Anthony Liguori
2009-11-08 8:27 ` Avi Kivity
2009-11-08 8:43 ` Arnd Bergmann
2009-11-08 8:55 ` Avi Kivity
2009-11-09 14:20 ` Anthony Liguori
2009-11-09 15:39 ` Jamie Lokier
2009-11-09 15:43 ` Anthony Liguori
2009-11-09 19:19 ` Jamie Lokier
2009-11-10 12:23 ` Avi Kivity
2009-11-04 12:02 ` [Qemu-devel] [PATCH 0/4] net-bridge: rootless bridge support for qemu Alexander Graf
2009-11-04 14:42 ` Anthony Liguori
2009-11-04 15:02 ` Alexander Graf
2009-11-04 16:02 ` Anthony Liguori
2009-11-04 17:04 ` [Qemu-devel] " Michael S. Tsirkin
2009-11-04 19:48 ` Anthony Liguori
2009-11-04 20:04 ` Michael S. Tsirkin
2009-11-04 20:44 ` Anthony Liguori
2009-11-05 8:17 ` Michael S. Tsirkin
2009-11-05 13:05 ` Anthony Liguori
2009-11-04 22:40 ` Dustin Kirkland
2009-11-05 0:52 ` Anthony Liguori
2009-11-05 2:12 ` Dustin Kirkland
2009-11-05 4:12 ` [Qemu-devel] " Jamie Lokier
2009-11-05 8:21 ` Michael S. Tsirkin
2009-11-06 2:03 ` Jamie Lokier
2009-11-06 11:58 ` Arnd Bergmann
2009-11-06 20:26 ` Jamie Lokier
2009-11-08 11:55 ` Michael S. Tsirkin
2009-11-05 13:11 ` Anthony Liguori
2009-11-05 14:33 ` Avi Kivity
2009-11-05 14:36 ` Avi Kivity
2009-11-05 14:46 ` Daniel P. Berrange
2009-11-05 14:53 ` Anthony Liguori
2009-11-05 16:41 ` Jamie Lokier
2009-11-05 16:51 ` Daniel P. Berrange
2009-11-06 1:53 ` Jamie Lokier
2009-11-05 14:50 ` Anthony Liguori
2009-11-05 15:05 ` Avi Kivity
2009-11-05 15:50 ` Anthony Liguori
2009-11-05 16:02 ` Avi Kivity
2009-11-05 16:19 ` Anthony Liguori
2009-11-05 16:28 ` Avi Kivity
2009-11-05 16:37 ` Jamie Lokier
2009-11-05 16:45 ` Anthony Liguori
2009-11-05 17:20 ` Arnd Bergmann
2009-11-05 17:42 ` Anthony Liguori
2009-11-05 18:02 ` Arnd Bergmann
2009-11-05 19:54 ` Anthony Liguori
2009-11-05 18:14 ` Avi Kivity
2009-11-05 18:11 ` Avi Kivity
2009-11-05 19:58 ` Anthony Liguori
2009-11-06 1:48 ` Jamie Lokier
2009-11-06 7:22 ` Avi Kivity
2009-11-06 10:54 ` Jamie Lokier
2009-11-06 12:42 ` Anthony Liguori
2009-11-07 3:44 ` Jamie Lokier
2009-11-06 14:19 ` Anthony Liguori
2009-11-07 9:14 ` Avi Kivity
2009-11-07 9:43 ` Avi Kivity
2009-11-07 14:07 ` Anthony Liguori
2009-11-07 21:50 ` Arnd Bergmann
2009-11-07 22:12 ` Anthony Liguori
2009-11-08 8:11 ` Avi Kivity
2009-11-07 14:04 ` Anthony Liguori
2009-11-06 0:29 ` Anthony Liguori
2009-11-06 7:26 ` Avi Kivity
2009-11-06 16:09 ` Anthony Liguori
2009-11-07 9:27 ` Avi Kivity
2009-11-07 10:44 ` Jamie Lokier
2009-11-07 11:23 ` Avi Kivity
2009-11-09 19:35 ` Jamie Lokier
2009-11-10 12:25 ` Avi Kivity
2009-11-10 13:33 ` Jamie Lokier
2009-11-07 13:59 ` Anthony Liguori
2009-11-05 16:29 ` Jamie Lokier
2009-11-05 14:57 ` Anthony Liguori
2009-11-05 15:11 ` Avi Kivity
2009-11-05 15:33 ` Avi Kivity
2009-11-05 15:58 ` Anthony Liguori
2009-11-05 16:07 ` Avi Kivity
2009-11-06 2:19 ` Jamie Lokier
2009-11-05 16:06 ` Anthony Liguori
2009-11-05 16:15 ` Avi Kivity
2009-11-05 16:25 ` Anthony Liguori
2009-11-05 16:33 ` Avi Kivity
2009-11-05 16:50 ` Anthony Liguori
2009-11-05 17:16 ` Scott Tsai
2009-11-05 18:19 ` Avi Kivity
2009-11-06 2:16 ` Jamie Lokier
2009-11-05 18:19 ` Avi Kivity
2009-11-06 2:17 ` Jamie Lokier
2009-11-05 15:11 ` Daniel P. Berrange
2009-11-05 15:14 ` Avi Kivity
2009-11-05 15:20 ` Daniel P. Berrange
2009-11-05 15:59 ` Anthony Liguori
2009-11-05 16:20 ` Avi Kivity
2009-11-05 16:28 ` Anthony Liguori
2009-11-05 16:35 ` Avi Kivity
2009-11-05 16:53 ` Daniel P. Berrange
2009-11-05 17:03 ` Anthony Liguori
2009-11-05 17:16 ` Daniel P. Berrange
2009-11-06 2:08 ` Jamie Lokier
2009-11-05 17:26 ` Arnd Bergmann
2009-11-05 19:54 ` Gerhard Stenzel
2009-11-06 2:11 ` Jamie Lokier
2009-11-05 15:00 ` [Qemu-devel] " Mark McLoughlin
2009-11-05 15:14 ` Daniel P. Berrange
2009-11-05 15:28 ` Dustin Kirkland
2009-11-05 15:06 ` Arnd Bergmann
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=1257294485-27015-4-git-send-email-aliguori@us.ibm.com \
--to=aliguori@us.ibm.com \
--cc=arndbergmann@googlemail.com \
--cc=kirkland@canonical.com \
--cc=markmc@redhat.com \
--cc=mst@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=quintela@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).