[Qemu-devel] [PATCH v2 03/18] tests/vm/openbsd: Disable the W^X protection on the build partition

Philippe Mathieu-Daudé posted 18 patches 6 years, 9 months ago
Maintainers: "Philippe Mathieu-Daudé" <philmd@redhat.com>, Igor Mammedov <imammedo@redhat.com>, Kevin Wolf <kwolf@redhat.com>, Max Reitz <mreitz@redhat.com>, "Michael S. Tsirkin" <mst@redhat.com>, Fam Zheng <fam@euphon.net>, "Alex Bennée" <alex.bennee@linaro.org>, Brad Smith <brad@comstyle.com>
[Qemu-devel] [PATCH v2 03/18] tests/vm/openbsd: Disable the W^X protection on the build partition
Posted by Philippe Mathieu-Daudé 6 years, 9 months ago
Since OpenBSD 6.0 [1], W^X is enforced by default [2].
TCG requires WX access, and QEMU binaries are now built with the WX
flag to disable the protection. However, WX allowed binaries need
to be run on a WX allowed partition.
To be able to run the QEMU test suite on the VM, mount the partition
where QEMU is built/tested as WX allowed.

[1] https://www.openbsd.org/faq/upgrade60.html
[2] https://undeadly.org/cgi?action=article&sid=20160527203200

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 tests/vm/openbsd | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/tests/vm/openbsd b/tests/vm/openbsd
index 2105c01a26..6263c8956b 100755
--- a/tests/vm/openbsd
+++ b/tests/vm/openbsd
@@ -41,6 +41,12 @@ class OpenBSDVM(basevm.BaseVM):
         if os.path.exists(img):
             os.remove(img)
         os.rename(img_tmp, img)
+        self.boot(img)
+        self.wait_ssh()
+        sys.stderr.write("Disabling W^X on the build partition...\n")
+        self.ssh_root_check("sed -E -i 's_(/tmp\ ffs)\ ([^\ ]*)_\\1 \\2,wxallowed_' /etc/fstab")
+        self.ssh_root("shutdown -p now")
+        self.wait()
 
 if __name__ == "__main__":
     sys.exit(basevm.main(OpenBSDVM))
-- 
2.20.1


Re: [Qemu-devel] [PATCH v2 03/18] tests/vm/openbsd: Disable the W^X protection on the build partition
Posted by Eric Blake 6 years, 9 months ago
On 1/29/19 11:53 AM, Philippe Mathieu-Daudé wrote:
> Since OpenBSD 6.0 [1], W^X is enforced by default [2].
> TCG requires WX access, and QEMU binaries are now built with the WX
> flag to disable the protection. However, WX allowed binaries need
> to be run on a WX allowed partition.
> To be able to run the QEMU test suite on the VM, mount the partition
> where QEMU is built/tested as WX allowed.
> 
> [1] https://www.openbsd.org/faq/upgrade60.html
> [2] https://undeadly.org/cgi?action=article&sid=20160527203200
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> ---
>  tests/vm/openbsd | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/tests/vm/openbsd b/tests/vm/openbsd
> index 2105c01a26..6263c8956b 100755
> --- a/tests/vm/openbsd
> +++ b/tests/vm/openbsd
> @@ -41,6 +41,12 @@ class OpenBSDVM(basevm.BaseVM):
>          if os.path.exists(img):
>              os.remove(img)
>          os.rename(img_tmp, img)
> +        self.boot(img)
> +        self.wait_ssh()
> +        sys.stderr.write("Disabling W^X on the build partition...\n")
> +        self.ssh_root_check("sed -E -i 's_(/tmp\ ffs)\ ([^\ ]*)_\\1 \\2,wxallowed_' /etc/fstab")

sed -i is non-POSIX, but it looks like it works in OpenBSD.

> +        self.ssh_root("shutdown -p now")
> +        self.wait()
>  
>  if __name__ == "__main__":
>      sys.exit(basevm.main(OpenBSDVM))
> 

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org