From: Thomas Garnier <hidden> Date: 2017-03-08 22:33:38
This patch prevents a syscall to modify the address limit of the
caller. The address limit is kept by the syscall wrapper and restored
just after the syscall ends.
For example, it would mitigation this bug:
- https://bugs.chromium.org/p/project-zero/issues/detail?id=990
By default, this change warns if the segment is incorrect while
returning to user-mode and fix it. The
CONFIG_VERIFY_PRE_USERMODE_STATE_BUG option can be enabled to halt
instead if needed.
The CONFIG_ARCH_NO_SYSCALL_VERIFY_PRE_USERMODE_STATE option is also
added so each architecture can optimize how the
verify_pre_usermode_state function is called.
Signed-off-by: Thomas Garnier <redacted>
---
Based on next-20170308
---
include/linux/syscalls.h | 19 +++++++++++++++++++
init/Kconfig | 16 ++++++++++++++++
kernel/sys.c | 11 +++++++++++
3 files changed, 46 insertions(+)
@@ -1929,6 +1929,22 @@ config PROFILINGconfigTRACEPOINTSbool+#+# Set by each architecture that want to optimize how verify_pre_usermode_state+# is called.+#+configARCH_NO_SYSCALL_VERIFY_PRE_USERMODE_STATE+bool++configVERIFY_PRE_USERMODE_STATE_BUG+bool"Halt on incorrect state on returning to user-mode"+defaultn+help+Bydefaultawarningisloggedandthestateisfixed.Thisoption+crashesthekernelinstead.++Ifunsure,sayY.+source"arch/Kconfig"endmenu# General setup
From: Russell King - ARM Linux <linux@armlinux.org.uk> Date: 2017-03-08 21:52:05
On Wed, Mar 08, 2017 at 01:38:43PM -0800, Thomas Garnier wrote:
quoted hunk
Implement specific usage of verify_pre_usermode_state for user-mode
returns for arm.
---
Based on next-20170308
---
arch/arm/Kconfig | 1 +
arch/arm/kernel/entry-common.S | 5 +++++
2 files changed, 6 insertions(+)
This really makes the fast exit utterly pointless, and we might as well
rip all that out.
--
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up
according to speedtest.net.
On Wed, Mar 8, 2017 at 1:38 PM, Thomas Garnier [off-list ref] wrote:
This patch prevents a syscall to modify the address limit of the
caller. The address limit is kept by the syscall wrapper and restored
just after the syscall ends.
For example, it would mitigation this bug:
- https://bugs.chromium.org/p/project-zero/issues/detail?id=990
By default, this change warns if the segment is incorrect while
returning to user-mode and fix it. The
CONFIG_VERIFY_PRE_USERMODE_STATE_BUG option can be enabled to halt
instead if needed.
Instead of this new config, please reuse the CHECK_DATA_CORRUPTION
test instead, which already controls very similar WARN vs BUG
behavior. Example below...
quoted hunk
The CONFIG_ARCH_NO_SYSCALL_VERIFY_PRE_USERMODE_STATE option is also
added so each architecture can optimize how the
verify_pre_usermode_state function is called.
Signed-off-by: Thomas Garnier <redacted>
---
Based on next-20170308
---
include/linux/syscalls.h | 19 +++++++++++++++++++
init/Kconfig | 16 ++++++++++++++++
kernel/sys.c | 11 +++++++++++
3 files changed, 46 insertions(+)
@@ -1929,6 +1929,22 @@ config PROFILINGconfigTRACEPOINTSbool+#+# Set by each architecture that want to optimize how verify_pre_usermode_state+# is called.+#+configARCH_NO_SYSCALL_VERIFY_PRE_USERMODE_STATE+bool++configVERIFY_PRE_USERMODE_STATE_BUG+bool"Halt on incorrect state on returning to user-mode"+defaultn+help+Bydefaultawarningisloggedandthestateisfixed.Thisoption+crashesthekernelinstead.++Ifunsure,sayY.+source"arch/Kconfig"endmenu# General setup
From: Russell King - ARM Linux <linux@armlinux.org.uk> Date: 2017-03-08 22:09:45
On Wed, Mar 08, 2017 at 01:38:41PM -0800, Thomas Garnier wrote:
This patch prevents a syscall to modify the address limit of the
caller. The address limit is kept by the syscall wrapper and restored
just after the syscall ends.
I would much rather architectures were given the opportunity to code up
checks like this efficiently (iow, inline in the exit path assembly),
rather than having to unconditionally call an additional function on
every syscall, with its register saving overheads.
--
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up
according to speedtest.net.
On Wed, Mar 8, 2017 at 1:58 PM, Russell King - ARM Linux
[off-list ref] wrote:
On Wed, Mar 08, 2017 at 01:38:41PM -0800, Thomas Garnier wrote:
quoted
This patch prevents a syscall to modify the address limit of the
caller. The address limit is kept by the syscall wrapper and restored
just after the syscall ends.
I would much rather architectures were given the opportunity to code up
checks like this efficiently (iow, inline in the exit path assembly),
rather than having to unconditionally call an additional function on
every syscall, with its register saving overheads.
Me too. I think the two config choices should be:
(a) BUG_ON(!segment_eq(...));
(b) No generic check at all -- arch code will handle it
--Andy
From: Thomas Garnier <hidden> Date: 2017-03-08 22:27:18
That make sense. I will optimize each architecture to not require a call.
On Wed, Mar 8, 2017 at 2:20 PM, Andy Lutomirski [off-list ref] wrote:
On Wed, Mar 8, 2017 at 1:58 PM, Russell King - ARM Linux
[off-list ref] wrote:
quoted
On Wed, Mar 08, 2017 at 01:38:41PM -0800, Thomas Garnier wrote:
quoted
This patch prevents a syscall to modify the address limit of the
caller. The address limit is kept by the syscall wrapper and restored
just after the syscall ends.
I would much rather architectures were given the opportunity to code up
checks like this efficiently (iow, inline in the exit path assembly),
rather than having to unconditionally call an additional function on
every syscall, with its register saving overheads.
Me too. I think the two config choices should be:
(a) BUG_ON(!segment_eq(...));
(b) No generic check at all -- arch code will handle it
--Andy
From: Thomas Garnier <hidden> Date: 2017-03-08 22:33:47
Make sense, as discussed on patch number one, I will write custom
assembly for each architecture when BUG_ON is not required. I will try
to use macros to make it easier to read.
On Wed, Mar 8, 2017 at 2:05 PM, Nicolas Pitre [off-list ref] wrote:
On Wed, 8 Mar 2017, Thomas Garnier wrote:
quoted
Implement specific usage of verify_pre_usermode_state for user-mode
returns for arm.
---
Based on next-20170308
---
arch/arm/Kconfig | 1 +
arch/arm/kernel/entry-common.S | 5 +++++
2 files changed, 6 insertions(+)
This feature is configurable, right?
Here the branch overhead is imposed even if the feature is configured
out. You should consider conditionally defining a macro like some other
features do.
Furthermore I think we still support old toolchains that don't know what
push and pop mean. You should use the legacy syntax instead.
Nicolas
From: Nicolas Pitre <hidden> Date: 2017-03-08 22:42:48
On Wed, 8 Mar 2017, Thomas Garnier wrote:
quoted hunk
Implement specific usage of verify_pre_usermode_state for user-mode
returns for arm.
---
Based on next-20170308
---
arch/arm/Kconfig | 1 +
arch/arm/kernel/entry-common.S | 5 +++++
2 files changed, 6 insertions(+)
This feature is configurable, right?
Here the branch overhead is imposed even if the feature is configured
out. You should consider conditionally defining a macro like some other
features do.
Furthermore I think we still support old toolchains that don't know what
push and pop mean. You should use the legacy syntax instead.
Nicolas
From: Thomas Garnier <hidden> Date: 2017-03-08 22:45:25
Implement specific usage of verify_pre_usermode_state for user-mode
returns for arm64.
---
Based on next-20170308
---
arch/arm64/Kconfig | 1 +
arch/arm64/kernel/entry.S | 2 ++
2 files changed, 3 insertions(+)
From: Thomas Garnier <hidden> Date: 2017-03-09 00:31:38
Implement specific usage of verify_pre_usermode_state for user-mode
returns for arm.
---
Based on next-20170308
---
arch/arm/Kconfig | 1 +
arch/arm/kernel/entry-common.S | 5 +++++
2 files changed, 6 insertions(+)
From: Thomas Garnier <hidden> Date: 2017-03-09 01:13:41
On Wed, Mar 8, 2017 at 1:57 PM, Kees Cook [off-list ref] wrote:
On Wed, Mar 8, 2017 at 1:38 PM, Thomas Garnier [off-list ref] wrote:
quoted
This patch prevents a syscall to modify the address limit of the
caller. The address limit is kept by the syscall wrapper and restored
just after the syscall ends.
For example, it would mitigation this bug:
- https://bugs.chromium.org/p/project-zero/issues/detail?id=990
By default, this change warns if the segment is incorrect while
returning to user-mode and fix it. The
CONFIG_VERIFY_PRE_USERMODE_STATE_BUG option can be enabled to halt
instead if needed.
Instead of this new config, please reuse the CHECK_DATA_CORRUPTION
test instead, which already controls very similar WARN vs BUG
behavior. Example below...
quoted
The CONFIG_ARCH_NO_SYSCALL_VERIFY_PRE_USERMODE_STATE option is also
added so each architecture can optimize how the
verify_pre_usermode_state function is called.
Signed-off-by: Thomas Garnier <redacted>
---
Based on next-20170308
---
include/linux/syscalls.h | 19 +++++++++++++++++++
init/Kconfig | 16 ++++++++++++++++
kernel/sys.c | 11 +++++++++++
3 files changed, 46 insertions(+)
@@ -1929,6 +1929,22 @@ config PROFILINGconfigTRACEPOINTSbool+#+# Set by each architecture that want to optimize how verify_pre_usermode_state+# is called.+#+configARCH_NO_SYSCALL_VERIFY_PRE_USERMODE_STATE+bool++configVERIFY_PRE_USERMODE_STATE_BUG+bool"Halt on incorrect state on returning to user-mode"+defaultn+help+Bydefaultawarningisloggedandthestateisfixed.Thisoption+crashesthekernelinstead.++Ifunsure,sayY.+source"arch/Kconfig"endmenu# General setup