Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3795166ybi; Mon, 29 Jul 2019 12:46:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqxJtIjHLa7um4gaOkptXvoqOh8u9eq4Qtue+V983cKmSVBet+q97XQMNb1476zgBXtItLAL X-Received: by 2002:a17:90a:fe5:: with SMTP id 92mr114935976pjz.35.1564429596019; Mon, 29 Jul 2019 12:46:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564429596; cv=none; d=google.com; s=arc-20160816; b=FuEEaRTLoMjXplejTH+oQd7EovLgVNP+u7RCi+nikRgidNDHaS5KgpfUxXDOfxiDdQ GtP1hxqUkAOBP7DQ788griCyzfK4Lw6lD7JmK1eoR28fbtSnrk66BkIoR3gMddnrbIHw NTyZ+kicqWqskIab67J5niEnStaVjDV2UyQf2TRfQKidiaBaGKsUdsr+fMivNXJaiy7O hJZL3ZI1uPIrJvXz+LP3spMvxOo6FSyhCc1dU7y5MQrf9/cWXFHUjTKtkID6Ja84k+J6 XwyC2rEBaBzaq+X+CXFfPa/Gl9hOKVjSxzA3FXNxRgDfJcY2au0zjTyVaJNKMNjko/oR DaqQ== 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=2y5rb4qiW3DDWdk54bjp7XuMF9f4ReFkFVs1jc7etEg=; b=RDwx5+iAhmuzynqvO3/S0ejpwPvEG3tjMfayyE8Q7F94wIOt6o761Ev/iqfRPGERat yDUs3B1OBfMCU3tgfiIJOk4I9l1VwE13WbMzu0NoKRnsa4U9DUlietd4rrvBbPssdNHE 5OewWrXiZ9+8rxmGjGGnTFih58LUDM0odk1AbszjF7zuYz2Fi9UAB1OGEsUHFe0D/5HS bm7wiIcG35WyY6zMEb7zx4vjnCHhvIywTJvlob6f7XrUdUHzkmYl6a6y67+SiDt/BSKz IGhIoXyOa4J8uqVWCmY491PN0QsV+CiiQZYkoveLDjUAUCACY7fut9GLa3FWBfwrNM1+ HB1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1iLdrhlU; 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 t24si28398767pgu.221.2019.07.29.12.46.21; Mon, 29 Jul 2019 12:46:36 -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=1iLdrhlU; 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 S2389573AbfG2TpN (ORCPT + 99 others); Mon, 29 Jul 2019 15:45:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:33920 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389905AbfG2TpI (ORCPT ); Mon, 29 Jul 2019 15:45:08 -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 4F3DA20C01; Mon, 29 Jul 2019 19:45:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564429507; bh=RZdOQBgOVa+INT8RKCIJ+QGpFkoab41V+bkvHbBKjfo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1iLdrhlU82p39ATzWWV6tWQmUmW525b+kPiOuPi2exS+Qi0rMaDucDJ62YZbNMwMb epCTbGcNA1bi1pQHP9Jvhw/6fS8ULTNbhAF61Wuk+XC8iKddjpd1Utmqi3heMOiXhK U1eClSAOzH6BAPIUEsFJXz780DAGoVnTZBnZbTRs= 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.19 081/113] block/bio-integrity: fix a memory leak bug Date: Mon, 29 Jul 2019 21:22:48 +0200 Message-Id: <20190729190714.983355258@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190729190655.455345569@linuxfoundation.org> References: <20190729190655.455345569@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 67b5fb861a51..5bd90cd4b51e 100644 --- a/block/bio-integrity.c +++ b/block/bio-integrity.c @@ -291,8 +291,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