From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.0 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AE10CC10F11 for ; Wed, 24 Apr 2019 17:22:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7E3A520675 for ; Wed, 24 Apr 2019 17:22:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1556126572; bh=4gtR+ipHP8b1akbPwICoubHd21BbkofpmeWiKRBdxrA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=pNrUe/Ul2Z9kYuvWuzTpA61JKjSrvaYA4ngSWlCPk/v0hzFZhD7rRBq4PcQ3SyWWP vGZ4hpasUb+w5qS3Y8Nu6NaPWCt3ia2CONCV9+IS+9BCCZ1St79AYch7R1+MBX7mdQ tdgzSB31jY7b1a2mbIY4T6ZbY6bna1z29ZaGwCZE= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389418AbfDXRWv (ORCPT ); Wed, 24 Apr 2019 13:22:51 -0400 Received: from mail.kernel.org ([198.145.29.99]:48408 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389398AbfDXRWs (ORCPT ); Wed, 24 Apr 2019 13:22:48 -0400 Received: from localhost (62-193-50-229.as16211.net [62.193.50.229]) (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 E3BEA20675; Wed, 24 Apr 2019 17:22:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1556126567; bh=4gtR+ipHP8b1akbPwICoubHd21BbkofpmeWiKRBdxrA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=R3m6MRyEvTzrRV9O5wSltzyUnLpFUbX0uVeON/EudVjFLIiaNjJ7PUgo29BhhGrX+ 3PB62QiigqJ1LASYmZTWHQKaQ+yI7cC5ue60yq2kHX/K8SBg1uN22pUkfMZ3Kz8s6E OtB8hUmz4okGMgKyy4GgfxYAOONF6LAgcr/wQsxk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ian Abbott Subject: [PATCH 4.4 154/168] staging: comedi: vmk80xx: Fix possible double-free of ->usb_rx_buf Date: Wed, 24 Apr 2019 19:09:58 +0200 Message-Id: <20190424170932.268783931@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190424170923.452349382@linuxfoundation.org> References: <20190424170923.452349382@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: Ian Abbott commit 663d294b4768bfd89e529e069bffa544a830b5bf upstream. `vmk80xx_alloc_usb_buffers()` is called from `vmk80xx_auto_attach()` to allocate RX and TX buffers for USB transfers. It allocates `devpriv->usb_rx_buf` followed by `devpriv->usb_tx_buf`. If the allocation of `devpriv->usb_tx_buf` fails, it frees `devpriv->usb_rx_buf`, leaving the pointer set dangling, and returns an error. Later, `vmk80xx_detach()` will be called from the core comedi module code to clean up. `vmk80xx_detach()` also frees both `devpriv->usb_rx_buf` and `devpriv->usb_tx_buf`, but `devpriv->usb_rx_buf` may have already been freed, leading to a double-free error. Fix it by removing the call to `kfree(devpriv->usb_rx_buf)` from `vmk80xx_alloc_usb_buffers()`, relying on `vmk80xx_detach()` to free the memory. Signed-off-by: Ian Abbott Cc: stable Signed-off-by: Greg Kroah-Hartman --- drivers/staging/comedi/drivers/vmk80xx.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) --- a/drivers/staging/comedi/drivers/vmk80xx.c +++ b/drivers/staging/comedi/drivers/vmk80xx.c @@ -691,10 +691,8 @@ static int vmk80xx_alloc_usb_buffers(str size = le16_to_cpu(devpriv->ep_tx->wMaxPacketSize); devpriv->usb_tx_buf = kzalloc(size, GFP_KERNEL); - if (!devpriv->usb_tx_buf) { - kfree(devpriv->usb_rx_buf); + if (!devpriv->usb_tx_buf) return -ENOMEM; - } return 0; }