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

Eric Biggers <[email protected]> Sat, 20 Jun 2026 14:23:19 -0700
Newsgroups org.kernel.vger.kernel-janitors,dev.linux.lists.dm-devel,org.kernel.vger.linux-kernel
Message-ID <20260620212319.GA1702@quark>
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 <[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;

Reviewed-by: Eric Biggers <[email protected]>

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;
	}