Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3790445ybi; Mon, 29 Jul 2019 12:40:47 -0700 (PDT) X-Google-Smtp-Source: APXvYqwoW8TYE88+TDTNqgteNvnG/DSslqFwvYCoNGQUDkaftENonXbqvxcBK5zcRmCDylGZobi2 X-Received: by 2002:a63:20a:: with SMTP id 10mr104774551pgc.226.1564429247055; Mon, 29 Jul 2019 12:40:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564429247; cv=none; d=google.com; s=arc-20160816; b=sP7t/0k5wMQC+NHNXnyQnykMnpNFYedYY9S4IQQcS6IFali8RhbqExn55dNyQl/I0y S1ejp61k/kuN10ggqH3wU/P1KvP5/fPEDZlYS6Vs9URSii0aqKrcOyhxdjSjYNh1fEss I8M7JaVdF/LRGH6Vc+ieXqDWyJnLI1YUhnkG6b1RDaDcRua/idMaEV0NZMcdxLu8O8S4 6+Ip+1wl0SZR6ACv0UV6uYW4QOm/l4NyDxCFiND2aDf8EM4FOLyvbdmY836853SmgqL3 Uo3MADmcqFYDWaTMdrW38la5AsGTsxAyY3n+JEOdGycf/bb+0CsCrAbRpWsmmfEW+K/L SKoA== 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=XUHWsRG8V23Xfie2LQvkF3qG+36tW8ySMd8iiK6QgJE=; b=KpUV7LIbJr9UoNpGPiRNGPingEADWNNeepcKEXSI1ck+yZlv9kz4NpHIXxU8bzNldE MXqCztTgo+M81CmmQ0cmQRF1dhH1wgTF1m3SYfrkqrswxWP12UcwAZkymeFJui1ldgNB QDN8vyoRw9lc+bIsRYgjJHxhG0U5fmGD69rpYAyGLa+JCa9qFOBFL6hoYbFrOqyRiBme 6VQmrN5yEoWXOG8l18gRlme0ilhzcMoOqOkkvt4EnWCYkvMneewM/OH7Sn+nyGMwWONT uR7kqJDVwRm/LRWtVUJAzGHBgPNiegnlQaqF5v/skqdATlcCX9mcmOlGWWp5LP8FyCzC 8WUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=PSi2kQRd; 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 21si3911530pgk.492.2019.07.29.12.40.32; Mon, 29 Jul 2019 12:40:47 -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=PSi2kQRd; 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 S2388880AbfG2Tig (ORCPT + 99 others); Mon, 29 Jul 2019 15:38:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:53404 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388857AbfG2Ti1 (ORCPT ); Mon, 29 Jul 2019 15:38:27 -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 DAFF62054F; Mon, 29 Jul 2019 19:38:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564429106; bh=7TwS66VnkAXcEWwLDrxDGAjg4D9ngN0o0NFESBASDec=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PSi2kQRdccJ2ieSgrKQ9xv2VhEhHz0t5V+c0GghbQS4m6gbYBfLCzM+jEZD67fKr/ JiMb+yLemTZtr+mT6GYl5KwnsrKskcmT0F6hbLFH0zuWSCdsnlGekZDw6CZOT1Wmnl T8FpUrMS7LWbJM/XmZtZkjlkvSPmea3S1OqdjsRM= 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 4.14 269/293] block/bio-integrity: fix a memory leak bug Date: Mon, 29 Jul 2019 21:22:40 +0200 Message-Id: <20190729190844.960449333@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190729190820.321094988@linuxfoundation.org> References: <20190729190820.321094988@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 5df32907ff3b..7f8010662437 100644 --- a/block/bio-integrity.c +++ b/block/bio-integrity.c @@ -313,8 +313,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