Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1724805

Re: Buffer overflow in the mptctl_replace_fw() function in linux kernel MPT ioctl driver

From Kees Cook <keescook@chromium.org>
Newsgroups linux.kernel
Subject Re: Buffer overflow in the mptctl_replace_fw() function in linux kernel MPT ioctl driver
Date 2017-09-01 08:50 +0200
Message-ID <ukNWa-9F-5@gated-at.bofh.it> (permalink)
References <ukNjr-8kR-1@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Thu, Aug 31, 2017 at 11:00 PM, Dison River <pwn2river@gmail.com> wrote:
> Hi:
> Buffer overflow in the mptctl_replace_fw() function in linux kernel
> MPT ioctl driver.
>
> In mptctl_replace_fw function, kernel didn't check the size of
> "newFwSize" variable allows attackers to cause a denial of service via
> unspecified vectors that trigger copy_from_user function calls with
> improper length arguments.

Is there a specific path you see to trigger this?

>
>
> static int
> mptctl_replace_fw (unsigned long arg)
> {
> ......
>     if (copy_from_user(&karg, uarg, sizeof(struct mpt_ioctl_replace_fw))) {
>         printk(KERN_ERR MYNAM "%s@%d::mptctl_replace_fw - "
>             "Unable to read in mpt_ioctl_replace_fw struct @ %p\n",
>                 __FILE__, __LINE__, uarg);
>         return -EFAULT;
>     }
>
> ......
>
>     mpt_free_fw_memory(ioc);

This frees ioc->cached_fw.

>
>     /* Allocate memory for the new FW image
>      */
>     newFwSize = ALIGN(karg.newImageSize, 4);
>
>     mpt_alloc_fw_memory(ioc, newFwSize);

This allocates ioc->cached_fw to newFwSize.

> ......
>
>     if (copy_from_user(ioc->cached_fw, uarg->newImage, newFwSize)) {

This copies newFwSize bytes into a buffer that is allocated to newFwSize bytes.

What am I missing? I see some games getting played in
mpt_alloc_fw_memory(), but they seem to be covered due to the earlier
call to mpt_free_fw_memory()...

-Kees

> ///------->newFwSize can control in userspace
>         printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_replace_fw - "
>                 "Unable to read in mpt_ioctl_replace_fw image "
>                 "@ %p\n", ioc->name, __FILE__, __LINE__, uarg);
>         mpt_free_fw_memory(ioc);
>         return -EFAULT;
>     }
>
> ......
>
>     return 0;
> }

-Kees

-- 
Kees Cook
Pixel Security

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Buffer overflow in the mptctl_replace_fw() function in linux kernel  MPT ioctl driver Dison River <pwn2river@gmail.com> - 2017-09-01 08:10 +0200
  Re: Buffer overflow in the mptctl_replace_fw() function in linux  kernel MPT ioctl driver Kees Cook <keescook@chromium.org> - 2017-09-01 08:50 +0200
  Re: Buffer overflow in the mptctl_replace_fw() function in linux  kernel MPT ioctl driver Dan Carpenter <dan.carpenter@oracle.com> - 2017-09-01 10:30 +0200

csiph-web