All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: Kurt Manucredo <fuzzybritches0@gmail.com>
Cc: linux-kernel-mentees@lists.linuxfoundation.org
Subject: Re: [PATCH] bpf: core: fix shift-out-of-bounds in ___bpf_prog_run
Date: Thu, 27 May 2021 06:29:39 +0200	[thread overview]
Message-ID: <YK8gM6LoV8q8AkhE@kroah.com> (raw)
In-Reply-To: <60aec085.1c69fb81.972cc.0bfb@mx.google.com>

On Wed, May 26, 2021 at 11:40:27PM +0200, Kurt Manucredo wrote:
> Fix shift-out-of-bounds in ___bpf_prog_run().
> 
> UBSAN: shift-out-of-bounds in kernel/bpf/core.c:1414:2
> shift exponent 248 is too large for 32-bit type 'unsigned int'
> https://syzkaller.appspot.com/bug?id=edb51be4c9a320186328893287bb30d5eed09231
> 
> Reported-by: syzbot+bed360704c521841c85d@syzkaller.appspotmail.com
> Signed-off-by: Kurt Manucredo <fuzzybritches0@gmail.com>
> ---
>  kernel/bpf/core.c | 31 +++++++++++++++++++++++++++++--
>  1 file changed, 29 insertions(+), 2 deletions(-)
> 
> diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
> index 5e31ee9f7512..35cba247c531 100644
> --- a/kernel/bpf/core.c
> +++ b/kernel/bpf/core.c
> @@ -1411,11 +1411,38 @@ static u64 ___bpf_prog_run(u64 *regs, const struct bpf_insn *insn)
>  	ALU(SUB,  -)
>  	ALU(AND,  &)
>  	ALU(OR,   |)
> -	ALU(LSH, <<)
> -	ALU(RSH, >>)
>  	ALU(XOR,  ^)
>  	ALU(MUL,  *)
>  #undef ALU
> +#define ALU(OPCODE, OP)		\
> +	ALU64_##OPCODE##_X:		\
> +		if (SRC >= 64)		\
> +			DST = 0;	\
> +		else			\
> +			DST = DST OP SRC;	\
> +		CONT;			\
> +	ALU_##OPCODE##_X:		\
> +		if (SRC >= 32)		\
> +			DST = 0;	\
> +		else			\
> +			DST = (u32) DST OP (u32) SRC;	\
> +		CONT;			\
> +	ALU64_##OPCODE##_K:		\
> +		if (IMM >= 64)		\
> +			DST = 0;	\
> +		else			\
> +			DST = DST OP IMM;	\
> +		CONT;			\
> +	ALU_##OPCODE##_K:		\
> +		if (IMM >= 32)		\
> +			DST = 0;	\
> +		else			\
> +			DST = (u32) DST OP (u32) IMM;	\
> +		CONT;
> +
> +	ALU(LSH, <<)
> +	ALU(RSH, >>)
> +#undef ALU
>  	ALU_NEG:
>  		DST = (u32) -DST;
>  		CONT;
> -- 
> 2.30.2
> 

This looks odd, shouldn't the caller be checked before it gets to this
part of the code?

did syzbot pass its tests with this change?

thanks,

greg k-h
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

  reply	other threads:[~2021-05-27  4:29 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-26 21:40 [PATCH] bpf: core: fix shift-out-of-bounds in ___bpf_prog_run Kurt Manucredo
2021-05-27  4:29 ` Greg KH [this message]
2021-06-01 14:33   ` [PATCH v2] " Kurt Manucredo
2021-06-01 15:43     ` Greg KH
2021-06-01 21:28       ` Kurt Manucredo
2021-06-02  6:09         ` Greg KH
2021-06-02  6:36           ` Pavel Skripkin
2021-06-04 21:15             ` Kurt Manucredo

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=YK8gM6LoV8q8AkhE@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=fuzzybritches0@gmail.com \
    --cc=linux-kernel-mentees@lists.linuxfoundation.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.