[PATCH] dm-inlinecrypt: Fix an error handling path in inlinecrypt_ctr()

Christophe JAILLET <[email protected]> Sat, 20 Jun 2026 21:33:03 +0200
Newsgroups org.kernel.vger.kernel-janitors,dev.linux.lists.dm-devel,org.kernel.vger.linux-kernel
Message-ID <2b6e6b71e66fbe90c75791669a9e16a36b48f7f6.1781983971.git.christophe.jaillet@wanadoo.fr>
All error handling paths, except but this one, 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 this error path 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]>
---
Compile tested only
---
 drivers/md/dm-inlinecrypt.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/md/dm-inlinecrypt.c b/drivers/md/dm-inlinecrypt.c
index be1b4aa8f28b..bb4ded4757d1 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;
 
-- 
2.54.0