public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] dm crypt: fix memory leak in dm_crypt_integrity_io_alloc() error path
@ 2019-02-16 21:00 sultan
  2019-02-22 22:45 ` Mike Snitzer
  0 siblings, 1 reply; 2+ messages in thread
From: sultan @ 2019-02-16 21:00 UTC (permalink / raw)
  Cc: Sultan Alsawaf, Alasdair Kergon, Mike Snitzer, dm-devel,
	linux-kernel

From: Sultan Alsawaf <sultan@kerneltoast.com>

dm_crypt_integrity_io_alloc() allocates space for an integrity payload but
doesn't free it in the error path, leaking memory. Add a bio_integrity_free()
invocation upon error to fix the memory leak.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
---
 drivers/md/dm-crypt.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c
index dd538e6b2..f731e1fe0 100644
--- a/drivers/md/dm-crypt.c
+++ b/drivers/md/dm-crypt.c
@@ -939,8 +939,10 @@ static int dm_crypt_integrity_io_alloc(struct dm_crypt_io *io, struct bio *bio)
 
 	ret = bio_integrity_add_page(bio, virt_to_page(io->integrity_metadata),
 				     tag_len, offset_in_page(io->integrity_metadata));
-	if (unlikely(ret != tag_len))
+	if (unlikely(ret != tag_len)) {
+		bio_integrity_free(bio);
 		return -ENOMEM;
+	}
 
 	return 0;
 }
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-02-22 22:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-02-16 21:00 [PATCH] dm crypt: fix memory leak in dm_crypt_integrity_io_alloc() error path sultan
2019-02-22 22:45 ` Mike Snitzer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox