Run dm_restrict=1 tests, and audit the qemu
cover Run dm_restrict=1 tests, and audit the qemu
From: Ian Jackson <[email protected]>
This series adds tests with the xl/libxl dm_restrict=1 feature enabled (to tests of Xen 4.10 and later).
Save/restore and migration is disabled in this tests for now, as that is broken in xen.git.
This series also adds auditing of the deprivileged qemu's file descriptors. That auditing depends on a new test utility in xen.git. That utility is not yet present in any xen.git upstream branch and is currently targeted at Xen 4.12. Without it, the audit test will bomb out (ie, be a test failure). This is fine; when the tool is available, the test should start to pass.
Ian Jackson (12):
sg-run-job: Provide new recipe-flag facility
sg-run-job: Allow flight to specify recipe flag to disable migr tests
ts-xen-install: Create xen-qemuuser-range-base
more_prepareguest_hvm: Honour guest runvar dmrestrict
make-flight: Add a single test with restricted dm
ts-xen-install: Honour DebianExtraPackages_<suite>
toolstack: Provide guest_create_paused
toolstack: Provide guest_unpause
dm restrict audit: install newer chiark-scripts for fishdescriptor dm restrict audit: Provide auditing script
dm restrict audit: Run ts-depriv-audit-qemu
dm restrict audit: Document future plans
Osstest/Debian.pm | 5 + Osstest/TestSupport.pm | 20 ++- Osstest/Toolstack/xl.pm | 22 ++- README | 1 + make-flight | 15 ++ overlay/usr/local/bin/osstest-depriv-fd-collector | 94 ++++++++++++ production-config | 2 + production-config-cambridge | 2 + sg-run-job | 18 +++ ts-depriv-audit-qemu | 170 ++++++++++++++++++++++ ts-xen-install | 6 + 11 files changed, 353 insertions(+), 2 deletions(-) create mode 100755 overlay/usr/local/bin/osstest-depriv-fd-collector create mode 100755 ts-depriv-audit-qemu
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 1/17 db_retry: Honour new OSSTEST_DB_ALWAYS_ABORT variable
This is useful for debugging.
--- Osstest.pm | 2 ++ 1 file changed, 2 insertions(+)
Osstest.pm +2 -0
@@ -330,6 +330,8 @@ sub db_retry ($$$;$$) { last if $db_retry_stop eq 'abort'; next; } + die 'OSSTEST_DB_ALWAYS_ABORT set' + if $ENV{'OSSTEST_DB_ALWAYS_ABORT'}; $committing = 1; $dbh->commit(); };
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 2/17 cs-bisection-step: Improve a message
In reply to Ian Jackson--- cs-bisection-step | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
cs-bisection-step +1 -1
@@ -1208,7 +1208,7 @@ END if ($cache_option and $cacheok and $recipe =~ m/^build/ and !@$subjobs) { my $reusejob= $builds_investigated{$popjob}; if (!defined $reusejob) { - print STDERR "Searching for $popflight.$popjob to reuse...\n"; + print STDERR "Searching for $popjob (like $copyflight) to reuse...\n"; $reusejob = $dbh_tests->selectrow_hashref(<<END,{}, $popjob,$popjob); SELECT *
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 3/17 cs-bisection-step: Refactor $subjobs calculations a bit
In reply to Ian JacksonParse the runvar name earlier, adding job and orgflight members to the row hashes we got from the db. This slightly unifies the call to preparejob, but more relevantly, makes the effective job and flight information available earlier. That will be useful in a moment.
No functional change.
--- cs-bisection-step | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)
cs-bisection-step +12 -6
@@ -1197,6 +1197,17 @@ END my $subjobs= $jobq->fetchall_arrayref( {} ); $jobq->finish(); + foreach my $subjob (@$subjobs) { + my $jobspec= $subjob->{val}; + if ($jobspec =~ m/^(\d+)\.(.+)$/) { + $subjob->{job} = $2; + $subjob->{orgflight} = $1; + } else { + $subjob->{job} = $jobspec; + $subjob->{orgflight} = $copyflight; + } + } + # See if there's a build we can reuse my ($recipe) = $dbh_tests->selectrow_array(<<END,{}, $copyflight,$popjob);
@@ -1277,12 +1288,7 @@ END END foreach my $subjob (@$subjobs) { my $target; - my $jobspec= $subjob->{val}; - if ($jobspec =~ m/^(\d+)\.(.+)$/) { - $target= preparejob($2, $1, 1); - } else { - $target= preparejob($jobspec, $copyflight, 1); - } + $target= preparejob($subjob->{job}, $subjob->{orgflight}, 1); $jobsetq->execute($target, $popflight, $popjob, $subjob->{name}); } $jobsetq->finish();
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 4/17 cs-bisection-step: Handle build job chains
In reply to Ian Jacksoncs-bisection-step assumes that every job it will need to create has a unique name. Indeed, in general, it is probably not reasonable to expect it to work if that is not the case.
build-amd64-freebsd needs a previous build-amd64-freebsd.
Currently cs-bisection-step confuses itself into writing a flight where build-amd64-freebsd uses itself as its freebsdbuildjob. This naturally does not work very well.
I think the right approach is for cs-bisection-step to spot when it its recursion through the jobs, via *job runvars, would descend into a job name which it was already encoutered earlier in the dependency chain, and, when that occurs, to simply skip regenerating that deeper copy of the job.
That is achieved here by filtering the subjob out of the list, before we go looking for jobs to reuse. As a result, not only will no new job be created, but the original deeper job will be reused because the runvar value will not be updated.
FTR, the circular dependency produces this error from sg-execute-flight:
wait for process failed: no children
while executing
"wait -nohang"
(procedure "main_iteration" line 14)
invoked from within
"main_iteration"
(procedure "main" line 8)
invoked from within
"main"
(file "./sg-execute-flight" line 238)
This is because sg-execute-flight's algorithm assumes that if there are no jobs running there must be some job whose dependencies are done. That is true if the job graph has no cycles.
Improving the error message from sg-execute-flight is left as an exercise for the future.
--- cs-bisection-step | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
cs-bisection-step +21 -0
@@ -1133,6 +1133,7 @@ END our %jobs_created; our %builds_investigated; # $builds_investigated{$popjob} = 0, or {..row..} +our %recursion_track; sub preparejob ($$$); sub preparejob ($$$) {
@@ -1144,6 +1145,11 @@ sub preparejob ($$$) { return $jobs_created{$popjob}; } + local $recursion_track{$popjob} = { + Depth => (1 + keys %recursion_track), + Spec => "$copyflight.$popjob" + }; + print STDERR "Need $popflight.$popjob (like $copyflight)\n"; # Create a temporary table containing the runvars we want
@@ -1208,6 +1214,21 @@ END } } + @$subjobs = grep { + if ($recursion_track{ $_->{job} }) { + print STDERR "Not recursively creating another $_->{job} (". + ( + join " -> ", + map { $_->{Spec} } + sort { $a->{Depth} <=> $b->{Depth} } + values %recursion_track + ). " -> $_->{orgflight}.$_->{job}\n"; + 0; + } else { + 1; + } + } @$subjobs; + # See if there's a build we can reuse my ($recipe) = $dbh_tests->selectrow_array(<<END,{}, $copyflight,$popjob);
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 5/17 cs-bisection-step: Do explicitly set runvar for suppressed recursion
In reply to Ian JacksonWhen we detect that we are considering a job which is identically named to one earlier in the dependency chain, it could happen that the final referencing runvar in the job at which we break the cycle is actually to an unqualified job name.
(This cannot happen unless the cycle has more than 2 jobs, and therefore more than one job name, because otherwise the job we would be copying would have a self-reference. So it cannot occur right now.)
So when breaking the cycle, we should update the job we are building to refer to the exact flight and job we want it to reuse.
The most convenient way to do this is to reorganise the new recursion suppression code: we retain the suppressed entries in $subjobs, and filter them as appropriate.
--- cs-bisection-step | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-)
cs-bisection-step +20 -16
@@ -1214,20 +1214,17 @@ END } } - @$subjobs = grep { - if ($recursion_track{ $_->{job} }) { - print STDERR "Not recursively creating another $_->{job} (". - ( - join " -> ", - map { $_->{Spec} } - sort { $a->{Depth} <=> $b->{Depth} } - values %recursion_track - ). " -> $_->{orgflight}.$_->{job}\n"; - 0; - } else { - 1; - } - } @$subjobs; + foreach my $subjob (@$subjobs) { + next unless $recursion_track{ $subjob->{job} }; + $subjob->{suppress} = 1; + print STDERR "Not recursively demanding another $subjob->{job} (". + ( + join " -> ", + map { $_->{Spec} } + sort { $a->{Depth} <=> $b->{Depth} } + values %recursion_track + ). " -> $subjob->{orgflight}.$subjob->{job}\n"; + } # See if there's a build we can reuse
@@ -1237,7 +1234,8 @@ END my $usejob; - if ($cache_option and $cacheok and $recipe =~ m/^build/ and !@$subjobs) { + if ($cache_option and $cacheok and $recipe =~ m/^build/ + and !grep { !$_->{suppress} } @$subjobs) { my $reusejob= $builds_investigated{$popjob}; if (!defined $reusejob) { print STDERR "Searching for $popjob (like $copyflight) to reuse...\n";
@@ -1309,7 +1307,13 @@ END END foreach my $subjob (@$subjobs) { my $target; - $target= preparejob($subjob->{job}, $subjob->{orgflight}, 1); + if ($subjob->{suppress}) { + $target = "$subjob->{orgflight}.$subjob->{job}"; + print STDERR "Reusing $target for $subjob->{name}". + " in $popflight.$popjob\n"; + } else { + $target= preparejob($subjob->{job}, $subjob->{orgflight}, 1); + } $jobsetq->execute($target, $popflight, $popjob, $subjob->{name}); } $jobsetq->finish();
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 6/17 sg-run-job: Provide new recipe-flag facility
In reply to Ian JacksonIndividual recipes can now honour modifications requested by setting runvars like recipe_<flag>.
No callers yet so no functional change.
--- sg-run-job | 7 +++++++ 1 file changed, 7 insertions(+)
sg-run-job +7 -0
@@ -160,6 +160,13 @@ proc testid_matches_globs {testid globs} { return 0 } +proc recipe-flag {flagname {def 0}} { + global flight jobinfo + set name "recipe_$flagname" + set val [jobdb::read-runvar $flight $jobinfo(job) $name $def] + return [regexp {true|y|1} $val] +} + #---------- test script handling ---------- # spwan-ts IFFAIL TESTID SCRIPT-ARGS...
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 7/17 sg-run-job: Allow flight to specify recipe flag to disable migr tests
In reply to Ian JacksonWe want this because there is no sensible way to probe whether a restricted qemu can cope with save/restore or migration. So we will want to disable it in flight construction (depending on Xen version, eventually).
--- sg-run-job | 3 +++ 1 file changed, 3 insertions(+)
sg-run-job +3 -0
@@ -591,6 +591,9 @@ proc run-job/test-livepatch {} { } proc test-guest-migr {g} { + # guest is expected to be running and remains so + if {[recipe-flag nomigrate]} return + set to_reap [spawn-ts . = ts-migrate-support-check + host $g 1] set can_migrate [reap-ts $to_reap] set to_reap [spawn-ts . = ts-saverestore-support-check + host $g]
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 8/17 ts-xen-install: Create xen-qemuuser-range-base
In reply to Ian JacksonIt is fine to do in all jobs. libxl will only use this if we ask it to.
We do need to check whether the user exists already, since adduser does not seem to have a mode which exits zero in that case.
--- ts-xen-install | 3 +++ 1 file changed, 3 insertions(+)
ts-xen-install +3 -0
@@ -129,6 +129,9 @@ END } sub adjustconfig () { + my $quser = 'xen-qemuuser-range-base'; + target_cmd_root($ho, "id $quser || adduser --system --uid=200000 $quser"); + target_editfile_root($ho, "/etc/xen/xend-config.sxp", "xend-config.sxp", sub { my (@domains) = (qw(localhost localhost.localdomain),
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 9/17 more_prepareguest_hvm: Honour guest runvar dmrestrict
In reply to Ian JacksonCurrently nothing sets this.
--- Osstest/TestSupport.pm | 4 ++++ 1 file changed, 4 insertions(+)
Osstest/TestSupport.pm +4 -0
@@ -2066,6 +2066,10 @@ END $cfg .= "device_model_version='$devmodel'\n"; } + if (guest_var_boolean($gho, 'dmrestrict')) { + $cfg .= "dm_restrict=1\n"; + } + my $bios = $xopts{'Bios'}; if (defined $bios) { $cfg .= "bios='$bios'\n";
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 10/17 make-flight: Add a single test with restricted dm
In reply to Ian JacksonAs of this commit, this test is only functional: we don't do any auditing yet.
Right now save/restore migration is broken with restricted dm, so disable that test with the recipe flag. See
sg-run-job: Allow flight to specify recipe flag to disable migr tests
Run this only on recent enough Xen: the dm_restrict option was added as an experimental feature in Xen 4.10 (currently as yet unreleased). (With older libxl/xl, the option would be ignored and the test would be a waste of time.)
--- make-flight | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
make-flight +14 -0
@@ -442,6 +442,20 @@ do_hvm_debian_tests() { # For libvirt we only generate -xsm test case. if [ "x$qemuu_suffix" == "x-qemuu" ]; then do_hvm_debian_test_one ovmf xl ovmf false + + case $xenbranch in + xen-3.*-testing) dmrestrict=false ;; + xen-4.[0-9]-testing) dmrestrict=false ;; + *) dmrestrict=true ;; + esac + + if $dmrestrict; then + do_hvm_debian_test_one dmrestrict xl seabios false '' -dmrestrict ' + debianhvm_dmrestrict=true + recipe_nomigrate=true + ' + fi + for xsm in $xsms ; do do_hvm_debian_test_one debianhvm xl seabios $xsm if [ x$xsm = xtrue ]; then
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 11/17 ts-xen-install: Honour DebianExtraPackages_<suite>
In reply to Ian JacksonThis allows us to specify some packages to install regardless of firmware and architecture.
--- README | 1 + ts-xen-install | 3 +++ 2 files changed, 4 insertions(+)
README +1 -0
@@ -537,6 +537,7 @@ DebianNonfreeFirmware grep-dctrl (for example because it's not Debian) then you must set this to the empty string, by writing DebianNonfreeFirmware='' +DebianExtraPackages_<suite> [<item>... ] DebianExtraPackages_<firmware>_<arch>_<suite> [<item>... ] Extra packages, or directories of them, to install on every Debian host (dom0). Each variable is a space-separated list of items.
ts-xen-install +3 -0
@@ -106,6 +106,9 @@ sub some_extradebs ($) { sub extradebs () { my $suite = $ho->{Suite}; + # $c{ DebianExtraPackages_<suite> } + some_extradebs([ 'DebianExtraPackages', $suite ]); + # $c{ DebianExtraPackages_<firmware>_<arch>_<suite> } my $firmware = get_host_property($ho, "firmware", "bios"); some_extradebs([ 'DebianExtraPackages', $firmware, $r{arch}, $suite ]);
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 12/17 toolstack: Provide guest_create_paused
In reply to Ian JacksonOnly for xl (and xm) for now.
--- Osstest/TestSupport.pm | 9 ++++++++- Osstest/Toolstack/xl.pm | 14 +++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-)
Osstest/TestSupport.pm +8 -1
@@ -119,7 +119,7 @@ BEGIN { guest_check_remus_ok guest_editconfig guest_prepare_disk guest_unprepare_disk host_involves_pcipassthrough host_get_pcipassthrough_devs - toolstack guest_create + toolstack guest_create guest_create_paused await_webspace_fetch_byleaf create_webfile file_link_contents get_timeout
@@ -1702,6 +1702,13 @@ sub guest_create ($) { toolstack($ho,$gho)->create($gho); } +sub guest_create_paused ($) { + my ($gho) = @_; + my $ho = $gho->{Host}; + guest_prepare_disk($gho); + toolstack($ho,$gho)->create_paused($gho); +} + sub guest_prepare_disk ($) { my ($gho) = @_;
Osstest/Toolstack/xl.pm +13 -1
@@ -40,10 +40,22 @@ sub destroy ($$) { target_cmd_root($self->{Host}, $self->{_Command}." destroy $gn", 40); } +sub _create ($$$) { + my ($self,$gho,$options) = @_; + my $cfg = $gho->{CfgPath}; + target_cmd_root($self->{Host}, + $self->{_VerboseCommand}." create $options $cfg", 100); +} + sub create ($$) { my ($self,$gho) = @_; + return $self->_create($gho,''); +} + +sub create_paused ($$) { + my ($self,$gho) = @_; + return $self->_create($gho,'-p'); my $cfg = $gho->{CfgPath}; - target_cmd_root($self->{Host}, $self->{_VerboseCommand}." create $cfg", 100); } sub consolecmd ($$) {
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 13/17 toolstack: Provide guest_unpause
In reply to Ian JacksonOnly for xl (and xm) for now.
--- Osstest/TestSupport.pm | 7 +++++++ Osstest/Toolstack/xl.pm | 8 ++++++++ 2 files changed, 15 insertions(+)
Osstest/TestSupport.pm +7 -0
@@ -115,6 +115,7 @@ BEGIN { guest_find_domid guest_check_up guest_check_up_quick guest_get_state guest_await_reboot guest_await_shutdown guest_await_destroy guest_destroy + guest_unpause guest_vncsnapshot_begin guest_vncsnapshot_stash guest_check_remus_ok guest_editconfig guest_prepare_disk guest_unprepare_disk
@@ -1689,6 +1690,12 @@ sub guest_destroy ($) { guest_unprepare_disk($gho); } +sub guest_unpause ($) { + my ($gho) = @_; + my $ho = $gho->{Host}; + toolstack($ho)->unpause($gho); +} + sub guest_await_destroy ($$) { my ($gho, $timeout) = @_; my $ho = $gho->{Host};
Osstest/Toolstack/xl.pm +8 -0
@@ -58,6 +58,14 @@ sub create_paused ($$) { my $cfg = $gho->{CfgPath}; } +sub unpause ($$) { + my ($self,$gho) = @_; + my $gn = $gho->{Name}; + target_cmd_root($self->{Host}, + $self->{_VerboseCommand}." unpause $gn", 100); + +} + sub consolecmd ($$) { my ($self,$gho) = @_; my $gn = $gho->{Name};
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 14/17 dm restrict audit: install newer chiark-scripts for fishdescriptor
In reply to Ian Jacksonfishdescriptor is not in stretch or earlier. It will be in buster, and we expect that a suitable version will be available in stretch-backports soon.
For jessie, use DebianExtraPackages to install the .deb from buster (which is directly installable on jessie).
Deployment note: I have already copied the .deb to the images directories in Massachusetts and Cambridge.
--- Osstest/Debian.pm | 5 +++++ production-config | 2 ++ production-config-cambridge | 2 ++ 3 files changed, 9 insertions(+)
Osstest/Debian.pm +5 -0
@@ -1023,6 +1023,11 @@ sub preseed_create_guest ($$$;@) { $extra_packages = "pv-grub-menu"; } } + if (grep { m/_dmrestrict$/ && $r{$_} } keys %r and + $suite =~ m/stretch/) { + preseed_backports_packages($ho, $sfx, \%xopts, $suite, + qw(chiark-utils-bin)); + } my $preseed_file= preseed_base($ho, $sfx, $extra_packages, %xopts); $preseed_file.= (<<END);
production-config +2 -0
@@ -106,6 +106,8 @@ MicrocodeUpdateI386 microcode.x86.2015-06-12.cpio # Update with ./mg-netgrub-loader-update TftpGrubVersion XXXX-XX-XX +DebianExtraPackages_jessie chiark-scripts_6.0.2_all.deb + DebianExtraPackages_uefi_i386_jessie extradebs-uefi-i386-2018-04-01/ DebianExtraPackages_uefi_amd64_jessie extradebs-uefi-amd64-2018-04-01/ DebianExtraPackages_uefi_i386_stretch extradebs-uefi-i386-2018-04-01/
production-config-cambridge +2 -0
@@ -79,6 +79,8 @@ TftpDiVersion_jessie 2018-04-09 DebianImageVersion_wheezy 7.2.0 DebianImageVersion_jessie 8.2.0 +DebianExtraPackages_jessie chiark-scripts_6.0.2_all.deb + # These should normally be the same. MicrocodeUpdateAmd64 microcode.x86.2015-06-12.cpio MicrocodeUpdateI386 microcode.x86.2015-06-12.cpio
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 15/17 dm restrict audit: Provide auditing script
In reply to Ian Jacksonts-depriv-audit-qemu knows how to create a domain paused, and audit its fds. It uses
* osstest-depriv-fd-collector, an on-test-host helper script
* fishdescriptor, a new utility program in chiark-scripts
* depriv-fd-checker, a new test program in xen.git
--- overlay/usr/local/bin/osstest-depriv-fd-collector | 94 +++++++++++++ ts-depriv-audit-qemu | 154 ++++++++++++++++++++++ 2 files changed, 248 insertions(+) create mode 100755 overlay/usr/local/bin/osstest-depriv-fd-collector create mode 100755 ts-depriv-audit-qemu
overlay/usr/local/bin/osstest-depriv-fd-collector new file +94 -0
@@ -0,0 +1,94 @@ +#!/usr/bin/perl -w +# +# usage: osstest-depriv-fd-collector <pid> +# +# audits that <pid> has only depriv fds, eg for a depriv qemu +# +# output is series of lines +# <class> pass|fail <fd> <info> repeated for each fd +# [<pid>] <fd> sockinfo... as from fishdescriptor +# generic unknown <fd> </proc link target> +# +# fishdescriptor on every fd in <pid> +# check what kind of fd it is +# +# classes are +# generic +# (handled here) +# appendonly +# readonly +# privcmd +# gntdev +# evtchn +# (passed to fishdescriptor and depriv-fd-checker) + +# This is part of "osstest", an automated testing framework for Xen. +# Copyright (C) 2018 Citrix Inc. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +use strict; + +die unless @ARGV==2; +our ($pid,$checker) = @ARGV; +die unless $pid =~ m{^\d+$}; + +our @fdchecks; +our @fdsockinfos; + +open F, "find /proc/$pid/fd/* -printf '%f %l\\n' |" or die $!; +while (<F>) { + chomp; + die "$_ ?" unless s/^(\d+) //; + my $fd = $1; + if (m{^/dev/null$} || + m{^pipe:} || + m{^anon_inode:\[(?:signalfd|eventfd|eventpoll)\]$}) { + print "generic pass $fd $_\n" or die $!; + } elsif (m{^/var/log/xen/qemu-dm-.*\.log$}) { + push @fdchecks, [ $fd, 'appendonly', $_ ]; + } elsif (m{^/dev/urandom$} || + m{^/root/.*.iso}) { + push @fdchecks, [ $fd, 'readonly', $_ ]; + } elsif (m{^/dev/xen/(privcmd|gntdev|evtchn)$}) { + push @fdchecks, [ $fd, $1, $_ ]; + } elsif (m{^/dev/net/tun$}) { + push @fdchecks, [ $fd, 'tun', $_ ]; + } elsif (m{^socket:}) { + push @fdsockinfos, $fd; + } else { + print "generic unknown $fd $_\n" or die $!; + } +} +close F or die "$? $!"; + +my @fish = (qw(fishdescriptor), $pid); +my @chk = $checker; + +foreach my $fd (@fdsockinfos) { + push @fish, $fd, qw(sockinfo); +} + +foreach my $fdi (@fdchecks) { + my ($fd, $class, $rhs) = @$fdi; + my $fish_fd = $fd + 100; + push @fish, "$fish_fd=$fd"; + push @chk, $class, $fish_fd, "$fd=$rhs"; +} + +my @cmd = (@fish, qw(exec), @chk); + +print STDERR "$0 running @cmd\n"; + +exec @cmd or die $!;
ts-depriv-audit-qemu new file +154 -0
154 lines not on this page · raw message
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 16/17 dm restrict audit: Run ts-depriv-audit-qemu
In reply to Ian JacksonAdd the new steps to jobs where the `recipe_dmrestrict' runvars is set, and set that flag on the relevant job.
We introduce the new recipe-flag proc in sg-run-job to make this more convenient.
--- make-flight | 1 + sg-run-job | 8 ++++++++ 2 files changed, 9 insertions(+)
make-flight +1 -0
@@ -452,6 +452,7 @@ do_hvm_debian_tests() { if $dmrestrict; then do_hvm_debian_test_one dmrestrict xl seabios false '' -dmrestrict ' debianhvm_dmrestrict=true + recipe_dmrestrict=true recipe_nomigrate=true ' fi
sg-run-job +8 -0
@@ -617,6 +617,14 @@ proc test-guest {g} { # guest is expected to be running, and ends up stopped test-guest-migr $g test-guest-nomigr $g + test-guest-dmrestrict $g +} + +proc test-guest-dmrestrict {g} { + # guest is expected to be stopped, and is left stopped + if {![recipe-flag dmrestrict]} return + run-ts . = ts-depriv-audit-qemu create + host $g + run-ts . =.audited ts-guest-stop + host $g } proc test-guest-nomigr {g} {
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 17/17 dm restrict audit: Document future plans
In reply to Ian Jackson--- ts-depriv-audit-qemu | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
ts-depriv-audit-qemu +16 -0
@@ -56,6 +56,9 @@ END /usr/local/lib/xen/bin/depriv-fd-checker END stashfilecontents($fish_output,"fish-info-paused.txt"); + + # Ideally we would check other process properties too: + # eg, check that qemu has chrooted; check its uid; etc. } sub packages () {
@@ -139,6 +142,19 @@ sub mode_ispaused () { audit_fish(); } +# In the future when migration works, we would like to audit the qemu +# receiving the migration stream. This auditing should be done just +# before the qemu starts reading the stream, as the stream might be +# hostile and might be able to take over the receiving qemu. +# I intend the following approach: +# install wrapper script for qemu, which: +# looks for -incoming fd:%d (libxl_dm.c:1416) +# substitutes a pipe which will cause qemu to block +# waits a fixed time +# maybe checks that qemu is reading that fd somehow +# runs the audit and leaves the output somewhere we can find it +# arranges for the blocking pipe thing to use cat to unblock qemu + compile_data_re(); $modesubproc->();
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel