From: Kamal Mostafa <kamal@canonical.com>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org,
kernel-team@lists.ubuntu.com
Cc: Sven Wegener <sven.wegener@stealer.net>,
"H. Peter Anvin" <hpa@zytor.com>,
Andy Lutomirski <luto@amacapital.net>,
Kamal Mostafa <kamal@canonical.com>
Subject: [PATCH 3.8 02/13] x86_32, entry: Store badsys error code in %eax
Date: Mon, 25 Aug 2014 09:54:48 -0700 [thread overview]
Message-ID: <1408985699-31838-3-git-send-email-kamal@canonical.com> (raw)
In-Reply-To: <1408985699-31838-1-git-send-email-kamal@canonical.com>
3.8.13.28 -stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Wegener <sven.wegener@stealer.net>
commit 8142b215501f8b291a108a202b3a053a265b03dd upstream.
Commit 554086d ("x86_32, entry: Do syscall exit work on badsys
(CVE-2014-4508)") introduced a regression in the x86_32 syscall entry
code, resulting in syscall() not returning proper errors for undefined
syscalls on CPUs supporting the sysenter feature.
The following code:
> int result = syscall(666);
> printf("result=%d errno=%d error=%s\n", result, errno, strerror(errno));
results in:
> result=666 errno=0 error=Success
Obviously, the syscall return value is the called syscall number, but it
should have been an ENOSYS error. When run under ptrace it behaves
correctly, which makes it hard to debug in the wild:
> result=-1 errno=38 error=Function not implemented
The %eax register is the return value register. For debugging via ptrace
the syscall entry code stores the complete register context on the
stack. The badsys handlers only store the ENOSYS error code in the
ptrace register set and do not set %eax like a regular syscall handler
would. The old resume_userspace call chain contains code that clobbers
%eax and it restores %eax from the ptrace registers afterwards. The same
goes for the ptrace-enabled call chain. When ptrace is not used, the
syscall return value is the passed-in syscall number from the untouched
%eax register.
Use %eax as the return value register in syscall_badsys and
sysenter_badsys, like a real syscall handler does, and have the caller
push the value onto the stack for ptrace access.
Signed-off-by: Sven Wegener <sven.wegener@stealer.net>
Link: http://lkml.kernel.org/r/alpine.LNX.2.11.1407221022380.31021@titan.int.lan.stealer.net
Reviewed-and-tested-by: Andy Lutomirski <luto@amacapital.net>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Cc: Andy Lutomirski <luto@amacapital.net>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
---
arch/x86/kernel/entry_32.S | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
index b32b466..1843543 100644
--- a/arch/x86/kernel/entry_32.S
+++ b/arch/x86/kernel/entry_32.S
@@ -436,8 +436,8 @@ sysenter_do_call:
cmpl $(NR_syscalls), %eax
jae sysenter_badsys
call *sys_call_table(,%eax,4)
- movl %eax,PT_EAX(%esp)
sysenter_after_call:
+ movl %eax,PT_EAX(%esp)
LOCKDEP_SYS_EXIT
DISABLE_INTERRUPTS(CLBR_ANY)
TRACE_IRQS_OFF
@@ -517,6 +517,7 @@ ENTRY(system_call)
jae syscall_badsys
syscall_call:
call *sys_call_table(,%eax,4)
+syscall_after_call:
movl %eax,PT_EAX(%esp) # store the return value
syscall_exit:
LOCKDEP_SYS_EXIT
@@ -686,12 +687,12 @@ syscall_fault:
END(syscall_fault)
syscall_badsys:
- movl $-ENOSYS,PT_EAX(%esp)
- jmp syscall_exit
+ movl $-ENOSYS,%eax
+ jmp syscall_after_call
END(syscall_badsys)
sysenter_badsys:
- movl $-ENOSYS,PT_EAX(%esp)
+ movl $-ENOSYS,%eax
jmp sysenter_after_call
END(syscall_badsys)
CFI_ENDPROC
--
1.9.1
next prev parent reply other threads:[~2014-08-25 16:55 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-25 16:54 [3.8.y.z extended stable] Linux 3.8.13.28 stable review Kamal Mostafa
2014-08-25 16:54 ` [PATCH 3.8 01/13] x86_32, entry: Do syscall exit work on badsys (CVE-2014-4508) Kamal Mostafa
2014-08-25 16:54 ` Kamal Mostafa [this message]
2014-08-25 16:54 ` [PATCH 3.8 03/13] shmem: fix faulting into a hole while it's punched Kamal Mostafa
2014-08-25 16:54 ` [PATCH 3.8 04/13] shmem: fix faulting into a hole, not taking i_mutex Kamal Mostafa
2014-08-25 16:54 ` [PATCH 3.8 05/13] shmem: fix splicing from a hole while it's punched Kamal Mostafa
2014-08-25 16:54 ` [PATCH 3.8 06/13] target: Explicitly clear ramdisk_mcp backend pages Kamal Mostafa
2014-08-25 16:54 ` [PATCH 3.8 07/13] sctp: Fix sk_ack_backlog wrap-around problem Kamal Mostafa
2014-08-25 16:54 ` [PATCH 3.8 08/13] mnt: Only change user settable mount flags in remount Kamal Mostafa
2014-08-25 16:54 ` [PATCH 3.8 09/13] mnt: Move the test for MNT_LOCK_READONLY from change_mount_flags into do_remount Kamal Mostafa
2014-08-25 16:54 ` [PATCH 3.8 10/13] mnt: Correct permission checks in do_remount Kamal Mostafa
2014-08-25 16:54 ` [PATCH 3.8 11/13] mnt: Change the default remount atime from relatime to the existing value Kamal Mostafa
2014-08-25 16:54 ` [PATCH 3.8 12/13] ptrace,x86: force IRET path after a ptrace_stop() Kamal Mostafa
2014-08-25 16:54 ` [PATCH 3.8 13/13] net/l2tp: don't fall back on UDP [get|set]sockopt Kamal Mostafa
2014-08-25 17:00 ` [3.8.y.z extended stable] Linux 3.8.13.28 stable review Greg KH
2014-08-25 19:14 ` Kamal Mostafa
2014-08-25 19:37 ` Greg KH
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=1408985699-31838-3-git-send-email-kamal@canonical.com \
--to=kamal@canonical.com \
--cc=hpa@zytor.com \
--cc=kernel-team@lists.ubuntu.com \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@amacapital.net \
--cc=stable@vger.kernel.org \
--cc=sven.wegener@stealer.net \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®