From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756575AbcCCSfj (ORCPT ); Thu, 3 Mar 2016 13:35:39 -0500 Received: from bombadil.infradead.org ([198.137.202.9]:60092 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751435AbcCCSfi (ORCPT ); Thu, 3 Mar 2016 13:35:38 -0500 Subject: Re: [PATCH] platform/chrome: cros_ec_dev - Fix security issue To: Gwendal Grignou , olofj@chromium.org, alan@lxorguk.ukuu.org.uk, javier.martinez@collabora.co.uk References: <20160301203338.360a3487@www.etchedpixels.co.uk> <1456984736-19811-1-git-send-email-gwendal@chromium.org> Cc: linux-kernel@vger.kernel.org From: Randy Dunlap Message-ID: <56D883F7.6020002@infradead.org> Date: Thu, 3 Mar 2016 10:35:35 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.0 MIME-Version: 1.0 In-Reply-To: <1456984736-19811-1-git-send-email-gwendal@chromium.org> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 03/02/16 21:58, Gwendal Grignou wrote: > Add a check to prevent memory scribbe when sending an ioctl with .insize scribble > set so large that memory allocation argument overflows. > > Signed-off-by: Gwendal Grignou > --- > drivers/platform/chrome/cros_ec_dev.c | 12 +++++++++++- > 1 file changed, 11 insertions(+), 1 deletion(-) > > diff --git a/drivers/platform/chrome/cros_ec_dev.c b/drivers/platform/chrome/cros_ec_dev.c > index d45cd25..86d6373 100644 > --- a/drivers/platform/chrome/cros_ec_dev.c > +++ b/drivers/platform/chrome/cros_ec_dev.c > @@ -131,13 +131,23 @@ static ssize_t ec_device_read(struct file *filp, char __user *buffer, > static long ec_device_ioctl_xcmd(struct cros_ec_dev *ec, void __user *arg) > { > long ret; > + size_t data_size; > struct cros_ec_command u_cmd; > struct cros_ec_command *s_cmd; > > if (copy_from_user(&u_cmd, arg, sizeof(u_cmd))) > return -EFAULT; > > - s_cmd = kmalloc(sizeof(*s_cmd) + max(u_cmd.outsize, u_cmd.insize), > + /* > + * Prevent mallicious attack where .inside is so big that amount malicious .insize > + * kmalloc'ed rollover, allowing memcpy to write beyond the allocated > + * space. > + */ > + data_size = max(u_cmd.outsize, u_cmd.insize); > + if (data_size + sizeof(*s_cmd) < data_size) > + return -EINVAL; > + > + s_cmd = kmalloc(sizeof(*s_cmd) + data_size, > GFP_KERNEL); > if (!s_cmd) > return -ENOMEM; > -- ~Randy