From patchwork Mon May 9 20:37:40 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Motyka X-Patchwork-Id: 770822 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.3) with ESMTP id p49Kcc7c008654 for ; Mon, 9 May 2011 20:38:38 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751417Ab1EIUi3 (ORCPT ); Mon, 9 May 2011 16:38:29 -0400 Received: from mail-bw0-f46.google.com ([209.85.214.46]:49108 "EHLO mail-bw0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754625Ab1EIUi1 (ORCPT ); Mon, 9 May 2011 16:38:27 -0400 Received: by mail-bw0-f46.google.com with SMTP id 15so4296617bwz.19 for ; Mon, 09 May 2011 13:38:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:message-id:date:from:user-agent:mime-version:to :cc:subject:references:in-reply-to:content-type :content-transfer-encoding; bh=ZQNCBErLv+tLakg5w6UAFDe0aUS9RiJKTndCLB48ce0=; b=B7tJtX2HCYULSgw3eiHbJlqd8rtATt6ftn7jBaxR456CiJoaJZbLhJwiu3scGbDQRl NoBQu4Yt46UKRXEylBclV3GTfgqQiTT/aU56EI+iDblsBNggtROinUBY60eknqBtys1w L5JgsNL1ktfaq3HcMPZAuwhmm0xE0QqxanlDk= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; b=vGdORVD1WXwY4DEWc4CUm7b0PHceZguGrtGmStqwsdMVyA9Jxx1EfOqrJl6t46h0G4 PwW08mAHT0bS14gwJ+nBd3ZLmnt4UDB7vLdGFsmqAcgkMzYttqhyxXCR9skkZWtuLbeS dK1m/IlNxSFv4Mp0CuGLLkJEAXDDV+DNrgvSY= Received: by 10.204.136.1 with SMTP id p1mr291945bkt.105.1304973506292; Mon, 09 May 2011 13:38:26 -0700 (PDT) Received: from [147.32.89.145] (terror.pod.cvut.cz [147.32.89.145]) by mx.google.com with ESMTPS id 16sm3892252bkm.6.2011.05.09.13.38.24 (version=SSLv3 cipher=OTHER); Mon, 09 May 2011 13:38:25 -0700 (PDT) Message-ID: <4DC85094.4050401@gmail.com> Date: Mon, 09 May 2011 22:37:40 +0200 From: Vladimir Motyka User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.17) Gecko/20110414 Lightning/1.0b2 Thunderbird/3.1.10 MIME-Version: 1.0 To: Julia Lawall CC: cjb@laptop.org, kernel-janitors@vger.kernel.org, linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] drivers/mmc/card/block.c: fix potential null dereference 'idata' References: <4DC7F4AB.90607@gmail.com> <4DC802C0.9040302@gmail.com> <4DC8117C.7060200@gmail.com> In-Reply-To: Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Mon, 09 May 2011 20:38:38 +0000 (UTC) When allocation of idata failed there was a null dereference. Also avoid calling kfree where it is needn't. --- if (copy_from_user(idata->buf, (void __user *)(unsigned long) @@ -267,9 +267,10 @@ static struct mmc_blk_ioc_data *mmc_blk_ioctl_copy_from_user( copy_err: kfree(idata->buf); +idata_err: kfree(idata); +out: return ERR_PTR(err); - } static int mmc_blk_ioctl_cmd(struct block_device *bdev, -- To unsubscribe from this list: send the line "unsubscribe linux-mmc" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c index 407836d..126c7f4 100644 --- a/drivers/mmc/card/block.c +++ b/drivers/mmc/card/block.c @@ -237,24 +237,24 @@ static struct mmc_blk_ioc_data *mmc_blk_ioctl_copy_from_user( idata = kzalloc(sizeof(*idata), GFP_KERNEL); if (!idata) { err = -ENOMEM; - goto copy_err; + goto out; } if (copy_from_user(&idata->ic, user, sizeof(idata->ic))) { err = -EFAULT; - goto copy_err; + goto idata_err; } idata->buf_bytes = (u64) idata->ic.blksz * idata->ic.blocks; if (idata->buf_bytes > MMC_IOC_MAX_BYTES) { err = -EOVERFLOW; - goto copy_err; + goto idata_err; } idata->buf = kzalloc(idata->buf_bytes, GFP_KERNEL); if (!idata->buf) { err = -ENOMEM; - goto copy_err; + goto idata_err; }