Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3128918ybi; Thu, 18 Jul 2019 21:35:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqwfOJ7cqcpladK4/ebbMNqm8grZbJinmIIVveAJWRsIxKlliXWf55EhZQltg2kC9HOdQt8N X-Received: by 2002:a17:902:9a06:: with SMTP id v6mr53167746plp.71.1563510936000; Thu, 18 Jul 2019 21:35:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563510935; cv=none; d=google.com; s=arc-20160816; b=hyEKVk0H5AwgYt+av+KMgbdcaIQNUuF7EMfMsMyi3ewQLlEB3RKnzxYfJjXR2kMd70 RnIKHAhmwn0Z0QuERilw/D8w35cgLBeuCZGgqHsF27DRvvUiRK2iltonfUo6iwnLqWFS t1vjYZ0s5qJS7QTGSIZASBaXA228QRtRVIpx+qCtoGuz5lk+L0CAWUGansC+/ErzvBEK ESp5rZ/LnL245tUDFg3npkxi3yRwJBMsXq7R6V8nozy+M6jWJZK0wT3MgBntSglrn/6G nlhuazUtXwJPvl3aOMxqpECMcpBG59Gt1aJF1GXBJ6BqdGc7hyN0QifpzmIWV8A1d5rG FWKQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=w5yYoxrcsm+rZI24eiMqgerWqBNWJRPzICKuvBZY3H4=; b=hK4XSLU9BulDWpU9sIvRn2guLyrtGvi6fgVffooKZA+7cySAgYb81HKgxAJ3l4EiJW 8dTzVJLxWvz//x6wegQlhXCdU0XC9FQISOpW4U98zn0gW2/8hCsEzo+L0M1mRTZRk+yb 1FAekpM3SJ5q+NwtVtZoFDEbDNs//bDojtExTb2yF3JALfdNcc5suJGBJU7urj0YyBPp FWmAnLhH3pbIji7DPE36OdfW/nMX54Jeq+WjCOOARJpYmuB6diWySFPKY4F5I2bs/rpM Pyw3VJoaAkOIsnXUGLpVCWR6gGLg3cCaP+oRXayXE0dxIGryLEEYNsO7ORgSo2kVkhMo 3jYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=cDJ7rwrs; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n123si3525205pgn.151.2019.07.18.21.35.20; Thu, 18 Jul 2019 21:35:35 -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=cDJ7rwrs; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728951AbfGSECB (ORCPT + 99 others); Fri, 19 Jul 2019 00:02:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:33546 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729659AbfGSEBs (ORCPT ); Fri, 19 Jul 2019 00:01:48 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7FB4721873; Fri, 19 Jul 2019 04:01:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563508907; bh=nMJglynZyLcYk9zCBzECY9j3OAE04HiIgAINB5zkQ5E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cDJ7rwrsvyEikFpzH964XvPV6286BOJyYL3xn8IWiTG3XTB0V4Lb2JtzEGAfS8DOd 670k1jWzxP9WDp2+fIiC9Yf/HhrlGeEce3QOeKa/fjlNaXLqvfpoR5tbummoIzhRT2 dsS8qM2Kgg55axbNpDOENZDwz5pJryBhs9LztxCw= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Wenwen Wang , Ming Lei , "Martin K . Petersen" , Jens Axboe , Sasha Levin , linux-block@vger.kernel.org Subject: [PATCH AUTOSEL 5.2 152/171] block/bio-integrity: fix a memory leak bug Date: Thu, 18 Jul 2019 23:56:23 -0400 Message-Id: <20190719035643.14300-152-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190719035643.14300-1-sashal@kernel.org> References: <20190719035643.14300-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Wenwen Wang [ 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