[2/3] x86/uprobes: Fix not using prefixes.nbytes for loop over prefixes.bytes
diff mbox series

Message ID 160689907597.3084105.18019089399087866918.stgit@devnote2
State New, archived
Headers show
Series
  • x86/insn: Fix not using prefixes.nbytes for loop over prefixes.bytes
Related show

Commit Message

Masami Hiramatsu Dec. 2, 2020, 8:51 a.m. UTC
Since the insn.prefixes.nbytes can be bigger than the size of
insn.prefixes.bytes[] when a same prefix is repeated, we have to
check whether the insn.prefixes.bytes[i] != 0 and i < 4 instead
of insn.prefixes.nbytes.

Fixes: 2b1444983508 ("uprobes, mm, x86: Add the ability to install and remove uprobes breakpoints")
Cc: stable@vger.kernel.org
Reported-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
 arch/x86/kernel/uprobes.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Srikar Dronamraju Dec. 2, 2020, 2:51 p.m. UTC | #1
* Masami Hiramatsu <mhiramat@kernel.org> [2020-12-02 17:51:16]:

> Since the insn.prefixes.nbytes can be bigger than the size of
> insn.prefixes.bytes[] when a same prefix is repeated, we have to
> check whether the insn.prefixes.bytes[i] != 0 and i < 4 instead
> of insn.prefixes.nbytes.
> 
> Fixes: 2b1444983508 ("uprobes, mm, x86: Add the ability to install and remove uprobes breakpoints")
> Cc: stable@vger.kernel.org
> Reported-by: Kees Cook <keescook@chromium.org>
> Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>

Looks good to me.

Reviewed-by: Srikar Dronamraju <srikar@linux.vnet.ibm.com>

> ---
>  arch/x86/kernel/uprobes.c |    4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
> index 3fdaa042823d..bb3ea3705b99 100644
> --- a/arch/x86/kernel/uprobes.c
> +++ b/arch/x86/kernel/uprobes.c
> @@ -257,7 +257,7 @@ static bool is_prefix_bad(struct insn *insn)
>  {
>  	int i;
> 
> -	for (i = 0; i < insn->prefixes.nbytes; i++) {
> +	for (i = 0; insn->prefixes.bytes[i] && i < 4; i++) {
>  		insn_attr_t attr;
> 
>  		attr = inat_get_opcode_attribute(insn->prefixes.bytes[i]);
> @@ -746,7 +746,7 @@ static int branch_setup_xol_ops(struct arch_uprobe *auprobe, struct insn *insn)
>  	 * Intel and AMD behavior differ in 64-bit mode: Intel ignores 66 prefix.
>  	 * No one uses these insns, reject any branch insns with such prefix.
>  	 */
> -	for (i = 0; i < insn->prefixes.nbytes; i++) {
> +	for (i = 0; insn->prefixes.bytes[i] && i < 4; i++) {
>  		if (insn->prefixes.bytes[i] == 0x66)
>  			return -ENOTSUPP;
>  	}
>
Kees Cook Dec. 2, 2020, 7:04 p.m. UTC | #2
On Wed, Dec 02, 2020 at 05:51:16PM +0900, Masami Hiramatsu wrote:
> Since the insn.prefixes.nbytes can be bigger than the size of
> insn.prefixes.bytes[] when a same prefix is repeated, we have to
> check whether the insn.prefixes.bytes[i] != 0 and i < 4 instead
> of insn.prefixes.nbytes.
> 
> Fixes: 2b1444983508 ("uprobes, mm, x86: Add the ability to install and remove uprobes breakpoints")
> Cc: stable@vger.kernel.org
> Reported-by: Kees Cook <keescook@chromium.org>

This should probably be:

Reported-by: syzbot+9b64b619f10f19d19a7c@syzkaller.appspotmail.com
Debugged-by: Kees Cook <keescook@chromium.org>

> Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
> ---
>  arch/x86/kernel/uprobes.c |    4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
> index 3fdaa042823d..bb3ea3705b99 100644
> --- a/arch/x86/kernel/uprobes.c
> +++ b/arch/x86/kernel/uprobes.c
> @@ -257,7 +257,7 @@ static bool is_prefix_bad(struct insn *insn)
>  {
>  	int i;
>  
> -	for (i = 0; i < insn->prefixes.nbytes; i++) {
> +	for (i = 0; insn->prefixes.bytes[i] && i < 4; i++) {
>  		insn_attr_t attr;
>  
>  		attr = inat_get_opcode_attribute(insn->prefixes.bytes[i]);
> @@ -746,7 +746,7 @@ static int branch_setup_xol_ops(struct arch_uprobe *auprobe, struct insn *insn)
>  	 * Intel and AMD behavior differ in 64-bit mode: Intel ignores 66 prefix.
>  	 * No one uses these insns, reject any branch insns with such prefix.
>  	 */
> -	for (i = 0; i < insn->prefixes.nbytes; i++) {
> +	for (i = 0; insn->prefixes.bytes[i] && i < 4; i++) {
>  		if (insn->prefixes.bytes[i] == 0x66)
>  			return -ENOTSUPP;
>  	}
>
Masami Hiramatsu Dec. 3, 2020, 2 a.m. UTC | #3
On Wed, 2 Dec 2020 11:04:41 -0800
Kees Cook <keescook@chromium.org> wrote:

> On Wed, Dec 02, 2020 at 05:51:16PM +0900, Masami Hiramatsu wrote:
> > Since the insn.prefixes.nbytes can be bigger than the size of
> > insn.prefixes.bytes[] when a same prefix is repeated, we have to
> > check whether the insn.prefixes.bytes[i] != 0 and i < 4 instead
> > of insn.prefixes.nbytes.
> > 
> > Fixes: 2b1444983508 ("uprobes, mm, x86: Add the ability to install and remove uprobes breakpoints")
> > Cc: stable@vger.kernel.org
> > Reported-by: Kees Cook <keescook@chromium.org>
> 
> This should probably be:
> 
> Reported-by: syzbot+9b64b619f10f19d19a7c@syzkaller.appspotmail.com
> Debugged-by: Kees Cook <keescook@chromium.org>

OK, let me fix it.

Thank you,

> 
> > Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
> > ---
> >  arch/x86/kernel/uprobes.c |    4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
> > index 3fdaa042823d..bb3ea3705b99 100644
> > --- a/arch/x86/kernel/uprobes.c
> > +++ b/arch/x86/kernel/uprobes.c
> > @@ -257,7 +257,7 @@ static bool is_prefix_bad(struct insn *insn)
> >  {
> >  	int i;
> >  
> > -	for (i = 0; i < insn->prefixes.nbytes; i++) {
> > +	for (i = 0; insn->prefixes.bytes[i] && i < 4; i++) {
> >  		insn_attr_t attr;
> >  
> >  		attr = inat_get_opcode_attribute(insn->prefixes.bytes[i]);
> > @@ -746,7 +746,7 @@ static int branch_setup_xol_ops(struct arch_uprobe *auprobe, struct insn *insn)
> >  	 * Intel and AMD behavior differ in 64-bit mode: Intel ignores 66 prefix.
> >  	 * No one uses these insns, reject any branch insns with such prefix.
> >  	 */
> > -	for (i = 0; i < insn->prefixes.nbytes; i++) {
> > +	for (i = 0; insn->prefixes.bytes[i] && i < 4; i++) {
> >  		if (insn->prefixes.bytes[i] == 0x66)
> >  			return -ENOTSUPP;
> >  	}
> > 
> 
> 
> -- 
> Kees Cook
Masami Hiramatsu Dec. 3, 2020, 4:20 a.m. UTC | #4
On Wed, 2 Dec 2020 20:21:35 +0530
Srikar Dronamraju <srikar@linux.vnet.ibm.com> wrote:

> * Masami Hiramatsu <mhiramat@kernel.org> [2020-12-02 17:51:16]:
> 
> > Since the insn.prefixes.nbytes can be bigger than the size of
> > insn.prefixes.bytes[] when a same prefix is repeated, we have to
> > check whether the insn.prefixes.bytes[i] != 0 and i < 4 instead
> > of insn.prefixes.nbytes.
> > 
> > Fixes: 2b1444983508 ("uprobes, mm, x86: Add the ability to install and remove uprobes breakpoints")
> > Cc: stable@vger.kernel.org
> > Reported-by: Kees Cook <keescook@chromium.org>
> > Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
> 
> Looks good to me.
> 
> Reviewed-by: Srikar Dronamraju <srikar@linux.vnet.ibm.com>

Thanks Srikar!


> 
> > ---
> >  arch/x86/kernel/uprobes.c |    4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
> > index 3fdaa042823d..bb3ea3705b99 100644
> > --- a/arch/x86/kernel/uprobes.c
> > +++ b/arch/x86/kernel/uprobes.c
> > @@ -257,7 +257,7 @@ static bool is_prefix_bad(struct insn *insn)
> >  {
> >  	int i;
> > 
> > -	for (i = 0; i < insn->prefixes.nbytes; i++) {
> > +	for (i = 0; insn->prefixes.bytes[i] && i < 4; i++) {
> >  		insn_attr_t attr;
> > 
> >  		attr = inat_get_opcode_attribute(insn->prefixes.bytes[i]);
> > @@ -746,7 +746,7 @@ static int branch_setup_xol_ops(struct arch_uprobe *auprobe, struct insn *insn)
> >  	 * Intel and AMD behavior differ in 64-bit mode: Intel ignores 66 prefix.
> >  	 * No one uses these insns, reject any branch insns with such prefix.
> >  	 */
> > -	for (i = 0; i < insn->prefixes.nbytes; i++) {
> > +	for (i = 0; insn->prefixes.bytes[i] && i < 4; i++) {
> >  		if (insn->prefixes.bytes[i] == 0x66)
> >  			return -ENOTSUPP;
> >  	}
> > 
> 
> -- 
> Thanks and Regards
> Srikar Dronamraju

Patch
diff mbox series

diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
index 3fdaa042823d..bb3ea3705b99 100644
--- a/arch/x86/kernel/uprobes.c
+++ b/arch/x86/kernel/uprobes.c
@@ -257,7 +257,7 @@  static bool is_prefix_bad(struct insn *insn)
 {
 	int i;
 
-	for (i = 0; i < insn->prefixes.nbytes; i++) {
+	for (i = 0; insn->prefixes.bytes[i] && i < 4; i++) {
 		insn_attr_t attr;
 
 		attr = inat_get_opcode_attribute(insn->prefixes.bytes[i]);
@@ -746,7 +746,7 @@  static int branch_setup_xol_ops(struct arch_uprobe *auprobe, struct insn *insn)
 	 * Intel and AMD behavior differ in 64-bit mode: Intel ignores 66 prefix.
 	 * No one uses these insns, reject any branch insns with such prefix.
 	 */
-	for (i = 0; i < insn->prefixes.nbytes; i++) {
+	for (i = 0; insn->prefixes.bytes[i] && i < 4; i++) {
 		if (insn->prefixes.bytes[i] == 0x66)
 			return -ENOTSUPP;
 	}