lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <YKfE+gfK5AdE9ckm@zn.tnic>
Date:   Fri, 21 May 2021 16:34:34 +0200
From:   Borislav Petkov <bp@...en8.de>
To:     Joerg Roedel <joro@...tes.org>
Cc:     x86@...nel.org, Hyunwook Baek <baekhw@...gle.com>,
        Joerg Roedel <jroedel@...e.de>, hpa@...or.com,
        Andy Lutomirski <luto@...nel.org>,
        Dave Hansen <dave.hansen@...ux.intel.com>,
        Peter Zijlstra <peterz@...radead.org>,
        Jiri Slaby <jslaby@...e.cz>,
        Dan Williams <dan.j.williams@...el.com>,
        Tom Lendacky <thomas.lendacky@....com>,
        Juergen Gross <jgross@...e.com>,
        Kees Cook <keescook@...omium.org>,
        David Rientjes <rientjes@...gle.com>,
        Cfir Cohen <cfir@...gle.com>,
        Erdem Aktas <erdemaktas@...gle.com>,
        Masami Hiramatsu <mhiramat@...nel.org>,
        Mike Stunes <mstunes@...are.com>,
        Sean Christopherson <seanjc@...gle.com>,
        Martin Radev <martin.b.radev@...il.com>,
        Arvind Sankar <nivedita@...m.mit.edu>,
        linux-coco@...ts.linux.dev, linux-kernel@...r.kernel.org,
        kvm@...r.kernel.org, virtualization@...ts.linux-foundation.org
Subject: Re: [PATCH v2 7/8] x86/insn: Extend error reporting from
 insn_fetch_from_user[_inatomic]()

On Wed, May 19, 2021 at 03:52:50PM +0200, Joerg Roedel wrote:
> diff --git a/arch/x86/lib/insn-eval.c b/arch/x86/lib/insn-eval.c
> index 4eecb9c7c6a0..d8a057ba0895 100644
> --- a/arch/x86/lib/insn-eval.c
> +++ b/arch/x86/lib/insn-eval.c
> @@ -1442,27 +1442,36 @@ static int insn_get_effective_ip(struct pt_regs *regs, unsigned long *ip)
>   * insn_fetch_from_user() - Copy instruction bytes from user-space memory
>   * @regs:	Structure with register values as seen when entering kernel mode
>   * @buf:	Array to store the fetched instruction
> + * @copied:	Pointer to an int where the number of copied instruction bytes
> + *		is stored. Can be NULL.
>   *
>   * Gets the linear address of the instruction and copies the instruction bytes
>   * to the buf.
>   *
>   * Returns:
>   *
> - * Number of instruction bytes copied.
> + * -EINVAL if the linear address of the instruction could not be calculated
> + * -EFAULT if nothing was copied
> + *       0 on success
>   *
> - * 0 if nothing was copied.
>   */
> -int insn_fetch_from_user(struct pt_regs *regs, unsigned char buf[MAX_INSN_SIZE])
> +int insn_fetch_from_user(struct pt_regs *regs, unsigned char buf[MAX_INSN_SIZE],
> +			 int *copied)
>  {
>  	unsigned long ip;
>  	int not_copied;
> +	int bytes;
>  
>  	if (insn_get_effective_ip(regs, &ip))
> -		return 0;
> +		return -EINVAL;
>  
>  	not_copied = copy_from_user(buf, (void __user *)ip, MAX_INSN_SIZE);
>  
> -	return MAX_INSN_SIZE - not_copied;
> +	bytes = MAX_INSN_SIZE - not_copied;
> +	if (copied)
> +		*copied = bytes;
> +
> +	return bytes ? 0 : -EFAULT;

Why not simpler?

return value >= 0 says how many bytes were copied
return value < 0 means some kind of error

And then you don't need @copied...

Ditto for the other one.

-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ