From: Thorsten Blum <thorsten.blum@linux.dev>
To: Alasdair Kergon <agk@redhat.com>,
Mike Snitzer <snitzer@kernel.org>,
Mikulas Patocka <mpatocka@redhat.com>,
Benjamin Marzinski <bmarzins@redhat.com>,
Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: Thorsten Blum <thorsten.blum@linux.dev>,
Mike Snitzer <snitzer@redhat.com>,
dm-devel@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: [PATCH] dm-crypt: Reject malformed raw keys in crypt_set_key()
Date: Thu, 13 Aug 2026 10:13:36 +0200 [thread overview]
Message-ID: <20260813081335.40282-3-thorsten.blum@linux.dev> (raw)
dm-crypt calculates the raw key size by dividing the hex string length
by two. If the string has an odd number of characters, the key size is
rounded down and hex2bin() only decodes complete byte pairs.
For example, a 33-character raw key string is malformed, but dm-crypt
treats it as a 16-byte key and ignores the last character.
Reject raw key strings whose length does not match the expected number
of hex characters. This restores the trailing character check that was
lost when the open-coded decoder was replaced with hex2bin().
Fixes: e944e03e336f ("dm crypt: replace custom implementation of hex2bin()")
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
drivers/md/dm-crypt.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c
index 608b617fb817..b7aa3d893303 100644
--- a/drivers/md/dm-crypt.c
+++ b/drivers/md/dm-crypt.c
@@ -2615,6 +2615,9 @@ static int crypt_set_key(struct crypt_config *cc, char *key)
kfree_sensitive(cc->key_string);
cc->key_string = NULL;
+ if (cc->key_size && key_string_len != cc->key_size * 2)
+ goto out;
+
/* Decode key from its hex representation. */
if (cc->key_size && hex2bin(cc->key, key, cc->key_size) < 0)
goto out;
next reply other threads:[~2026-08-13 8:14 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-13 8:13 Thorsten Blum [this message]
2026-08-13 20:39 ` [PATCH] dm-crypt: Reject malformed raw keys in crypt_set_key() Andy Shevchenko
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=20260813081335.40282-3-thorsten.blum@linux.dev \
--to=thorsten.blum@linux.dev \
--cc=agk@redhat.com \
--cc=andy.shevchenko@gmail.com \
--cc=bmarzins@redhat.com \
--cc=dm-devel@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=mpatocka@redhat.com \
--cc=snitzer@kernel.org \
--cc=snitzer@redhat.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.