[PATCH v2] dm-inlinecrypt: Fix some error handling paths in inlinecrypt_ctr()

Christophe JAILLET <[email protected]>
Newsgroups dev.linux.lists.dm-devel,org.kernel.vger.kernel-janitors,org.kernel.vger.linux-kernel
Message-ID <714aaad163237e33157408c31c4b71796d20c133.1782020965.git.christophe.jaillet@wanadoo.fr>
All error handling paths, except these ones, branch to the 'bad' label in
the error handling path.

If not done, there is a memory leak and some sensitive data may be kept
around.

So, fix these error handling paths and also do the needed clean-up.

Fixes: e7f57d2c47e2 ("dm-inlinecrypt: add target for inline block device encryption")
Signed-off-by: Christophe JAILLET <[email protected]>
Reviewed-by: Eric Biggers <[email protected]>
---
Compile tested only

Changes in v2:
  - Fix another missing goto   [Eric Biggers]
  - Add R-b tag (received privately)

v1: https://lore.kernel.org/all/2b6e6b71e66fbe90c75791669a9e16a36b48f7f6.1781983971.git.christophe.jaillet@wanadoo.fr/
---
 drivers/md/dm-inlinecrypt.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/md/dm-inlinecrypt.c b/drivers/md/dm-inlinecrypt.c
index be1b4aa8f28b..41293c18d10f 100644
--- a/drivers/md/dm-inlinecrypt.c
+++ b/drivers/md/dm-inlinecrypt.c
@@ -347,7 +347,8 @@ static int inlinecrypt_ctr(struct dm_target *ti, unsigned int argc, char **argv)
 	err = get_key_size(&argv[1]);
 	if (err < 0) {
 		ti->error = "Cannot parse key size";
-		return -EINVAL;
+		err = -EINVAL;
+		goto bad;
 	}
 	ctx->key_size = err;
 
@@ -398,6 +399,7 @@ static int inlinecrypt_ctr(struct dm_target *ti, unsigned int argc, char **argv)
 	if (ctx->iv_offset & ((ctx->sector_size >> SECTOR_SHIFT) - 1)) {
 		ti->error = "Wrong alignment of iv_offset sector";
 		err = -EINVAL;
+		goto bad;
 	}
 
 	ctx->max_dun = (ctx->iv_offset + ti->len - 1) >>
-- 
2.54.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.