Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp5999976ybc; Wed, 27 Nov 2019 13:10:22 -0800 (PST) X-Google-Smtp-Source: APXvYqz9ggcpbjwAQG1yZpEwLOaJF0xA+hUWvpcR6/fwlTWw+sL+4JnNli7BCfnPhLBitwN2Rgi6 X-Received: by 2002:a50:8ada:: with SMTP id k26mr2986511edk.100.1574889022487; Wed, 27 Nov 2019 13:10:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574889022; cv=none; d=google.com; s=arc-20160816; b=TDFkI6paQgdt4MtTMRUPkFhOuMTjBxsm2NbrHtYC6uRBJnhk+Ohk1zUoUxHUBs1U/m UJg9bb4KTZZBEo8WuTSTGJ6F4o/P6876UnDuWwy/MpDVOBZtqLTUI9/bI7zuUXTtXART g5AD5tYhG/QguJHVFWZypy7Q90B7peV78SJ8sWDXfcwdWBZkJgoVmpmAZmNG3xUBTlxi 2o71ASs1R1zSA2l6f1Yl1OHgeZz4e3uqaUo4kxwCYJVj174q0Gg3FU7tq/49Z19eQNdG c3yP6Wc+1tHayvV96SEBnali3jkcerLXS8rw4A/LJEgauF0NkiWAmvg/TsJEa1brqJg4 7nxA== 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=XKe7vTVMuwHDwv8KM3vauOc2Zx4UZVQTgrZet1GUT9o=; b=L3gLWkvpw9qalJNiLC0fhR3Kcxsn6A/QHiBsZJp/937fA0BKKYcJiLZukOptLKT2r7 XwsqAV2SiewgkX2xMVyim93pwfKCeW/NckQ+ILY53vRT4j0BVzMCU906wxMJWtghKNVK iRc3C7St/dk4nWh4proFVCTxsAbThTeOWCf5Zj+Y0+Kb/wgfG6oYx9V3SVUFJ8sz6uSW 7q1aFW3I1fqSucXHykmhCQRIZOYS2AHyLcwD2takd7YFFQbwnU8oeK2Yt0H+jhhJlD1V jiKRuoT2Z7c0tbWQQJTzSGz/AOE0nS7W62BgN0nA1so7AhN5YPw+4FisOtTLvnEqy0Z6 LRUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=WMKneCkF; 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 f15si4191798edy.159.2019.11.27.13.09.58; Wed, 27 Nov 2019 13:10:22 -0800 (PST) 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=WMKneCkF; 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 S1732460AbfK0VGi (ORCPT + 99 others); Wed, 27 Nov 2019 16:06:38 -0500 Received: from mail.kernel.org ([198.145.29.99]:60722 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732433AbfK0VGc (ORCPT ); Wed, 27 Nov 2019 16:06:32 -0500 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 8DD7121843; Wed, 27 Nov 2019 21:06:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1574888792; bh=egGgjq34mNQHDV+YUm8b+aSrL1YXPGQXAQkh4o3C5Mc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WMKneCkFvb8D7WKo7OANhpgSATtMleFiDi5hL1HxW77pasBxhDOUZ3vx+DkxEWKGi Kx8RZ3rIWGwqQSqkfMeX1kkEzhgebsihGNB8bYW0MhhhSPl7V0383IdZsJVnOMsWt9 2iRU/kyb6dXwJ1zvJOdLwye9V2m6/0dKP4tZ5uBg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Josef Bacik , Navid Emamdoost , Jens Axboe Subject: [PATCH 4.19 270/306] nbd: prevent memory leak Date: Wed, 27 Nov 2019 21:32:00 +0100 Message-Id: <20191127203134.553583842@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191127203114.766709977@linuxfoundation.org> References: <20191127203114.766709977@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: Navid Emamdoost commit 03bf73c315edca28f47451913177e14cd040a216 upstream. In nbd_add_socket when krealloc succeeds, if nsock's allocation fail the reallocted memory is leak. The correct behaviour should be assigning the reallocted memory to config->socks right after success. Reviewed-by: Josef Bacik Signed-off-by: Navid Emamdoost Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman --- drivers/block/nbd.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) --- a/drivers/block/nbd.c +++ b/drivers/block/nbd.c @@ -984,14 +984,15 @@ static int nbd_add_socket(struct nbd_dev sockfd_put(sock); return -ENOMEM; } + + config->socks = socks; + nsock = kzalloc(sizeof(struct nbd_sock), GFP_KERNEL); if (!nsock) { sockfd_put(sock); return -ENOMEM; } - config->socks = socks; - nsock->fallback_index = -1; nsock->dead = false; mutex_init(&nsock->tx_lock);