Skip to contentSkip to conversation

linux-user: return EINVAL from prctl(PR_*_SECCOMP)

PATCH Superseded James Cowgill 4 participants 9 messages Nov 3, 2017 – Nov 6, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 linux-user: return EINVAL from prctl(PR_*_SECCOMP)

If an application tries to install a seccomp filter using prctl(PR_SET_SECCOMP), the filter is likely for the target instead of the host architecture. This will probably cause qemu to be immediately killed when it executes another syscall.

Prevent this from happening by returning EINVAL from both seccomp prctl calls. This is the error returned by the kernel when seccomp support is disabled.

---
 linux-user/syscall.c | 4 ++++
 1 file changed, 4 insertions(+)
linux-user/syscall.c +4 -0
index d4497dec5d..43cd5fb2bb 100644
@@ -10482,6 +10482,10 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
             break;
         }
 #endif
+        case PR_GET_SECCOMP:
+        case PR_SET_SECCOMP:
+            ret = -TARGET_EINVAL;
+            break;
         default:
             /* Most prctl options have no pointer arguments */
             ret = get_errno(prctl(arg1, arg2, arg3, arg4, arg5));
Signature · 1 line
2.15.0
#1 lore raw

Le 03/11/2017 à 13:07, James Cowgill a écrit :

Quoted 21 lines

If an application tries to install a seccomp filter using prctl(PR_SET_SECCOMP), the filter is likely for the target instead of the host architecture. This will probably cause qemu to be immediately killed when it executes another syscall.

Prevent this from happening by returning EINVAL from both seccomp prctl calls. This is the error returned by the kernel when seccomp support is disabled.

---
 linux-user/syscall.c | 4 ++++
 1 file changed, 4 insertions(+)
linux-user/syscall.c +0 -0
index d4497dec5d..43cd5fb2bb 100644

linux-user/syscall.c abi_long do_syscall(void *cpu_env, int num, abi_long arg1, · line 10491

Quoted 10 lines
linux-user/syscall.c +4 -0
@@ -10482,6 +10482,10 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
             break;
         }
 #endif
+        case PR_GET_SECCOMP:
+        case PR_SET_SECCOMP:
+            ret = -TARGET_EINVAL;
+            break;
         default:
             /* Most prctl options have no pointer arguments */
             ret = get_errno(prctl(arg1, arg2, arg3, arg4, arg5));

I think we should allow PR_GET_SECCOMP, and at least all the modes except SECCOMP_MODE_FILTER for PR_SET_SECCOMP.

Thanks,
Laurent

#2 lore raw

Hi,

Quoted 27 lines · Laurent Vivier

Le 03/11/2017 à 13:07, James Cowgill a écrit :

Quoted 26 lines

If an application tries to install a seccomp filter using prctl(PR_SET_SECCOMP), the filter is likely for the target instead of the host architecture. This will probably cause qemu to be immediately killed when it executes another syscall.

Prevent this from happening by returning EINVAL from both seccomp prctl calls. This is the error returned by the kernel when seccomp support is disabled.

---
 linux-user/syscall.c | 4 ++++
 1 file changed, 4 insertions(+)
linux-user/syscall.c +3 -0
index d4497dec5d..43cd5fb2bb 100644
@@ -10482,6 +10482,10 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
             break;
         }
 #endif
+        case PR_GET_SECCOMP:
+        case PR_SET_SECCOMP:
+            ret = -TARGET_EINVAL;
Quoted 8 lines

linux-user/syscall.c abi_long do_syscall(void *cpu_env, int num, abi_long arg1, · line 10491

Quoted 5 lines
linux-user/syscall.c +1 -0
+            break;
         default:
             /* Most prctl options have no pointer arguments */
             ret = get_errno(prctl(arg1, arg2, arg3, arg4, arg5));

I think we should allow PR_GET_SECCOMP, and at least all the modes except SECCOMP_MODE_FILTER for PR_SET_SECCOMP.

I tried allowing SECCOMP_MODE_STRICT and made a small test program. It seems that qemu is SIGKILLed when _exit is used because qemu itself tries to call rt_sigprocmask which is not an allowed syscall.

PR_GET_SECCOMP can probably be allowed. My reasoning for disabling it was to match the kernel behavior for when seccomp is disabled by the Kconfig option.

Thanks,
James

#3 lore raw
Quoted 11 lines · James Cowgill
Quoted 2 lines · Laurent Vivier

I think we should allow PR_GET_SECCOMP, and at least all the modes except SECCOMP_MODE_FILTER for PR_SET_SECCOMP.

I tried allowing SECCOMP_MODE_STRICT and made a small test program. It seems that qemu is SIGKILLed when _exit is used because qemu itself tries to call rt_sigprocmask which is not an allowed syscall.

PR_GET_SECCOMP can probably be allowed. My reasoning for disabling it was to match the kernel behavior for when seccomp is disabled by the Kconfig option.

I think I like "behave like a kernel with seccomp disabled" -- it's a clean line that we can assume won't confuse guest programs. Laurent?

thanks
-- PMM

Reviewed-by
#4 lore raw

Le 03/11/2017 à 17:01, Peter Maydell a écrit :

Quoted 9 lines · James Cowgill
Quoted 8 lines · Laurent Vivier
Quoted 2 lines

I think we should allow PR_GET_SECCOMP, and at least all the modes except SECCOMP_MODE_FILTER for PR_SET_SECCOMP.

I tried allowing SECCOMP_MODE_STRICT and made a small test program. It seems that qemu is SIGKILLed when _exit is used because qemu itself tries to call rt_sigprocmask which is not an allowed syscall.

Quoted 7 lines
Quoted 3 lines

PR_GET_SECCOMP can probably be allowed. My reasoning for disabling it was to match the kernel behavior for when seccomp is disabled by the Kconfig option.

I think I like "behave like a kernel with seccomp disabled" -- it's a clean line that we can assume won't confuse guest programs. Laurent?

I agree. I didn't think about all the syscalls QEMU can do aside of the executed program. So your solution is the good one.

Thanks,
Laurent

#5 lore raw
In reply to James Cowgill
Quoted 21 lines · James Cowgill

If an application tries to install a seccomp filter using prctl(PR_SET_SECCOMP), the filter is likely for the target instead of the host architecture. This will probably cause qemu to be immediately killed when it executes another syscall.

Prevent this from happening by returning EINVAL from both seccomp prctl calls. This is the error returned by the kernel when seccomp support is disabled.

---
 linux-user/syscall.c | 4 ++++
 1 file changed, 4 insertions(+)
linux-user/syscall.c +0 -0
index d4497dec5d..43cd5fb2bb 100644

linux-user/syscall.c abi_long do_syscall(void *cpu_env, int num, abi_long arg1, · line 10491

Quoted 10 lines
linux-user/syscall.c +4 -0
@@ -10482,6 +10482,10 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
             break;
         }
 #endif
+        case PR_GET_SECCOMP:
+        case PR_SET_SECCOMP:
+            ret = -TARGET_EINVAL;
+            break;
         default:
             /* Most prctl options have no pointer arguments */
             ret = get_errno(prctl(arg1, arg2, arg3, arg4, arg5));

Seems like a good idea -- can we have the "why are we failing this" in a comment as well as in the commit message, please?

thanks
-- PMM

#6 lore raw

PATCH v2 1/1 linux-user: return EINVAL from prctl(PR_*_SECCOMP)

In reply to James Cowgill

If an application tries to install a seccomp filter using prctl(PR_SET_SECCOMP), the filter is likely for the target instead of the host architecture. This will probably cause qemu to be immediately killed when it executes another syscall.

Prevent this from happening by returning EINVAL from both seccomp prctl calls. This is the error returned by the kernel when seccomp support is disabled.

---
Changes from v1:
- add comment

 linux-user/syscall.c | 6 ++++++
 1 file changed, 6 insertions(+)
linux-user/syscall.c +6 -0
index d4497dec5d..419991e834 100644
@@ -10482,6 +10482,12 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
             break;
         }
 #endif
+        case PR_GET_SECCOMP:
+        case PR_SET_SECCOMP:
+            /* Disable seccomp to prevent the target disabling syscalls we
+             * need. */
+            ret = -TARGET_EINVAL;
+            break;
         default:
             /* Most prctl options have no pointer arguments */
             ret = get_errno(prctl(arg1, arg2, arg3, arg4, arg5));
Signature · 1 line
2.15.0
Reviewed-by on v2 1/1
#7 lore raw

Le 06/11/2017 à 19:03, James Cowgill a écrit :

Quoted 26 lines

If an application tries to install a seccomp filter using prctl(PR_SET_SECCOMP), the filter is likely for the target instead of the host architecture. This will probably cause qemu to be immediately killed when it executes another syscall.

Prevent this from happening by returning EINVAL from both seccomp prctl calls. This is the error returned by the kernel when seccomp support is disabled.

---
Changes from v1:
- add comment

 linux-user/syscall.c | 6 ++++++
 1 file changed, 6 insertions(+)
linux-user/syscall.c +0 -0
index d4497dec5d..419991e834 100644
@@ -10482,6 +10482,12 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
             break;
         }

linux-user/syscall.c abi_long do_syscall(void *cpu_env, int num, abi_long arg1, · line 10493

Quoted 10 lines
linux-user/syscall.c +6 -0
 #endif
+        case PR_GET_SECCOMP:
+        case PR_SET_SECCOMP:
+            /* Disable seccomp to prevent the target disabling syscalls we
+             * need. */
+            ret = -TARGET_EINVAL;
+            break;
         default:
             /* Most prctl options have no pointer arguments */
             ret = get_errno(prctl(arg1, arg2, arg3, arg4, arg5));
Applied
#8 lore raw
In reply to James Cowgill
Quoted 8 lines · James Cowgill

If an application tries to install a seccomp filter using prctl(PR_SET_SECCOMP), the filter is likely for the target instead of the host architecture. This will probably cause qemu to be immediately killed when it executes another syscall.

Prevent this from happening by returning EINVAL from both seccomp prctl calls. This is the error returned by the kernel when seccomp support is disabled.

Thanks, applied to linux-user

Quoted 30 lines

---
Changes from v1:
- add comment

 linux-user/syscall.c | 6 ++++++
 1 file changed, 6 insertions(+)
linux-user/syscall.c +6 -0
index d4497dec5d..419991e834 100644
@@ -10482,6 +10482,12 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
             break;
         }
 #endif
+        case PR_GET_SECCOMP:
+        case PR_SET_SECCOMP:
+            /* Disable seccomp to prevent the target disabling syscalls we
+             * need. */
+            ret = -TARGET_EINVAL;
+            break;
         default:
             /* Most prctl options have no pointer arguments */
             ret = get_errno(prctl(arg1, arg2, arg3, arg4, arg5));
Signature · 1 line
2.15.0