From: George Dunlap <george.dunlap@citrix.com>
To: xen-devel@lists.xenproject.org
Cc: Stefano Stabellini <sstabellini@kernel.org>,
Wei Liu <wei.liu2@citrix.com>,
George Dunlap <george.dunlap@citrix.com>,
Ross Lagerwall <ross.lagerwall@citrix.com>,
Anthony Perard <anthony.perard@citrix.com>,
Ian Jackson <ian.jackson@citrix.com>
Subject: [PATCH v2 2/6] test/depriv: Add a tool to check process-level depriv
Date: Fri, 21 Sep 2018 18:04:24 +0100 [thread overview]
Message-ID: <20180921170428.13771-2-george.dunlap@citrix.com> (raw)
In-Reply-To: <20180921170428.13771-1-george.dunlap@citrix.com>
Add a tool to check whether the various process-level deprivileging
operations have actually taken place on the process.
The tool takes a domname or domid, and returns success or failure.
To begin with, only test the process/group it setting, since this is
the only restriction currently implemented.
Signed-off-by: George Dunlap <george.dunlap@citrix.com>
---
CC: Ian Jackson <ian.jackson@citrix.com>
CC: Wei Liu <wei.liu2@citrix.com>
CC: Stefano Stabellini <sstabellini@kernel.org>
CC: Anthony Perard <anthony.perard@citrix.com>
CC: Ross Lagerwall <ross.lagerwall@citrix.com>
---
tools/tests/depriv/depriv-process-checker.sh | 71 ++++++++++++++++++++
1 file changed, 71 insertions(+)
create mode 100755 tools/tests/depriv/depriv-process-checker.sh
diff --git a/tools/tests/depriv/depriv-process-checker.sh b/tools/tests/depriv/depriv-process-checker.sh
new file mode 100755
index 0000000000..4aa58e7760
--- /dev/null
+++ b/tools/tests/depriv/depriv-process-checker.sh
@@ -0,0 +1,71 @@
+#!/bin/bash
+
+domain="$1"
+
+if [[ "$domain" =~ ^[0-9]+$ ]] ; then
+ domid="$domain"
+else
+ domid=$(xl domid "$domain")
+fi
+
+dmpid=$(xenstore-read /local/domain/$domid/image/device-model-pid 2>/dev/null)
+if [[ -z "$dmpid" ]] ; then
+ echo "xenstore-read failed"
+ exit 1
+fi
+
+failed="false"
+
+# TEST: Process / group id
+#
+# Read /proc/<qpid>/status, checking Uid and Gid lines
+#
+# Uid should be xen-qemuuser-range-base+$domid
+# Gid should be 65534 ("nobody")
+# FIXME: deal with other UID configurations?
+echo -n "Process UID: "
+tgt_uid=$(id -u xen-qemuuser-range-base)
+tgt_uid=$(( $tgt_uid + $domid ))
+
+# Example input:
+# Uid: 1193 1193 1193 1193
+input=$(grep Uid /proc/$dmpid/status)
+if [[ "$input" =~ ^Uid:[[:space:]]*([0-9]+)[[:space:]]*([0-9]+)[[:space:]]*([0-9]+)[[:space:]]*([0-9]+)$ ]] ; then
+ result="PASSED"
+ for i in {1..4}; do
+ if [[ "${BASH_REMATCH[$i]}" != "$tgt_uid" ]] ; then
+ result="FAILED"
+ failed="true"
+ break
+ fi
+ done
+else
+ result="FAILED"
+ failed="true"
+fi
+echo $result
+
+# Example input:
+# Gid: 10020 10020 10020 10020
+echo -n "Process GID: "
+input=$(grep Uid /proc/$dmpid/status)
+if [[ "$input" =~ ^Gid:[[:space:]]*([0-9]+)[[:space:]]*([0-9]+)[[:space:]]*([0-9]+)[[:space:]]*([0-9]+)$ ]] ; then
+ result="PASSED"
+ for i in {1..4}; do
+ if [[ "${BASH_REMATCH[$i]}" != "$65534" ]] ; then
+ result="FAILED"
+ failed="true"
+ break
+ fi
+ done
+else
+ result="FAILED"
+ failed="true"
+fi
+echo $result
+
+if $failed ; then
+ exit 1
+else
+ exit 0
+fi
--
2.18.0
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
next prev parent reply other threads:[~2018-09-21 17:04 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-21 17:04 [PATCH v2 1/6] docs/qemu-deprivilege: Revise and update with status and future plans George Dunlap
2018-09-21 17:04 ` George Dunlap [this message]
2018-09-24 10:57 ` [PATCH v2 2/6] test/depriv: Add a tool to check process-level depriv Ian Jackson
2018-09-24 14:45 ` George Dunlap
2018-09-24 11:14 ` Anthony PERARD
2018-09-21 17:04 ` [PATCH v2 3/6] tools/dm_restrict: Ask QEMU to chroot George Dunlap
2018-09-24 8:20 ` Paul Durrant
2018-09-24 9:50 ` George Dunlap
2018-09-24 9:52 ` Paul Durrant
2018-09-24 10:31 ` Ian Jackson
2018-09-21 17:04 ` [PATCH v2 4/6] tools/dm_restrict: Unshare mount and IPC namespaces on Linux George Dunlap
2018-09-24 8:24 ` Paul Durrant
2018-09-24 10:40 ` Ian Jackson
2018-09-24 14:22 ` George Dunlap
2018-09-25 10:55 ` Ian Jackson
2018-09-21 17:04 ` [PATCH v2 5/6] tools/dm_depriv: Add first cut RLIMITs George Dunlap
2018-09-24 8:34 ` Paul Durrant
[not found] ` <CAFLBxZanne777R0WfJLuGqTv3dx=A+W0Z5UsW9B0i4MFMWWKXw@mail.gmail.com>
2018-10-05 15:18 ` George Dunlap
2018-09-24 10:48 ` Ian Jackson
2018-09-24 14:41 ` George Dunlap
2018-09-25 11:03 ` Ian Jackson
2018-09-21 17:04 ` [PATCH v2 6/6] RFC: tools/dm_restrict: Enable QEMU sandboxing George Dunlap
2018-09-24 10:49 ` Ian Jackson
2018-09-24 11:16 ` George Dunlap
2018-09-24 13:04 ` Ian Jackson
2018-09-24 13:43 ` George Dunlap
2018-09-25 10:46 ` Ian Jackson
2018-09-24 11:21 ` Ian Jackson
2018-09-24 14:28 ` George Dunlap
2018-09-25 11:02 ` Ian Jackson
2018-09-25 14:24 ` George Dunlap
2018-09-26 10:57 ` Ian Jackson
2018-09-24 8:14 ` [PATCH v2 1/6] docs/qemu-deprivilege: Revise and update with status and future plans Paul Durrant
2018-09-24 10:23 ` Ian Jackson
2018-09-24 13:08 ` George Dunlap
2018-09-25 10:44 ` Ian Jackson
2018-09-25 11:20 ` Anthony PERARD
2018-09-28 11:37 ` George Dunlap
2018-09-28 12:59 ` Anthony PERARD
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=20180921170428.13771-2-george.dunlap@citrix.com \
--to=george.dunlap@citrix.com \
--cc=anthony.perard@citrix.com \
--cc=ian.jackson@citrix.com \
--cc=ross.lagerwall@citrix.com \
--cc=sstabellini@kernel.org \
--cc=wei.liu2@citrix.com \
--cc=xen-devel@lists.xenproject.org \
/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.