The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Ethan Tidmore <ethantidmore06@gmail.com>
To: Alasdair Kergon <agk@redhat.com>,
	Mike Snitzer <snitzer@kernel.org>,
	Mikulas Patocka <mpatocka@redhat.com>,
	Benjamin Marzinski <bmarzins@redhat.com>
Cc: Eric Biggers <ebiggers@google.com>,
	Linlin Zhang <linlin.zhang@oss.qualcomm.com>,
	dm-devel@lists.linux.dev, linux-kernel@vger.kernel.org,
	Ethan Tidmore <ethantidmore06@gmail.com>
Subject: [PATCH] dm-inlinecrypt: Fix signedness bug
Date: Thu,  7 May 2026 21:37:16 -0500	[thread overview]
Message-ID: <20260508023716.668783-1-ethantidmore06@gmail.com> (raw)

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 <ethantidmore06@gmail.com>
---
 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


             reply	other threads:[~2026-05-08  2:37 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-08  2:37 Ethan Tidmore [this message]
2026-05-11 11:15 ` [PATCH] dm-inlinecrypt: Fix signedness bug Mikulas Patocka

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260508023716.668783-1-ethantidmore06@gmail.com \
    --to=ethantidmore06@gmail.com \
    --cc=agk@redhat.com \
    --cc=bmarzins@redhat.com \
    --cc=dm-devel@lists.linux.dev \
    --cc=ebiggers@google.com \
    --cc=linlin.zhang@oss.qualcomm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mpatocka@redhat.com \
    --cc=snitzer@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox