Skip to contentSkip to conversation

libseccomp: add cacheflush to whitelist

PATCH Superseded Andrew Jones 4 participants 11 messages Jul 1, 2015 – Oct 14, 2015

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libseccomp: add cacheflush to whitelist

cacheflush is an arm-specific syscall that qemu built for arm uses. Add it to the whitelist.

---

I'm not sure about the priority selection. Maybe cacheflush gets used frequently enough that it deserves a higher one?

This patch isn't really necessary yet due to ae6e8ef11e6c: "Revert seccomp tests that allow it to be used on non-x86 architectures", which we can't revert until libseccomp has released a fix for arm-specific syscall symbol naming, but when linking to a patched libseccomp and reverting ae6e8ef11e6c, then this patch allows guests to boot with '-sandbox on'.

---
 qemu-seccomp.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
qemu-seccomp.c +2 -1
index f9de0d3390feb..33644a4e3c3d3 100644
@@ -237,7 +237,8 @@ static const struct QemuSeccompSyscall seccomp_whitelist[] = {
     { SCMP_SYS(fadvise64), 240 },
     { SCMP_SYS(inotify_init1), 240 },
     { SCMP_SYS(inotify_add_watch), 240 },
-    { SCMP_SYS(mbind), 240 }
+    { SCMP_SYS(mbind), 240 },
+    { SCMP_SYS(cacheflush), 240 },
 };
 
 int seccomp_start(void)
Signature · 1 line
2.1.0
#1 lore raw
Quoted 9 lines · Andrew Jones

cacheflush is an arm-specific syscall that qemu built for arm uses. Add it to the whitelist.

---

I'm not sure about the priority selection. Maybe cacheflush gets used frequently enough that it deserves a higher one?

The frequency is measured using strace and comparing the frequency they appear among other syscalls. Can you run this analysis and double check if the lowest priority is still accurate?

Thanks for the patch.

Quoted 30 lines

This patch isn't really necessary yet due to ae6e8ef11e6c: "Revert seccomp tests that allow it to be used on non-x86 architectures", which we can't revert until libseccomp has released a fix for arm-specific syscall symbol naming, but when linking to a patched libseccomp and reverting ae6e8ef11e6c, then this patch allows guests to boot with '-sandbox on'.

---
 qemu-seccomp.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
qemu-seccomp.c +2 -1
index f9de0d3390feb..33644a4e3c3d3 100644
@@ -237,7 +237,8 @@ static const struct QemuSeccompSyscall seccomp_whitelist[] = {
     { SCMP_SYS(fadvise64), 240 },
     { SCMP_SYS(inotify_init1), 240 },
     { SCMP_SYS(inotify_add_watch), 240 },
-    { SCMP_SYS(mbind), 240 }
+    { SCMP_SYS(mbind), 240 },
+    { SCMP_SYS(cacheflush), 240 },
 };
 
 int seccomp_start(void)
Signature · 1 line
2.1.0
Signature · 2 lines
Eduardo Otubo
ProfitBricks GmbH
#2 lore raw
Quoted 6 lines · Eduardo Otubo
Quoted 5 lines · Andrew Jones

cacheflush is an arm-specific syscall that qemu built for arm uses. Add it to the whitelist.

Quoted 8 lines
Quoted 4 lines

---

I'm not sure about the priority selection. Maybe cacheflush gets used frequently enough that it deserves a higher one?

The frequency is measured using strace and comparing the frequency they appear among other syscalls. Can you run this analysis and double check if the lowest priority is still accurate?

Hi Eduardo,

Short answer: The lowest priority is definitely correct.

Long answer:

I ran strace while installing a new guest, of 3.6 million syscalls, only 5 were cacheflush. Of course the syscalls used (and their frequency) is host-type, qemu machine-type, config (qemu command line), and guest workload specific. So, ideally, qemu machine-types would register their own whitelists, possibly modified by host-type. For example, I ran the mach-virt machine-type on both a midway and a mustang. In both cases it was a basic guest config and an install-type workload. For the mustang, over 55% of the syscalls were ioctl, but, for the midway, ioctls were 16% and 43% were clock_gettime. I generated a most-used-first list for each. Neither list really matched up well with seccomp_whitelist (except for futex).

Besides allowing machine types to help set priorities, it may also be nice if both compile-time and run-time configs could further reduce the whitelist. For example, mlockall is only necessary if '-realtime mlock=on' is passed on the command line.

Thanks,
drew

Quoted 37 lines

Thanks for the patch.

Quoted 30 lines

This patch isn't really necessary yet due to ae6e8ef11e6c: "Revert seccomp tests that allow it to be used on non-x86 architectures", which we can't revert until libseccomp has released a fix for arm-specific syscall symbol naming, but when linking to a patched libseccomp and reverting ae6e8ef11e6c, then this patch allows guests to boot with '-sandbox on'.

---
 qemu-seccomp.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
qemu-seccomp.c +2 -1
index f9de0d3390feb..33644a4e3c3d3 100644
@@ -237,7 +237,8 @@ static const struct QemuSeccompSyscall seccomp_whitelist[] = {
     { SCMP_SYS(fadvise64), 240 },
     { SCMP_SYS(inotify_init1), 240 },
     { SCMP_SYS(inotify_add_watch), 240 },
-    { SCMP_SYS(mbind), 240 }
+    { SCMP_SYS(mbind), 240 },
+    { SCMP_SYS(cacheflush), 240 },
 };
 
 int seccomp_start(void)
Signature · 1 line
2.1.0
Signature · 2 lines
Eduardo Otubo
ProfitBricks GmbH
#3 lore raw
Quoted 4 lines · Andrew Jones

Short answer: The lowest priority is definitely correct.

Long answer:

Quoted 11 lines

I ran strace while installing a new guest, of 3.6 million syscalls, only 5 were cacheflush. Of course the syscalls used (and their frequency) is host-type, qemu machine-type, config (qemu command line), and guest workload specific. So, ideally, qemu machine-types would register their own whitelists, possibly modified by host-type. For example, I ran the mach-virt machine-type on both a midway and a mustang. In both cases it was a basic guest config and an install-type workload. For the mustang, over 55% of the syscalls were ioctl, but, for the midway, ioctls were 16% and 43% were clock_gettime. I generated a most-used-first list for each. Neither list really matched up well with seccomp_whitelist (except for futex).

This is strongly dependent on host CPU and what you're doing. If you build QEMU for 64-bit ARM then we should be able to do the cache ops from userspace without syscalls. If you're running KVM then we probably only flush the cache a few times at startup when we load the ROM images and so on. If you're using TCG emulation I would expect that we do quite a lot of cache ops...

You could reasonably argue that anybody who cares about seccomp is going to be running with KVM, of course.

thanks
-- PMM

Acked-by
#4 lore raw
In reply to Andrew Jones
Quoted 71 lines · Andrew Jones
Quoted 6 lines · Eduardo Otubo
Quoted 5 lines · Andrew Jones

cacheflush is an arm-specific syscall that qemu built for arm uses. Add it to the whitelist.

Quoted 8 lines
Quoted 4 lines

---

I'm not sure about the priority selection. Maybe cacheflush gets used frequently enough that it deserves a higher one?

The frequency is measured using strace and comparing the frequency they appear among other syscalls. Can you run this analysis and double check if the lowest priority is still accurate?

Hi Eduardo,

Short answer: The lowest priority is definitely correct.

Long answer:

I ran strace while installing a new guest, of 3.6 million syscalls, only 5 were cacheflush. Of course the syscalls used (and their frequency) is host-type, qemu machine-type, config (qemu command line), and guest workload specific. So, ideally, qemu machine-types would register their own whitelists, possibly modified by host-type. For example, I ran the mach-virt machine-type on both a midway and a mustang. In both cases it was a basic guest config and an install-type workload. For the mustang, over 55% of the syscalls were ioctl, but, for the midway, ioctls were 16% and 43% were clock_gettime. I generated a most-used-first list for each. Neither list really matched up well with seccomp_whitelist (except for futex).

Besides allowing machine types to help set priorities, it may also be nice if both compile-time and run-time configs could further reduce the whitelist. For example, mlockall is only necessary if '-realtime mlock=on' is passed on the command line.

Thanks,
drew

Quoted 29 lines

Thanks for the patch.

Quoted 26 lines

This patch isn't really necessary yet due to ae6e8ef11e6c: "Revert seccomp tests that allow it to be used on non-x86 architectures", which we can't revert until libseccomp has released a fix for arm-specific syscall symbol naming, but when linking to a patched libseccomp and reverting ae6e8ef11e6c, then this patch allows guests to boot with '-sandbox on'.

---
 qemu-seccomp.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
qemu-seccomp.c +2 -1
index f9de0d3390feb..33644a4e3c3d3 100644
@@ -237,7 +237,8 @@ static const struct QemuSeccompSyscall seccomp_whitelist[] = {
     { SCMP_SYS(fadvise64), 240 },
     { SCMP_SYS(inotify_init1), 240 },
     { SCMP_SYS(inotify_add_watch), 240 },
-    { SCMP_SYS(mbind), 240 }
+    { SCMP_SYS(mbind), 240 },
+    { SCMP_SYS(cacheflush), 240 },
 };
 
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
qemu-seccomp.c +0 -0
 int seccomp_start(void)
Signature · 1 line
2.1.0
Signature · 2 lines
Eduardo Otubo
ProfitBricks GmbH
#5 lore raw
Quoted 59 lines · Eduardo Otubo
Quoted 58 lines · Andrew Jones
Quoted 6 lines · Eduardo Otubo
Quoted 5 lines · Andrew Jones

cacheflush is an arm-specific syscall that qemu built for arm uses. Add it to the whitelist.

Quoted 8 lines
Quoted 4 lines

---

I'm not sure about the priority selection. Maybe cacheflush gets used frequently enough that it deserves a higher one?

The frequency is measured using strace and comparing the frequency they appear among other syscalls. Can you run this analysis and double check if the lowest priority is still accurate?

Hi Eduardo,

Short answer: The lowest priority is definitely correct.

Long answer:

I ran strace while installing a new guest, of 3.6 million syscalls, only 5 were cacheflush. Of course the syscalls used (and their frequency) is host-type, qemu machine-type, config (qemu command line), and guest workload specific. So, ideally, qemu machine-types would register their own whitelists, possibly modified by host-type. For example, I ran the mach-virt machine-type on both a midway and a mustang. In both cases it was a basic guest config and an install-type workload. For the mustang, over 55% of the syscalls were ioctl, but, for the midway, ioctls were 16% and 43% were clock_gettime. I generated a most-used-first list for each. Neither list really matched up well with seccomp_whitelist (except for futex).

Besides allowing machine types to help set priorities, it may also be nice if both compile-time and run-time configs could further reduce the whitelist. For example, mlockall is only necessary if '-realtime mlock=on' is passed on the command line.

Thanks,
drew

Quoted 16 lines

Thanks for the patch.

Quoted 13 lines

This patch isn't really necessary yet due to ae6e8ef11e6c: "Revert seccomp tests that allow it to be used on non-x86 architectures", which we can't revert until libseccomp has released a fix for arm-specific syscall symbol naming, but when linking to a patched libseccomp and reverting ae6e8ef11e6c, then this patch allows guests to boot with '-sandbox on'.

---
 qemu-seccomp.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

qemu-seccomp.c static const struct QemuSeccompSyscall seccomp_whitelist[] = { · line 241

Quoted 11 lines
qemu-seccomp.c +2 -1
index f9de0d3390feb..33644a4e3c3d3 100644
@@ -237,7 +237,8 @@ static const struct QemuSeccompSyscall seccomp_whitelist[] = {
     { SCMP_SYS(fadvise64), 240 },
     { SCMP_SYS(inotify_init1), 240 },
     { SCMP_SYS(inotify_add_watch), 240 },
-    { SCMP_SYS(mbind), 240 }
+    { SCMP_SYS(mbind), 240 },
+    { SCMP_SYS(cacheflush), 240 },

FYI: I had to fixed this minor mistake (using comma at the end of the list) before applying your patch.

Signature · 2 lines
Eduardo Otubo
ProfitBricks GmbH
#6 lore raw
Quoted 60 lines · Eduardo Otubo
Quoted 59 lines · Eduardo Otubo
Quoted 58 lines · Andrew Jones
Quoted 6 lines · Eduardo Otubo
Quoted 5 lines · Andrew Jones

cacheflush is an arm-specific syscall that qemu built for arm uses. Add it to the whitelist.

Quoted 8 lines
Quoted 4 lines

---

I'm not sure about the priority selection. Maybe cacheflush gets used frequently enough that it deserves a higher one?

The frequency is measured using strace and comparing the frequency they appear among other syscalls. Can you run this analysis and double check if the lowest priority is still accurate?

Hi Eduardo,

Short answer: The lowest priority is definitely correct.

Long answer:

I ran strace while installing a new guest, of 3.6 million syscalls, only 5 were cacheflush. Of course the syscalls used (and their frequency) is host-type, qemu machine-type, config (qemu command line), and guest workload specific. So, ideally, qemu machine-types would register their own whitelists, possibly modified by host-type. For example, I ran the mach-virt machine-type on both a midway and a mustang. In both cases it was a basic guest config and an install-type workload. For the mustang, over 55% of the syscalls were ioctl, but, for the midway, ioctls were 16% and 43% were clock_gettime. I generated a most-used-first list for each. Neither list really matched up well with seccomp_whitelist (except for futex).

Besides allowing machine types to help set priorities, it may also be nice if both compile-time and run-time configs could further reduce the whitelist. For example, mlockall is only necessary if '-realtime mlock=on' is passed on the command line.

Thanks,
drew

Quoted 16 lines

Thanks for the patch.

Quoted 13 lines

This patch isn't really necessary yet due to ae6e8ef11e6c: "Revert seccomp tests that allow it to be used on non-x86 architectures", which we can't revert until libseccomp has released a fix for arm-specific syscall symbol naming, but when linking to a patched libseccomp and reverting ae6e8ef11e6c, then this patch allows guests to boot with '-sandbox on'.

---
 qemu-seccomp.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 14 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

qemu-seccomp.c static const struct QemuSeccompSyscall seccomp_whitelist[] = { · line 241

Quoted 11 lines
qemu-seccomp.c +2 -1
index f9de0d3390feb..33644a4e3c3d3 100644
@@ -237,7 +237,8 @@ static const struct QemuSeccompSyscall seccomp_whitelist[] = {
     { SCMP_SYS(fadvise64), 240 },
     { SCMP_SYS(inotify_init1), 240 },
     { SCMP_SYS(inotify_add_watch), 240 },
-    { SCMP_SYS(mbind), 240 }
+    { SCMP_SYS(mbind), 240 },
+    { SCMP_SYS(cacheflush), 240 },

FYI: I had to fixed this minor mistake (using comma at the end of the list) before applying your patch.

Does that violate a QEMU coding style? Because I actually put it there on purpose so the next addition wouldn't have to modify the line (by adding a comma), making git-blame more difficult to use.

Thanks,
drew

Quoted 4 lines
Signature · 3 lines
-- 
Eduardo Otubo
ProfitBricks GmbH
#7 lore raw
Quoted 5 lines · Andrew Jones
Quoted 4 lines · Eduardo Otubo
Quoted 3 lines · Eduardo Otubo
Quoted 2 lines · Andrew Jones
Quoted 1 line · Eduardo Otubo

On Wed, Jul 01, 2015 at 09=12=33AM -0400, Andrew Jones wrote:

[...]

Quoted 15 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
qemu-seccomp.c +0 -0
index f9de0d3390feb..33644a4e3c3d3 100644
@@ -237,7 +237,8 @@ static const struct QemuSeccompSyscall seccomp_whitelist[] = {
     { SCMP_SYS(fadvise64), 240 },
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

qemu-seccomp.c static const struct QemuSeccompSyscall seccomp_whitelist[] = { · line 241

Quoted 5 lines
qemu-seccomp.c +2 -1
     { SCMP_SYS(inotify_init1), 240 },
     { SCMP_SYS(inotify_add_watch), 240 },
-    { SCMP_SYS(mbind), 240 }
+    { SCMP_SYS(mbind), 240 },
+    { SCMP_SYS(cacheflush), 240 },

FYI: I had to fixed this minor mistake (using comma at the end of the list) before applying your patch.

Quoted 3 lines

Does that violate a QEMU coding style? Because I actually put it there on purpose so the next addition wouldn't have to modify the line (by adding a comma), making git-blame more difficult to use.

We have trailing commas all over the place, for precisely the reason you gave. I recommend to put it right back.

#8 lore raw
Quoted 23 lines · Markus Armbruster
Quoted 5 lines · Andrew Jones
Quoted 4 lines · Eduardo Otubo
Quoted 3 lines · Eduardo Otubo
Quoted 2 lines · Andrew Jones
Quoted 1 line · Eduardo Otubo

On Wed, Jul 01, 2015 at 09=12=33AM -0400, Andrew Jones wrote:

[...]

Quoted 15 lines
Quoted 14 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

qemu-seccomp.c static const struct QemuSeccompSyscall seccomp_whitelist[] = { · line 241

Quoted 11 lines
qemu-seccomp.c +2 -1
index f9de0d3390feb..33644a4e3c3d3 100644
@@ -237,7 +237,8 @@ static const struct QemuSeccompSyscall seccomp_whitelist[] = {
     { SCMP_SYS(fadvise64), 240 },
     { SCMP_SYS(inotify_init1), 240 },
     { SCMP_SYS(inotify_add_watch), 240 },
-    { SCMP_SYS(mbind), 240 }
+    { SCMP_SYS(mbind), 240 },
+    { SCMP_SYS(cacheflush), 240 },

FYI: I had to fixed this minor mistake (using comma at the end of the list) before applying your patch.

Quoted 7 lines
Quoted 3 lines

Does that violate a QEMU coding style? Because I actually put it there on purpose so the next addition wouldn't have to modify the line (by adding a comma), making git-blame more difficult to use.

We have trailing commas all over the place, for precisely the reason you gave. I recommend to put it right back.

Well, that makes a lot of sense. I'll just put it back again and send the pull request once more.

ps.: I just thought the guideline said to make sure every commit should be "compilable" with no errors, perhaps I saw it somewhere else. Sorry for the trouble.

Signature · 2 lines
Eduardo Otubo
ProfitBricks GmbH
#9 lore raw
Quoted 32 lines · Eduardo Otubo
Quoted 23 lines · Markus Armbruster
Quoted 5 lines · Andrew Jones
Quoted 4 lines · Eduardo Otubo
Quoted 3 lines · Eduardo Otubo
Quoted 2 lines · Andrew Jones
Quoted 1 line · Eduardo Otubo

On Wed, Jul 01, 2015 at 09=12=33AM -0400, Andrew Jones wrote:

[...]

Quoted 15 lines
Quoted 14 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

qemu-seccomp.c static const struct QemuSeccompSyscall seccomp_whitelist[] = { · line 241

Quoted 11 lines
qemu-seccomp.c +2 -1
index f9de0d3390feb..33644a4e3c3d3 100644
@@ -237,7 +237,8 @@ static const struct QemuSeccompSyscall seccomp_whitelist[] = {
     { SCMP_SYS(fadvise64), 240 },
     { SCMP_SYS(inotify_init1), 240 },
     { SCMP_SYS(inotify_add_watch), 240 },
-    { SCMP_SYS(mbind), 240 }
+    { SCMP_SYS(mbind), 240 },
+    { SCMP_SYS(cacheflush), 240 },

FYI: I had to fixed this minor mistake (using comma at the end of the list) before applying your patch.

Quoted 7 lines
Quoted 3 lines

Does that violate a QEMU coding style? Because I actually put it there on purpose so the next addition wouldn't have to modify the line (by adding a comma), making git-blame more difficult to use.

We have trailing commas all over the place, for precisely the reason you gave. I recommend to put it right back.

Quoted 6 lines

Well, that makes a lot of sense. I'll just put it back again and send the pull request once more.

ps.: I just thought the guideline said to make sure every commit should be "compilable" with no errors, perhaps I saw it somewhere else. Sorry for the trouble.

Does your complier complain about that trailing comma? I thought allowing that was even part of the ANSI C standard.

Thanks,
drew

Quoted 4 lines
Signature · 3 lines
-- 
Eduardo Otubo
ProfitBricks GmbH
#10 lore raw
Quoted 37 lines · Andrew Jones
Quoted 36 lines · Eduardo Otubo
Quoted 24 lines · Markus Armbruster
Quoted 5 lines · Andrew Jones
Quoted 4 lines · Eduardo Otubo
Quoted 3 lines · Eduardo Otubo
Quoted 2 lines · Andrew Jones
Quoted 1 line · Eduardo Otubo

On Wed, Jul 01, 2015 at 09=12=33AM -0400, Andrew Jones wrote:

[...]

Quoted 16 lines
Quoted 15 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
qemu-seccomp.c +0 -0
index f9de0d3390feb..33644a4e3c3d3 100644
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

qemu-seccomp.c static const struct · line 242

Quoted 8 lines
qemu-seccomp.c +2 -1
@@ -237,7 +237,8 @@ static const struct
 QemuSeccompSyscall seccomp_whitelist[] = {
     { SCMP_SYS(fadvise64), 240 },
     { SCMP_SYS(inotify_init1), 240 },
     { SCMP_SYS(inotify_add_watch), 240 },
-    { SCMP_SYS(mbind), 240 }
+    { SCMP_SYS(mbind), 240 },
+    { SCMP_SYS(cacheflush), 240 },

FYI: I had to fixed this minor mistake (using comma at the end of the list) before applying your patch.

Quoted 7 lines
Quoted 3 lines

Does that violate a QEMU coding style? Because I actually put it there on purpose so the next addition wouldn't have to modify the line (by adding a comma), making git-blame more difficult to use.

We have trailing commas all over the place, for precisely the reason you gave. I recommend to put it right back.

Well, that makes a lot of sense. I'll just put it back again and send the pull request once more.

Quoted 6 lines
Quoted 3 lines

ps.: I just thought the guideline said to make sure every commit should be "compilable" with no errors, perhaps I saw it somewhere else. Sorry for the trouble.

Does your complier complain about that trailing comma? I thought allowing that was even part of the ANSI C standard.

It's C99.