Re: [PATCH] dm-inlinecrypt: Fix signedness bug

Mikulas Patocka <[email protected]>
Newsgroups dev.linux.lists.dm-devel,org.kernel.vger.linux-kernel
Message-ID <[email protected]>
Hi

Thanks. I merged this into the existing commit.

Mikulas


On Thu, 7 May 2026, Ethan Tidmore wrote:

> The function get_key_size() returns negative error codes and
> ctx->key_size is an unsigned integer, so the check (ctx->key_size < 0)
> is always impossible
> 
> Assign get_key_size() return value to err, check for error code, then
> assign ctx->key_size to err.
> 
> Detected by Smatch:
> drivers/md/dm-inlinecrypt.c:329 inlinecrypt_ctr()
> warn: unsigned 'ctx->key_size' is never less than zero.
> 
> Fixes: 753450f716417 ("dm-inlinecrypt: add target for inline block device encryption")
> Signed-off-by: Ethan Tidmore <[email protected]>
> ---
>  drivers/md/dm-inlinecrypt.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/md/dm-inlinecrypt.c b/drivers/md/dm-inlinecrypt.c
> index 6f804f5a4be6..40d48ba73e23 100644
> --- a/drivers/md/dm-inlinecrypt.c
> +++ b/drivers/md/dm-inlinecrypt.c
> @@ -325,11 +325,13 @@ static int inlinecrypt_ctr(struct dm_target *ti, unsigned int argc, char **argv)
>  	}
>  
>  	/* <key> */
> -	ctx->key_size = get_key_size(&argv[1]);
> -	if (ctx->key_size < 0) {
> +	err = get_key_size(&argv[1]);
> +	if (err < 0) {
>  		ti->error = "Cannot parse key size";
>  		return -EINVAL;
>  	}
> +	ctx->key_size = err;
> +
>  	err = inlinecrypt_get_key(argv[1], raw_key, ctx->key_size);
>  	if (err) {
>  		ti->error = "Malformed key string";
> -- 
> 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.