Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp464630yba; Wed, 15 May 2019 04:35:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqwTHYUuMYwiGgcPf2NklLzT8eFhSOW86BS6iT4Rm3movcGeYOaRuRU6FDMbXKaz7XL/J7tS X-Received: by 2002:a17:902:8214:: with SMTP id x20mr21142052pln.308.1557920101711; Wed, 15 May 2019 04:35:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557920101; cv=none; d=google.com; s=arc-20160816; b=dv6JGdQU5aiUr8lviKyMNVn2nXglwS4KX8msCr3ZsqV8sFSF2cIrsXz4t0SAlg/bZt YLf04YUezGnoQhwPMCoO4x+CmAvTJct3NfwsjxEYJAl7/TXZMlPqGF17Xc6f3ealBN4q tdAj1CSQFm066jnAO6HmgUKv4VoKlVUEuCs46uDQIoccPAYRp7bomAoabxQl82mnr5bl OnJhaVQsurpUUxjtri1dkPooOzK7r/zcWoa5NHnCN9kTawVS00aeR4AeFTTka716r2Um KAy0bfrCxVJ5fSr6JyDChVXMlzW3/TrxXj7PqMviSiofVkOb8ARG8vMoADjXAL572fnv SE7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=bJzJ4x3l1m0YIIqgTyKFjWDlxE18tHaJ353+lXRPrb8=; b=zruGV+1BzMFXuwvjIhkWvPUFSZYW+1As3Zwm99elWxOH/VNFfRdGLoZfbLG++rEkt/ /hZgkXR5bAc8dhWoNpl7B7iThExnJ2jpqb6zDC8dTGmsb+kAMTH1AYDbHeQ9xnRHcXnp 7SlhbI/x3GD3XykLXs9qLSZDLhT0pClub+Yq+DSl3OWKhK4kP5PjDCrOfs0wwEmIm1tG gFqhdCSTRMA7NAFgECYI7RbaXanx/2IwJxQMVeCw1RmNfck+b23Oj9ceUUAUDtNvtkWe C9AScZnqz2+PjCi1DG3XIw/IQ0KMMKqntrtCikqL57cR8HVwLKGXMIHebYt1kxsdWCcn FWCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=rk6cQB68; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a69si1549403pla.178.2019.05.15.04.34.46; Wed, 15 May 2019 04:35:01 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=rk6cQB68; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732949AbfEOLb6 (ORCPT + 99 others); Wed, 15 May 2019 07:31:58 -0400 Received: from mail.kernel.org ([198.145.29.99]:43718 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732431AbfEOLb4 (ORCPT ); Wed, 15 May 2019 07:31:56 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 11269206BF; Wed, 15 May 2019 11:31:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1557919915; bh=okYy+GU6/N0t4Tvh74P9xri3NwBQ8lf9DQZpI4Zyqi4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rk6cQB68BZCk1xPk5p5MF3Qkq0e25ytpvqyeOukfny8+QnDyqMI1fElohO0H8LtZJ ibBxBTEbR71/qYXsPiMflDfMGgDXncU4FD51q2UcZl8E0wzDB9HSxiO4axzicQRFzg G6YjSU1estpfdEis+U3XQbaCh5ayikiwBnfqXboI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter , Andrew Morton , Timur Tabi , Mihai Caraman , Kumar Gala , Linus Torvalds Subject: [PATCH 5.0 128/137] drivers/virt/fsl_hypervisor.c: dereferencing error pointers in ioctl Date: Wed, 15 May 2019 12:56:49 +0200 Message-Id: <20190515090703.193844260@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190515090651.633556783@linuxfoundation.org> References: <20190515090651.633556783@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dan Carpenter commit c8ea3663f7a8e6996d44500ee818c9330ac4fd88 upstream. strndup_user() returns error pointers on error, and then in the error handling we pass the error pointers to kfree(). It will cause an Oops. Link: http://lkml.kernel.org/r/20181218082003.GD32567@kadam Fixes: 6db7199407ca ("drivers/virt: introduce Freescale hypervisor management driver") Signed-off-by: Dan Carpenter Reviewed-by: Andrew Morton Cc: Timur Tabi Cc: Mihai Caraman Cc: Kumar Gala Cc: Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- drivers/virt/fsl_hypervisor.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) --- a/drivers/virt/fsl_hypervisor.c +++ b/drivers/virt/fsl_hypervisor.c @@ -331,8 +331,8 @@ static long ioctl_dtprop(struct fsl_hv_i struct fsl_hv_ioctl_prop param; char __user *upath, *upropname; void __user *upropval; - char *path = NULL, *propname = NULL; - void *propval = NULL; + char *path, *propname; + void *propval; int ret = 0; /* Get the parameters from the user. */ @@ -344,32 +344,30 @@ static long ioctl_dtprop(struct fsl_hv_i upropval = (void __user *)(uintptr_t)param.propval; path = strndup_user(upath, FH_DTPROP_MAX_PATHLEN); - if (IS_ERR(path)) { - ret = PTR_ERR(path); - goto out; - } + if (IS_ERR(path)) + return PTR_ERR(path); propname = strndup_user(upropname, FH_DTPROP_MAX_PATHLEN); if (IS_ERR(propname)) { ret = PTR_ERR(propname); - goto out; + goto err_free_path; } if (param.proplen > FH_DTPROP_MAX_PROPLEN) { ret = -EINVAL; - goto out; + goto err_free_propname; } propval = kmalloc(param.proplen, GFP_KERNEL); if (!propval) { ret = -ENOMEM; - goto out; + goto err_free_propname; } if (set) { if (copy_from_user(propval, upropval, param.proplen)) { ret = -EFAULT; - goto out; + goto err_free_propval; } param.ret = fh_partition_set_dtprop(param.handle, @@ -388,7 +386,7 @@ static long ioctl_dtprop(struct fsl_hv_i if (copy_to_user(upropval, propval, param.proplen) || put_user(param.proplen, &p->proplen)) { ret = -EFAULT; - goto out; + goto err_free_propval; } } } @@ -396,10 +394,12 @@ static long ioctl_dtprop(struct fsl_hv_i if (put_user(param.ret, &p->ret)) ret = -EFAULT; -out: - kfree(path); +err_free_propval: kfree(propval); +err_free_propname: kfree(propname); +err_free_path: + kfree(path); return ret; }