Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2522492imu; Thu, 29 Nov 2018 06:22:12 -0800 (PST) X-Google-Smtp-Source: AFSGD/Xq3yDkI+FjvjH74wdNHNcZOEuPU3vwVY+6A75ZPGkRkLQKnDgqsg3RyWts36KLJeHFWTcc X-Received: by 2002:a63:181c:: with SMTP id y28mr1366145pgl.75.1543501332635; Thu, 29 Nov 2018 06:22:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543501332; cv=none; d=google.com; s=arc-20160816; b=t4X4KRW7fmsoo597VfbAH24QRKpYcKF2Q7w8pHp4G9cHN8WlcL9SGxcdDqgqKFRcLo i5YYMAgb2XXIohy5AG6F8iJYTUWwvURa9uf1Q+jxqZXTWnl7TLOBggTiD6+jSyBPtHAs 33/aRDJzFxEBxoSUp1hcFNMTwVnIgvJEeTOOw34kHD4SZGdZp0XedZbg2e1Jk/9uVvGa FmDd3wxeAKuWIoPA62B/Wd5LdbHDooflRPttD0RWhC6o8kKUHOqC8v/LEPjAp84gYYD8 1oELkM1oBJFcd4nrGmPDvd/fhR2o7tK6qSzt7LR/OH+K+DTvcMhJcSuA7qRq92Xi7oT0 H46w== 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=YDs6h3a4YvCrtQ/pdrHduPyWfpCgjhaDGXRXqOnXlJQ=; b=Ts/Q3uELf4d4xeFcsL7lbkVOw+u3eC/w814c6386IDqkZOUTWo4ZGAWWlb84yW9OkW xPWB/RtJ583tNBQO3zq7wM5mKTxLr5twAGkrnvar9AMfJxp5k7G9AIeMiKShIEO37uxI NLjl9mFX8FVxTt8Pc2SX2rqaUOdTVDzpTMxnFIYVrDgSUaMq5VzEAn/T/YKRhMx/of3c EMXVGRm5Bg5Nymm+FOQ3IVm6u/sKfteWv0rt4unvDZLdojgW4gWjwn/Vgr8zmaoOlrGo wKou+i78uIhUI2ha27bz8196T8lLRTU5gZODcj1JIqMk3ygpBN134xKj4XKL6NyQMHyr qdbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=hCIAq3gu; 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 i5si2234808pfo.189.2018.11.29.06.21.57; Thu, 29 Nov 2018 06:22:12 -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=hCIAq3gu; 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 S1731095AbeK3BY7 (ORCPT + 99 others); Thu, 29 Nov 2018 20:24:59 -0500 Received: from mail.kernel.org ([198.145.29.99]:48124 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729918AbeK3BY6 (ORCPT ); Thu, 29 Nov 2018 20:24:58 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.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 F2908205C9; Thu, 29 Nov 2018 14:19:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1543501167; bh=SstcGJkuP4W0yF4FjNwpUuMkH7LpDlmMy7C4T6VFQ/8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hCIAq3gui6LkneKj+NAkJvLtPljwi8OWt+dKGHIpkKqZigRHdCFfurZUhDFOAuUE0 RRw8qLjm9eiq/VLwB2kmRwdlfieauDCLjaFLCKQ3fzKytBMwJ17QmJ6YH0jUZWnbK2 Amq3K+ZjLbZxWaLEyQvI6RJsRKYuilEP9g3w24lk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Johannes Thumshirn , Johannes Berg , Kalle Valo , Amit Pundir Subject: [PATCH 4.4 69/86] cw1200: Dont leak memory if krealloc failes Date: Thu, 29 Nov 2018 15:12:34 +0100 Message-Id: <20181129140115.644648095@linuxfoundation.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181129140109.832117862@linuxfoundation.org> References: <20181129140109.832117862@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review 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 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Johannes Thumshirn commit 9afdd6128c39f42398041bb2e017d8df0dcebcd1 upstream. The call to krealloc() in wsm_buf_reserve() directly assigns the newly returned memory to buf->begin. This is all fine except when krealloc() failes we loose the ability to free the old memory pointed to by buf->begin. If we just create a temporary variable to assign memory to and assign the memory to it we can mitigate the memory leak. Signed-off-by: Johannes Thumshirn Cc: Johannes Berg Signed-off-by: Kalle Valo Signed-off-by: Amit Pundir Signed-off-by: Greg Kroah-Hartman --- drivers/net/wireless/cw1200/wsm.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) --- a/drivers/net/wireless/cw1200/wsm.c +++ b/drivers/net/wireless/cw1200/wsm.c @@ -1805,16 +1805,18 @@ static int wsm_buf_reserve(struct wsm_bu { size_t pos = buf->data - buf->begin; size_t size = pos + extra_size; + u8 *tmp; size = round_up(size, FWLOAD_BLOCK_SIZE); - buf->begin = krealloc(buf->begin, size, GFP_KERNEL | GFP_DMA); - if (buf->begin) { - buf->data = &buf->begin[pos]; - buf->end = &buf->begin[size]; - return 0; - } else { - buf->end = buf->data = buf->begin; + tmp = krealloc(buf->begin, size, GFP_KERNEL | GFP_DMA); + if (!tmp) { + wsm_buf_deinit(buf); return -ENOMEM; } + + buf->begin = tmp; + buf->data = &buf->begin[pos]; + buf->end = &buf->begin[size]; + return 0; }