Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3546480pxj; Mon, 24 May 2021 09:05:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJya6/QimJUBfEgAjCHqNtCFX17ee/r2wNkgKBFsRVzPw5hk93/SJDE7ycuJKJo9m9K1gmDR X-Received: by 2002:a05:6402:3507:: with SMTP id b7mr26498914edd.101.1621872355679; Mon, 24 May 2021 09:05:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621872355; cv=none; d=google.com; s=arc-20160816; b=06fPJS8J90GkWWo7EWT8iE/2WEAk/Xu6a60TFu3vW/qgAeLOoWxmbBSoOHIEN0odAT /6UeATk3YLkduzlS/rk5Li8a3XVhWPJg2vqAW6vUbU0EwT7mqQJ6qrPnq+QcJNDLsv5m MjNaM2lzskZIq4GCFpceuPu8e+JNEEiDZShV2nQTQkcAHVnfESt99YqE3+mzcR8xffWL Qmzj9D8OSgNVOL3z6CM8zViH2jLhhlHrZLrAY1SWJo4MIiSGHQz2z8dz+LxuBMHQC2GO 6pqUJ+V1SZ87UXYH7YU0egMRtrNxM62X6H21T4EqzgtJv3KrgSxvKfKXqk/l4AgBY9kg rHZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=CC85L3gfxgeAkeb8mL6XIT6rHfTCXD6f2lw32NdkXDU=; b=uXOqZOhVyIT1xOR5CeKdGzdOyYuOdnx9IX7mTf6TQTdX5L/bM/h8Ze7pQf+UOV8wi+ rXRu32EREoGUBJ9py/IJCurCh2jRr1URiK9mbyvrzFc7s7xtRWu2IT7pk9i9IQt1AFsV gmNb5maqBHFhkBX0ny7BbHbacNQj8N8iwv9I6MNjvs6/xVCNkbs3RaR3/F395W5yfLeR xNienEFq9P8hZy+cF6SlijnjnUjwiM/oZXOOcLeZGPu/vGHDEqDR2boTGb1s/qxNSjqk G1brQySSSHWkujJ1YfJOC0Au2WrdH3R96X/BDT4orMbkTeIe2jLep1kX81Hjtc5NlKWk +zYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=XwPK9pFM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dk7si15222503ejb.409.2021.05.24.09.05.24; Mon, 24 May 2021 09:05:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=XwPK9pFM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237639AbhEXQFb (ORCPT + 99 others); Mon, 24 May 2021 12:05:31 -0400 Received: from mail.kernel.org ([198.145.29.99]:41186 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234830AbhEXP7D (ORCPT ); Mon, 24 May 2021 11:59:03 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 80E306197D; Mon, 24 May 2021 15:44:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621871090; bh=0/p0tc9WrNj0jr3ZyF9G/zdESfFGAEkfgCe3qd7ps5w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XwPK9pFM7r06gbr/8I2z9zsM+eGsxYTafVVvDnrXzpoUope+GMgBgjvbx1iUmlbFQ tp7b3BPW9nJ+3KPK8AuVkEQP66oB5h+FXurDG7KQGtmDHMKncDbNpk/kvmFqwe7G21 SUVqaN82WV58YqJQj8HPrsh/WVLeE2iASCMhnoLM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Christophe JAILLET Subject: [PATCH 5.12 061/127] uio_hv_generic: Fix a memory leak in error handling paths Date: Mon, 24 May 2021 17:26:18 +0200 Message-Id: <20210524152336.896674027@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210524152334.857620285@linuxfoundation.org> References: <20210524152334.857620285@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Christophe JAILLET commit 3ee098f96b8b6c1a98f7f97915f8873164e6af9d upstream. If 'vmbus_establish_gpadl()' fails, the (recv|send)_gpadl will not be updated and 'hv_uio_cleanup()' in the error handling path will not be able to free the corresponding buffer. In such a case, we need to free the buffer explicitly. Fixes: cdfa835c6e5e ("uio_hv_generic: defer opening vmbus until first use") Cc: stable Signed-off-by: Christophe JAILLET Link: https://lore.kernel.org/r/4fdaff557deef6f0475d02ba7922ddbaa1ab08a6.1620544055.git.christophe.jaillet@wanadoo.fr Signed-off-by: Greg Kroah-Hartman --- drivers/uio/uio_hv_generic.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) --- a/drivers/uio/uio_hv_generic.c +++ b/drivers/uio/uio_hv_generic.c @@ -296,8 +296,10 @@ hv_uio_probe(struct hv_device *dev, ret = vmbus_establish_gpadl(channel, pdata->recv_buf, RECV_BUFFER_SIZE, &pdata->recv_gpadl); - if (ret) + if (ret) { + vfree(pdata->recv_buf); goto fail_close; + } /* put Global Physical Address Label in name */ snprintf(pdata->recv_name, sizeof(pdata->recv_name), @@ -316,8 +318,10 @@ hv_uio_probe(struct hv_device *dev, ret = vmbus_establish_gpadl(channel, pdata->send_buf, SEND_BUFFER_SIZE, &pdata->send_gpadl); - if (ret) + if (ret) { + vfree(pdata->send_buf); goto fail_close; + } snprintf(pdata->send_name, sizeof(pdata->send_name), "send:%u", pdata->send_gpadl);