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] [thread-next>] [day] [month] [year] [list]
Message-ID: <BYAPR02MB599297A2EB81002FA34AC401B8720@BYAPR02MB5992.namprd02.prod.outlook.com>
Date:   Tue, 5 Mar 2019 18:57:05 +0000
From:   Jolly Shah <JOLLYS@...inx.com>
To:     Jann Horn <jannh@...gle.com>, Michal Simek <michals@...inx.com>
CC:     Rajan Vaja <RAJANV@...inx.com>,
        "linux-arm-kernel@...ts.infradead.org" 
        <linux-arm-kernel@...ts.infradead.org>,
        "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Subject: RE: [PATCH] firmware: xilinx: fix debugfs write handler

Acked-by: Jolly Shah <jollys@...inx.com>


> -----Original Message-----
> From: Jann Horn <jannh@...gle.com>
> Sent: Monday, February 18, 2019 1:43 PM
> To: Michal Simek <michals@...inx.com>; jannh@...gle.com
> Cc: Rajan Vaja <RAJANV@...inx.com>; Jolly Shah <JOLLYS@...inx.com>; linux-
> arm-kernel@...ts.infradead.org; linux-kernel@...r.kernel.org
> Subject: [PATCH] firmware: xilinx: fix debugfs write handler
> 
>  - Userspace wants to write a string with `len` bytes, not counting the
>    terminating NULL, so we should allocate `len+1` bytes. It looks like the
>    current code relied on having a nullbyte directly behind `kern_buff`,
>    which happens to work reliably as long as `len` isn't one of the kmalloc
>    size classes.
>  - strncpy_from_user() is completely wrong here; userspace is giving us a
>    (not necessarily null-terminated) buffer and its length.
>    strncpy_from_user() is for cases in which we don't know the length.
>  - Don't let broken userspace allocate arbitrarily big kmalloc allocations.
> 
> Just use memdup_user_nul(), which is designed precisely for things like
> this.
> 
> Signed-off-by: Jann Horn <jannh@...gle.com>
> ---
> WARNING: completely untested patch
> 
> drivers/firmware/xilinx/zynqmp-debug.c | 15 ++++-----------
>  1 file changed, 4 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/firmware/xilinx/zynqmp-debug.c
> b/drivers/firmware/xilinx/zynqmp-debug.c
> index 2771df6df379..90b66cdbfd58 100644
> --- a/drivers/firmware/xilinx/zynqmp-debug.c
> +++ b/drivers/firmware/xilinx/zynqmp-debug.c
> @@ -163,21 +163,14 @@ static ssize_t zynqmp_pm_debugfs_api_write(struct
> file *file,
> 
>  	strcpy(debugfs_buf, "");
> 
> -	if (*off != 0 || len == 0)
> +	if (*off != 0 || len <= 1 || len > PAGE_SIZE - 1)
>  		return -EINVAL;
> 
> -	kern_buff = kzalloc(len, GFP_KERNEL);
> -	if (!kern_buff)
> -		return -ENOMEM;
> -
> +	kern_buff = memdup_user_nul(ptr, len);
> +	if (IS_ERR(kern_buff))
> +		return PTR_ERR(kern_buff);
>  	tmp_buff = kern_buff;
> 
> -	ret = strncpy_from_user(kern_buff, ptr, len);
> -	if (ret < 0) {
> -		ret = -EFAULT;
> -		goto err;
> -	}
> -
>  	/* Read the API name from a user request */
>  	pm_api_req = strsep(&kern_buff, " ");
> 
> --
> 2.21.0.rc0.258.g878e2cd30e-goog

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ