From: Markos Chandras <Markos.Chandras@imgtec.com>
To: David Laight <David.Laight@ACULAB.COM>,
"linux-mips@linux-mips.org" <linux-mips@linux-mips.org>
Cc: "David S. Miller" <davem@davemloft.net>,
Daniel Borkmann <dborkman@redhat.com>,
Alexei Starovoitov <ast@plumgrid.com>,
"netdev@vger.kernel.org" <netdev@vger.kernel.org>
Subject: Re: [PATCH 14/17] MIPS: bpf: Prevent kernel fall over for >=32bit shifts
Date: Mon, 23 Jun 2014 12:39:38 +0100 [thread overview]
Message-ID: <53A811FA.5060502@imgtec.com> (raw)
In-Reply-To: <063D6719AE5E284EB5DD2968C1650D6D1726139F@AcuExch.aculab.com>
On 06/23/2014 12:08 PM, David Laight wrote:
> From: Markos Chandras
>> On 06/23/2014 10:44 AM, David Laight wrote:
>>> From: Markos Chandras
>>>> Remove BUG_ON() if the shift immediate is >=32 to avoid
>>>> kernel crashes due to malicious user input. Since the micro-assembler
>>>> will not allow an immediate greater or equal to 32, we will use the
>>>> maximum value which is 31. This will do the correct thing on either 32-
>>>> or 64-bit cores since no 64-bit instructions are being used in JIT.
>>>
>>> I'm not sure that bounding the shift to 31 bits 'is the correct thing'.
>>> I'd have thought that emulating the large shift or masking the shift
>>> to 5 bits are equally 'correct'.
>>>
>>> ...
>> Hi David,
>>
>> Since we use 32-bit registers (or rather, we ignore the top 32bits on
>> MIPS64), shifting >= 32 will always result to 0.
>> Alexei suggested [1] to allow large shifts and emulate them, so this
>> patch aims to do that by treating >=32 shift values as 31. Please tell
>> me if I got this wrong.
>
> Shifting by 31 converts 0xffffffff to 1, not 0.
>
> David
>
>
>
oops indeed. Maybe it can be fixed by something like this?
diff --git a/arch/mips/net/bpf_jit.c b/arch/mips/net/bpf_jit.c
index 545c8487542c..32233ec747e0 100644
--- a/arch/mips/net/bpf_jit.c
+++ b/arch/mips/net/bpf_jit.c
@@ -151,6 +151,8 @@ static inline int optimize_div(u32 *k)
return 0;
}
+static inline void emit_jit_reg_move(ptr dst, ptr src, struct jit_ctx
*ctx);
+
/* Simply emit the instruction if the JIT memory space has been
allocated */
#define emit_instr(ctx, func, ...) \
do { \
@@ -310,8 +312,10 @@ static inline void emit_sll(unsigned int dst,
unsigned int src,
{
/* sa is 5-bits long */
if (sa >= BIT(5))
- sa = BIT(5) - 1;
- emit_instr(ctx, sll, dst, src, sa);
+ /* Shifting >= 32 results in zero */
+ emit_jit_reg_move(dst, r_zero, ctx);
+ else
+ emit_instr(ctx, sll, dst, src, sa);
}
static inline void emit_srlv(unsigned int dst, unsigned int src,
@@ -325,8 +329,10 @@ static inline void emit_srl(unsigned int dst,
unsigned int src,
{
/* sa is 5-bits long */
if (sa >= BIT(5))
- sa = BIT(5) - 1;
- emit_instr(ctx, srl, dst, src, sa);
+ /* Shifting >= 32 results in zero */
+ emit_jit_reg_move(dst, r_zero, ctx);
+ else
+ emit_instr(ctx, srl, dst, src, sa);
}
--
markos
next prev parent reply other threads:[~2014-06-23 11:39 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-23 9:38 [PATCH 00/17] Misc MIPS/BPF fixes for 3.16 Markos Chandras
2014-06-23 9:38 ` [PATCH 04/17] MIPS: bpf: Use the LO register to get division's quotient Markos Chandras
2014-06-23 9:38 ` [PATCH 05/17] MIPS: bpf: Return error code if the offset is a negative number Markos Chandras
2014-06-23 22:09 ` Alexei Starovoitov
2014-06-25 8:12 ` Markos Chandras
2014-06-23 9:38 ` [PATCH 06/17] MIPS: bpf: Use 'andi' instead of 'and' for the VLAN cases Markos Chandras
2014-06-23 9:38 ` [PATCH 07/17] MIPS: bpf: Add SEEN_SKB to flags when looking for the PKT_TYPE Markos Chandras
2014-06-23 9:38 ` [PATCH 08/17] MIPS: bpf: Fix branch conditional for BPF_J{GT/GE} cases Markos Chandras
2014-06-23 9:38 ` [PATCH 09/17] MIPS: bpf: Use correct mask for VLAN_TAG case Markos Chandras
2014-06-23 9:38 ` [PATCH 10/17] MIPS: bpf: Fix return values for VLAN_TAG_PRESENT case Markos Chandras
2014-06-23 9:38 ` [PATCH 11/17] MIPS: bpf: Use pr_debug instead of pr_warn for unhandled opcodes Markos Chandras
2014-06-23 9:38 ` [PATCH 12/17] MIPS: bpf: Fix is_range() semantics Markos Chandras
2014-06-23 9:38 ` [PATCH 13/17] MIPS: bpf: Drop update_on_xread and always initialize the X register Markos Chandras
2014-06-23 9:38 ` [PATCH 14/17] MIPS: bpf: Prevent kernel fall over for >=32bit shifts Markos Chandras
2014-06-23 9:44 ` David Laight
2014-06-23 11:06 ` Markos Chandras
2014-06-23 11:08 ` David Laight
2014-06-23 11:39 ` Markos Chandras [this message]
2014-06-25 8:37 ` [PATCH v2 " Markos Chandras
2014-06-23 9:38 ` [PATCH 15/17] MIPS: bpf: Fix PKT_TYPE case for big-endian cores Markos Chandras
2014-06-23 9:38 ` [PATCH 16/17] MIPS: bpf: Use 32 or 64-bit load instruction to load an address to register Markos Chandras
2014-06-23 20:24 ` Paul Burton
2014-06-25 8:18 ` Markos Chandras
2014-06-25 8:39 ` [PATCH v2 " Markos Chandras
2014-06-25 14:28 ` Alexei Starovoitov
2014-06-23 9:39 ` [PATCH 17/17] MIPS: bpf: Fix stack space allocation for BPF memwords on MIPS64 Markos Chandras
2014-06-23 19:49 ` [PATCH 00/17] Misc MIPS/BPF fixes for 3.16 David Miller
2014-06-25 8:12 ` Markos Chandras
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=53A811FA.5060502@imgtec.com \
--to=markos.chandras@imgtec.com \
--cc=David.Laight@ACULAB.COM \
--cc=ast@plumgrid.com \
--cc=davem@davemloft.net \
--cc=dborkman@redhat.com \
--cc=linux-mips@linux-mips.org \
--cc=netdev@vger.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;
as well as URLs for NNTP newsgroup(s).