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

From: Eric Biggers

Date: Sat Jun 20 2026 - 17:23:35 EST


On Sat, Jun 20, 2026 at 09:33:03PM +0200, Christophe JAILLET wrote:
> 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 <christophe.jaillet@xxxxxxxxxx>
> ---
> 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;

Reviewed-by: Eric Biggers <ebiggers@xxxxxxxxxx>

The missing 'goto' below could use a patch too:

if (ctx->iv_offset & ((ctx->sector_size >> SECTOR_SHIFT) - 1)) {
ti->error = "Wrong alignment of iv_offset sector";
err = -EINVAL;
}