Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3809016ybi; Mon, 29 Jul 2019 13:03:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqz1g61N6QreHbZ8lk8Yz5F5VSONZNswUm2hnE1XuGFrfUHh6KgAnqYakWM0eUnO6zfQa6Vv X-Received: by 2002:a63:774c:: with SMTP id s73mr107212301pgc.238.1564430602668; Mon, 29 Jul 2019 13:03:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564430602; cv=none; d=google.com; s=arc-20160816; b=eEdW8VnI/eO4OdsCS+NhtZnL8YA+NjdA1cNRuTVorITdBVAAsZAPXZE0cnTyDxStjV ERfTbyctJkuGZ9+W1bE4M4ERFYjwpBSWSX2lS92zNtj40Zw2pZsbi4/8x943/GJdUple JvY09gqoBQ0pDssBPIyvQx0Gmlf9G6eb8SXNTcLaF5uNN3BV0vPbD4C67AivazmkGIRY 4DPJELxehLA7KAnwPp/JbmzGsEf9IzlM/ttT72oySpEyyB32r5oHI1LFT/jcUc07fNSE AAaH56zQCmLbuOIs+RxZ1ThbCSarQkTw7i8qcfLngBwW5+2I1yNEhSruIlq7sGQBdd/O QdOw== 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=W5ax9YCCNrqI/lXmC6xil/e8CF73uKWhBZcTxbcn35Y=; b=KNcfilp+NA2xKUaO+t20DhHqfc77ubXOJ4roGT0oOWKeB1GE9bImwIboL7IgjNWohF 8gCfDsyA5xJoeqj7ynlmoTkCQrkZyBHYc0gcGz1cEvpj1jMDthTe5KCtwtgqZUujFzmF Uj92kbnkcsCClt33ybubdnlJT1ImHzrwJyD+tAA46KeCCJSJXquZ3K8ut7Nh9wjMx8Ft YMQ6keRwMCTqWiyRVtO3HgQ65EnmnEYQBhAbeUrsAtBQjr/JwXyfk36gCm8ONMFFQw/d gmtdumyeNQhBthgyuPvwUuH1lI46ctxHt/1aTt00vSD6cGmeqzNCcsEDJORuNe+lDrRV lxig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=azzjUBHZ; 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 s62si24317309pjc.75.2019.07.29.13.03.07; Mon, 29 Jul 2019 13:03:22 -0700 (PDT) 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=azzjUBHZ; 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 S2391018AbfG2UAg (ORCPT + 99 others); Mon, 29 Jul 2019 16:00:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:44350 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390121AbfG2Twc (ORCPT ); Mon, 29 Jul 2019 15:52:32 -0400 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 9817A204EC; Mon, 29 Jul 2019 19:52:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564429952; bh=w0GuBMuaQl17zfa8FY0kwHgVAdFRg6KpuFNW7q5+UDA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=azzjUBHZKG0ubkAwKSu7wOD028EkZtucD5glSEl4pvke9eBdfNIJG2uXfebwS68vB aalZTx68nsDw0Zr8OjnoiQsvxMOLV0pA5v4nKa+VipPBL2DO3ZKeax24YpmDcK4ZUB OVNIWfaM7q7/HvYZAxQfnUDNK9Mz3CrW10alymeA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ming Lei , "Martin K. Petersen" , Wenwen Wang , Jens Axboe , Sasha Levin Subject: [PATCH 5.2 147/215] block/bio-integrity: fix a memory leak bug Date: Mon, 29 Jul 2019 21:22:23 +0200 Message-Id: <20190729190805.209329734@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190729190739.971253303@linuxfoundation.org> References: <20190729190739.971253303@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 [ Upstream commit e7bf90e5afe3aa1d1282c1635a49e17a32c4ecec ] In bio_integrity_prep(), a kernel buffer is allocated through kmalloc() to hold integrity metadata. Later on, the buffer will be attached to the bio structure through bio_integrity_add_page(), which returns the number of bytes of integrity metadata attached. Due to unexpected situations, bio_integrity_add_page() may return 0. As a result, bio_integrity_prep() needs to be terminated with 'false' returned to indicate this error. However, the allocated kernel buffer is not freed on this execution path, leading to a memory leak. To fix this issue, free the allocated buffer before returning from bio_integrity_prep(). Reviewed-by: Ming Lei Acked-by: Martin K. Petersen Signed-off-by: Wenwen Wang Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- block/bio-integrity.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/block/bio-integrity.c b/block/bio-integrity.c index 4db620849515..fb95dbb21dd8 100644 --- a/block/bio-integrity.c +++ b/block/bio-integrity.c @@ -276,8 +276,12 @@ bool bio_integrity_prep(struct bio *bio) ret = bio_integrity_add_page(bio, virt_to_page(buf), bytes, offset); - if (ret == 0) - return false; + if (ret == 0) { + printk(KERN_ERR "could not attach integrity payload\n"); + kfree(buf); + status = BLK_STS_RESOURCE; + goto err_end_io; + } if (ret < bytes) break; -- 2.20.1