All of lore.kernel.org
 help / color / mirror / Atom feed
From: Will Deacon <will.deacon@arm.com>
To: Thomas Garnier <thgarnie@google.com>
Cc: Kees Cook <keescook@chromium.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, "H . Peter Anvin" <hpa@zytor.com>,
	Andy Lutomirski <luto@kernel.org>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Rik van Riel <riel@redhat.com>, Oleg Nesterov <oleg@redhat.com>,
	Josh Poimboeuf <jpoimboe@redhat.com>,
	Petr Mladek <pmladek@suse.com>, Miroslav Benes <mbenes@suse.cz>,
	Al Viro <viro@zeniv.linux.org.uk>, Arnd Bergmann <arnd@arndb.de>,
	Dave Hansen <dave.hansen@intel.com>,
	David Howells <dhowells@redhat.com>,
	Russell King <linux@armlinux.org.uk>,
	Andy Lutomirski <luto@amacapital.net>,
	Will Drewry <wad@chromium.org>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Mark Rutland <mark.rutland@arm.com>,
	Pratyush Anand <panand@redhat.com>,
	Chris Metcalf <cmetcalf@mellanox.com>,
	"x86@kernel.org" <x86@kernel.org>,
	LKML <linux-kernel@vger.kernel.org>,
	Linux API <linux-api@vger.kernel.org>,
	"linux-arm-kernel@lists.infradead.org"
	<linux-arm-kernel@lists.infradead.org>,
	"kernel-hardening@lists.openwall.com"
	<kernel-hardening@lists.openwall.com>
Subject: [kernel-hardening] Re: [PATCH v10 2/3] arm/syscalls: Check address limit on user-mode return
Date: Wed, 21 Jun 2017 10:08:15 +0100	[thread overview]
Message-ID: <20170621090815.GC3768@arm.com> (raw)
In-Reply-To: <CAJcbSZG8KH7kw5HMP-7HvfHh2RdAfGnOqjOibHr5H42tORRGCw@mail.gmail.com>

On Tue, Jun 20, 2017 at 01:31:14PM -0700, Thomas Garnier wrote:
> On Tue, Jun 20, 2017 at 1:18 PM, Kees Cook <keescook@chromium.org> wrote:
> > On Wed, Jun 14, 2017 at 6:12 PM, Thomas Garnier <thgarnie@google.com> wrote:
> >> diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
> >> index eb5cd77bf1d8..e33c32d56193 100644
> >> --- a/arch/arm/kernel/entry-common.S
> >> +++ b/arch/arm/kernel/entry-common.S
> >> @@ -41,7 +41,9 @@ ret_fast_syscall:
> >>   UNWIND(.cantunwind    )
> >>         disable_irq_notrace                     @ disable interrupts
> >>         ldr     r1, [tsk, #TI_FLAGS]            @ re-check for syscall tracing
> >> -       tst     r1, #_TIF_SYSCALL_WORK | _TIF_WORK_MASK
> >> +       tst     r1, #_TIF_SYSCALL_WORK
> >> +       bne     fast_work_pending
> >> +       tst     r1, #_TIF_WORK_MASK
> >
> > (IIUC) MOV32 is 2 cycles (MOVW, MOVT), and each TST above is 1 cycle
> > and each BNE is 1 cycle (when not taken). So:
> >
> > mov32 r2, #_TIF_SYSCALL_WORK | _TIF_WORK_MASK
> > tst r1, r2
> > bne fast_work_pending
> >
> > is 4 cycles and tst, bne, tst, bne is also 4 cycles. Would mov32 be
> > more readable (since it keeps the flags together)?
> 
> I guess it would be more readable. Any opinion from the arm folks?

The mov32 sequence is probably better, but statically attributing cycles
on a per instruction basis is pretty futile on modern CPUs.

Will

WARNING: multiple messages have this Message-ID (diff)
From: Will Deacon <will.deacon@arm.com>
To: Thomas Garnier <thgarnie@google.com>
Cc: Kees Cook <keescook@chromium.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, "H . Peter Anvin" <hpa@zytor.com>,
	Andy Lutomirski <luto@kernel.org>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Rik van Riel <riel@redhat.com>, Oleg Nesterov <oleg@redhat.com>,
	Josh Poimboeuf <jpoimboe@redhat.com>,
	Petr Mladek <pmladek@suse.com>, Miroslav Benes <mbenes@suse.cz>,
	Al Viro <viro@zeniv.linux.org.uk>, Arnd Bergmann <arnd@arndb.de>,
	Dave Hansen <dave.hansen@intel.com>,
	David Howells <dhowells@redhat.com>,
	Russell King <linux@armlinux.org.uk>,
	Andy Lutomirski <luto@amacapital.net>,
	Will Drewry <wad@chromium.org>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Mark Rutland <mark.rutland@arm.com>,
	Pratyush Anand <panand@redhat.com>,
	Chris Metcalf <cmetcalf@mellanox.com>,
	"x86@kernel.org" <x86@kernel.org>,
	LKML <linux-kernel@vger.kernel.org>, Linux API <linux-api@>
Subject: Re: [PATCH v10 2/3] arm/syscalls: Check address limit on user-mode return
Date: Wed, 21 Jun 2017 10:08:15 +0100	[thread overview]
Message-ID: <20170621090815.GC3768@arm.com> (raw)
In-Reply-To: <CAJcbSZG8KH7kw5HMP-7HvfHh2RdAfGnOqjOibHr5H42tORRGCw@mail.gmail.com>

On Tue, Jun 20, 2017 at 01:31:14PM -0700, Thomas Garnier wrote:
> On Tue, Jun 20, 2017 at 1:18 PM, Kees Cook <keescook@chromium.org> wrote:
> > On Wed, Jun 14, 2017 at 6:12 PM, Thomas Garnier <thgarnie@google.com> wrote:
> >> diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
> >> index eb5cd77bf1d8..e33c32d56193 100644
> >> --- a/arch/arm/kernel/entry-common.S
> >> +++ b/arch/arm/kernel/entry-common.S
> >> @@ -41,7 +41,9 @@ ret_fast_syscall:
> >>   UNWIND(.cantunwind    )
> >>         disable_irq_notrace                     @ disable interrupts
> >>         ldr     r1, [tsk, #TI_FLAGS]            @ re-check for syscall tracing
> >> -       tst     r1, #_TIF_SYSCALL_WORK | _TIF_WORK_MASK
> >> +       tst     r1, #_TIF_SYSCALL_WORK
> >> +       bne     fast_work_pending
> >> +       tst     r1, #_TIF_WORK_MASK
> >
> > (IIUC) MOV32 is 2 cycles (MOVW, MOVT), and each TST above is 1 cycle
> > and each BNE is 1 cycle (when not taken). So:
> >
> > mov32 r2, #_TIF_SYSCALL_WORK | _TIF_WORK_MASK
> > tst r1, r2
> > bne fast_work_pending
> >
> > is 4 cycles and tst, bne, tst, bne is also 4 cycles. Would mov32 be
> > more readable (since it keeps the flags together)?
> 
> I guess it would be more readable. Any opinion from the arm folks?

The mov32 sequence is probably better, but statically attributing cycles
on a per instruction basis is pretty futile on modern CPUs.

Will

WARNING: multiple messages have this Message-ID (diff)
From: will.deacon@arm.com (Will Deacon)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v10 2/3] arm/syscalls: Check address limit on user-mode return
Date: Wed, 21 Jun 2017 10:08:15 +0100	[thread overview]
Message-ID: <20170621090815.GC3768@arm.com> (raw)
In-Reply-To: <CAJcbSZG8KH7kw5HMP-7HvfHh2RdAfGnOqjOibHr5H42tORRGCw@mail.gmail.com>

On Tue, Jun 20, 2017 at 01:31:14PM -0700, Thomas Garnier wrote:
> On Tue, Jun 20, 2017 at 1:18 PM, Kees Cook <keescook@chromium.org> wrote:
> > On Wed, Jun 14, 2017 at 6:12 PM, Thomas Garnier <thgarnie@google.com> wrote:
> >> diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
> >> index eb5cd77bf1d8..e33c32d56193 100644
> >> --- a/arch/arm/kernel/entry-common.S
> >> +++ b/arch/arm/kernel/entry-common.S
> >> @@ -41,7 +41,9 @@ ret_fast_syscall:
> >>   UNWIND(.cantunwind    )
> >>         disable_irq_notrace                     @ disable interrupts
> >>         ldr     r1, [tsk, #TI_FLAGS]            @ re-check for syscall tracing
> >> -       tst     r1, #_TIF_SYSCALL_WORK | _TIF_WORK_MASK
> >> +       tst     r1, #_TIF_SYSCALL_WORK
> >> +       bne     fast_work_pending
> >> +       tst     r1, #_TIF_WORK_MASK
> >
> > (IIUC) MOV32 is 2 cycles (MOVW, MOVT), and each TST above is 1 cycle
> > and each BNE is 1 cycle (when not taken). So:
> >
> > mov32 r2, #_TIF_SYSCALL_WORK | _TIF_WORK_MASK
> > tst r1, r2
> > bne fast_work_pending
> >
> > is 4 cycles and tst, bne, tst, bne is also 4 cycles. Would mov32 be
> > more readable (since it keeps the flags together)?
> 
> I guess it would be more readable. Any opinion from the arm folks?

The mov32 sequence is probably better, but statically attributing cycles
on a per instruction basis is pretty futile on modern CPUs.

Will

WARNING: multiple messages have this Message-ID (diff)
From: Will Deacon <will.deacon@arm.com>
To: Thomas Garnier <thgarnie@google.com>
Cc: Kees Cook <keescook@chromium.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, "H . Peter Anvin" <hpa@zytor.com>,
	Andy Lutomirski <luto@kernel.org>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Rik van Riel <riel@redhat.com>, Oleg Nesterov <oleg@redhat.com>,
	Josh Poimboeuf <jpoimboe@redhat.com>,
	Petr Mladek <pmladek@suse.com>, Miroslav Benes <mbenes@suse.cz>,
	Al Viro <viro@zeniv.linux.org.uk>, Arnd Bergmann <arnd@arndb.de>,
	Dave Hansen <dave.hansen@intel.com>,
	David Howells <dhowells@redhat.com>,
	Russell King <linux@armlinux.org.uk>,
	Andy Lutomirski <luto@amacapital.net>,
	Will Drewry <wad@chromium.org>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Mark Rutland <mark.rutland@arm.com>,
	Pratyush Anand <panand@redhat.com>,
	Chris Metcalf <cmetcalf@mellanox.com>,
	"x86@kernel.org" <x86@kernel.org>,
	LKML <linux-kernel@vger.kernel.org>,
	Linux API <linux-api@vger.kernel.org>,
	"linux-arm-kernel@lists.infradead.org" 
	<linux-arm-kernel@lists.infradead.org>,
	"kernel-hardening@lists.openwall.com" 
	<kernel-hardening@lists.openwall.com>
Subject: Re: [PATCH v10 2/3] arm/syscalls: Check address limit on user-mode return
Date: Wed, 21 Jun 2017 10:08:15 +0100	[thread overview]
Message-ID: <20170621090815.GC3768@arm.com> (raw)
In-Reply-To: <CAJcbSZG8KH7kw5HMP-7HvfHh2RdAfGnOqjOibHr5H42tORRGCw@mail.gmail.com>

On Tue, Jun 20, 2017 at 01:31:14PM -0700, Thomas Garnier wrote:
> On Tue, Jun 20, 2017 at 1:18 PM, Kees Cook <keescook@chromium.org> wrote:
> > On Wed, Jun 14, 2017 at 6:12 PM, Thomas Garnier <thgarnie@google.com> wrote:
> >> diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
> >> index eb5cd77bf1d8..e33c32d56193 100644
> >> --- a/arch/arm/kernel/entry-common.S
> >> +++ b/arch/arm/kernel/entry-common.S
> >> @@ -41,7 +41,9 @@ ret_fast_syscall:
> >>   UNWIND(.cantunwind    )
> >>         disable_irq_notrace                     @ disable interrupts
> >>         ldr     r1, [tsk, #TI_FLAGS]            @ re-check for syscall tracing
> >> -       tst     r1, #_TIF_SYSCALL_WORK | _TIF_WORK_MASK
> >> +       tst     r1, #_TIF_SYSCALL_WORK
> >> +       bne     fast_work_pending
> >> +       tst     r1, #_TIF_WORK_MASK
> >
> > (IIUC) MOV32 is 2 cycles (MOVW, MOVT), and each TST above is 1 cycle
> > and each BNE is 1 cycle (when not taken). So:
> >
> > mov32 r2, #_TIF_SYSCALL_WORK | _TIF_WORK_MASK
> > tst r1, r2
> > bne fast_work_pending
> >
> > is 4 cycles and tst, bne, tst, bne is also 4 cycles. Would mov32 be
> > more readable (since it keeps the flags together)?
> 
> I guess it would be more readable. Any opinion from the arm folks?

The mov32 sequence is probably better, but statically attributing cycles
on a per instruction basis is pretty futile on modern CPUs.

Will

  reply	other threads:[~2017-06-21  9:08 UTC|newest]

Thread overview: 89+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-15  1:12 [kernel-hardening] [PATCH v10 1/3] x86/syscalls: Check address limit on user-mode return Thomas Garnier
2017-06-15  1:12 ` Thomas Garnier
2017-06-15  1:12 ` Thomas Garnier
2017-06-15  1:12 ` [kernel-hardening] [PATCH v10 2/3] arm/syscalls: " Thomas Garnier
2017-06-15  1:12   ` Thomas Garnier
2017-06-15  1:12   ` Thomas Garnier
2017-06-20 20:18   ` [kernel-hardening] " Kees Cook
2017-06-20 20:18     ` Kees Cook
2017-06-20 20:18     ` Kees Cook
2017-06-20 20:18     ` Kees Cook
2017-06-20 20:31     ` [kernel-hardening] " Thomas Garnier
2017-06-20 20:31       ` Thomas Garnier
2017-06-20 20:31       ` Thomas Garnier
2017-06-20 20:31       ` Thomas Garnier
2017-06-21  9:08       ` Will Deacon [this message]
2017-06-21  9:08         ` Will Deacon
2017-06-21  9:08         ` Will Deacon
2017-06-21  9:08         ` Will Deacon
2017-07-08 12:10   ` [tip:x86/syscall] " tip-bot for Thomas Garnier
2017-07-18 14:36   ` [kernel-hardening] Re: [PATCH v10 2/3] " Leonard Crestez
2017-07-18 14:36     ` Leonard Crestez
2017-07-18 14:36     ` Leonard Crestez
2017-07-18 14:36     ` Leonard Crestez
2017-07-18 16:04     ` [kernel-hardening] " Thomas Garnier
2017-07-18 16:04       ` Thomas Garnier
2017-07-18 16:04       ` Thomas Garnier
2017-07-18 16:04       ` Thomas Garnier
2017-07-18 17:18       ` [kernel-hardening] " Leonard Crestez
2017-07-18 17:18         ` Leonard Crestez
2017-07-18 17:18         ` Leonard Crestez
2017-07-18 17:18         ` Leonard Crestez
2017-07-18 19:04         ` [kernel-hardening] " Thomas Garnier
2017-07-18 19:04           ` Thomas Garnier
2017-07-18 19:04           ` Thomas Garnier
2017-07-18 19:04           ` Thomas Garnier
2017-07-19 14:58           ` [kernel-hardening] " Leonard Crestez
2017-07-19 14:58             ` Leonard Crestez
2017-07-19 14:58             ` Leonard Crestez
2017-07-19 14:58             ` Leonard Crestez
2017-07-19 16:51             ` [kernel-hardening] " Thomas Garnier
2017-07-19 16:51               ` Thomas Garnier
2017-07-19 16:51               ` Thomas Garnier
2017-07-19 16:51               ` Thomas Garnier
2017-07-19 17:06             ` [kernel-hardening] " Russell King - ARM Linux
2017-07-19 17:06               ` Russell King - ARM Linux
2017-07-19 17:06               ` Russell King - ARM Linux
2017-07-19 17:06               ` Russell King - ARM Linux
2017-07-19 17:20               ` [kernel-hardening] " Thomas Garnier
2017-07-19 17:20                 ` Thomas Garnier
2017-07-19 17:20                 ` Thomas Garnier
2017-07-19 18:35                 ` Russell King - ARM Linux
2017-07-19 18:35                   ` Russell King - ARM Linux
2017-07-19 18:35                   ` Russell King - ARM Linux
2017-07-19 18:50                   ` Thomas Garnier
2017-07-19 18:50                     ` Thomas Garnier
2017-07-19 18:50                     ` Thomas Garnier
2017-06-15  1:12 ` [kernel-hardening] [PATCH v10 3/3] arm64/syscalls: " Thomas Garnier
2017-06-15  1:12   ` Thomas Garnier
2017-06-15  1:12   ` Thomas Garnier
2017-06-21  8:16   ` [kernel-hardening] " Catalin Marinas
2017-06-21  8:16     ` Catalin Marinas
2017-06-21  8:16     ` Catalin Marinas
2017-06-21  8:16     ` Catalin Marinas
2017-06-21 13:57     ` [kernel-hardening] " Thomas Garnier
2017-06-21 13:57       ` Thomas Garnier
2017-06-21 13:57       ` Thomas Garnier
2017-06-21 13:57       ` Thomas Garnier
2017-07-08 12:10   ` [tip:x86/syscall] " tip-bot for Thomas Garnier
2017-06-20 20:24 ` [kernel-hardening] Re: [PATCH v10 1/3] x86/syscalls: " Kees Cook
2017-06-20 20:24   ` Kees Cook
2017-06-20 20:24   ` Kees Cook
2017-06-20 20:24   ` Kees Cook
2017-06-28 17:52   ` [kernel-hardening] " Kees Cook
2017-06-28 17:52     ` Kees Cook
2017-06-28 17:52     ` Kees Cook
2017-06-28 17:52     ` Kees Cook
2017-07-06 20:38     ` [kernel-hardening] " Thomas Garnier
2017-07-06 20:38       ` Thomas Garnier
2017-07-06 20:38       ` Thomas Garnier
2017-07-06 20:38       ` Thomas Garnier
2017-07-06 20:48       ` [kernel-hardening] " Thomas Gleixner
2017-07-06 20:48         ` Thomas Gleixner
2017-07-06 20:48         ` Thomas Gleixner
2017-07-06 20:48         ` Thomas Gleixner
2017-07-06 20:52         ` [kernel-hardening] " Thomas Garnier
2017-07-06 20:52           ` Thomas Garnier
2017-07-06 20:52           ` Thomas Garnier
2017-07-06 20:52           ` Thomas Garnier
2017-07-08 12:09 ` [tip:x86/syscall] " tip-bot for Thomas Garnier

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=20170621090815.GC3768@arm.com \
    --to=will.deacon@arm.com \
    --cc=arnd@arndb.de \
    --cc=catalin.marinas@arm.com \
    --cc=cmetcalf@mellanox.com \
    --cc=dave.hansen@intel.com \
    --cc=dhowells@redhat.com \
    --cc=hpa@zytor.com \
    --cc=jpoimboe@redhat.com \
    --cc=keescook@chromium.org \
    --cc=kernel-hardening@lists.openwall.com \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=luto@amacapital.net \
    --cc=luto@kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mbenes@suse.cz \
    --cc=mingo@redhat.com \
    --cc=oleg@redhat.com \
    --cc=panand@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=pmladek@suse.com \
    --cc=riel@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=thgarnie@google.com \
    --cc=viro@zeniv.linux.org.uk \
    --cc=wad@chromium.org \
    --cc=x86@kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.