From: Ingo Molnar <mingo@kernel.org>
To: Dan Williams <dan.j.williams@intel.com>
Cc: tglx@linutronix.de, linux-arch@vger.kernel.org,
kernel-hardening@lists.openwall.com, gregkh@linuxfoundation.org,
x86@kernel.org, Ingo Molnar <mingo@redhat.com>,
"H. Peter Anvin" <hpa@zytor.com>,
torvalds@linux-foundation.org, alan@linux.intel.com
Subject: Re: [PATCH v5 03/12] x86: implement array_idx_mask
Date: Sun, 28 Jan 2018 10:02:50 +0100 [thread overview]
Message-ID: <20180128090250.3gxq2uoebiwh4who@gmail.com> (raw)
In-Reply-To: <151703972912.26578.6792656143278523491.stgit@dwillia2-desk3.amr.corp.intel.com>
* Dan Williams <dan.j.williams@intel.com> wrote:
> 'array_idx' uses a mask to sanitize user controllable array indexes,
> i.e. generate a 0 mask if idx >= sz, and a ~0 mask otherwise. While the
> default array_idx_mask handles the carry-bit from the (index - size)
> result in software. The x86 'array_idx_mask' does the same, but the
> carry-bit is handled in the processor CF flag without conditional
> instructions in the control flow.
Same style comments apply as for patch 02.
> Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: Ingo Molnar <mingo@redhat.com>
> Cc: "H. Peter Anvin" <hpa@zytor.com>
> Cc: x86@kernel.org
> Signed-off-by: Dan Williams <dan.j.williams@intel.com>
> ---
> arch/x86/include/asm/barrier.h | 22 ++++++++++++++++++++++
> 1 file changed, 22 insertions(+)
>
> diff --git a/arch/x86/include/asm/barrier.h b/arch/x86/include/asm/barrier.h
> index 01727dbc294a..30419b674ebd 100644
> --- a/arch/x86/include/asm/barrier.h
> +++ b/arch/x86/include/asm/barrier.h
> @@ -24,6 +24,28 @@
> #define wmb() asm volatile("sfence" ::: "memory")
> #endif
>
> +/**
> + * array_idx_mask - generate a mask for array_idx() that is ~0UL when
> + * the bounds check succeeds and 0 otherwise
> + *
> + * mask = 0 - (idx < sz);
> + */
> +#define array_idx_mask array_idx_mask
> +static inline unsigned long array_idx_mask(unsigned long idx, unsigned long sz)
Please put an extra newline between definitions (even if they are closely related
as these).
> +{
> + unsigned long mask;
> +
> +#ifdef CONFIG_X86_32
> + asm ("cmpl %1,%2; sbbl %0,%0;"
> +#else
> + asm ("cmpq %1,%2; sbbq %0,%0;"
> +#endif
Wouldn't this suffice:
asm ("cmp %1,%2; sbb %0,%0;"
... as the word width should automatically be 32 bits on 32-bit kernels and 64
bits on 64-bit kernels?
Thanks,
Ingo
next prev parent reply other threads:[~2018-01-28 9:14 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <151703971300.26578.1185595719337719486.stgit@dwillia2-desk3.amr.corp.intel.com>
2018-01-27 19:26 ` [PATCH v5 00/12] spectre variant1 mitigations for tip/x86/pti Dan Williams
[not found] ` <151703972396.26578.7326612698912543866.stgit@dwillia2-desk3.amr.corp.intel.com>
2018-01-28 8:55 ` [PATCH v5 02/12] array_idx: sanitize speculative array de-references Ingo Molnar
2018-01-28 11:36 ` Thomas Gleixner
2018-01-28 16:28 ` Dan Williams
2018-01-28 18:33 ` Ingo Molnar
2018-01-29 16:45 ` Dan Williams
2018-01-28 18:36 ` [kernel-hardening] " Thomas Gleixner
2018-01-30 6:29 ` Dan Williams
2018-01-30 19:38 ` Linus Torvalds
2018-01-30 20:13 ` Dan Williams
2018-01-30 20:27 ` Van De Ven, Arjan
2018-01-31 8:03 ` Ingo Molnar
2018-01-31 14:13 ` Van De Ven, Arjan
2018-01-31 14:21 ` Greg KH
[not found] ` <151703972912.26578.6792656143278523491.stgit@dwillia2-desk3.amr.corp.intel.com>
2018-01-28 9:02 ` Ingo Molnar [this message]
[not found] ` <151703973427.26578.15693075353773519333.stgit@dwillia2-desk3.amr.corp.intel.com>
2018-01-28 9:14 ` [PATCH v5 04/12] x86: introduce __uaccess_begin_nospec and ifence Ingo Molnar
2018-01-29 20:41 ` Dan Williams
2018-01-30 6:56 ` Ingo Molnar
[not found] ` <151703974000.26578.2874964402485950653.stgit@dwillia2-desk3.amr.corp.intel.com>
2018-01-28 9:19 ` [PATCH v5 05/12] x86, __get_user: use __uaccess_begin_nospec Ingo Molnar
[not found] ` <151703974570.26578.3809646715924406820.stgit@dwillia2-desk3.amr.corp.intel.com>
2018-01-28 9:25 ` [PATCH v5 06/12] x86, get_user: use pointer masking to limit speculation Ingo Molnar
[not found] ` <151703975137.26578.11230688940391207602.stgit@dwillia2-desk3.amr.corp.intel.com>
2018-01-28 9:29 ` [PATCH v5 07/12] x86: remove the syscall_64 fast-path Ingo Molnar
2018-01-28 15:22 ` Andy Lutomirski
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=20180128090250.3gxq2uoebiwh4who@gmail.com \
--to=mingo@kernel.org \
--cc=alan@linux.intel.com \
--cc=dan.j.williams@intel.com \
--cc=gregkh@linuxfoundation.org \
--cc=hpa@zytor.com \
--cc=kernel-hardening@lists.openwall.com \
--cc=linux-arch@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.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 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®