From: T Pratham <t-pratham@ti.com>
To: T Pratham <t-pratham@ti.com>,
Herbert Xu <herbert@gondor.apana.org.au>,
"David S. Miller" <davem@davemloft.net>
Cc: Mert Seftali <mertsftl@gmail.com>,
Sebin Francis <sebin.francis@ti.com>,
Manorit Chawdhry <m-chawdhry@ti.com>,
Vishal Mahaveer <vishalm@ti.com>,
Praneeth Bajjuri <praneeth@ti.com>,
kernel test robot <lkp@intel.com>,
"Dan Carpenter" <error27@gmail.com>,
<linux-crypto@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: [PATCH 1/5] crypto: ti - Use list_first_entry_or_null() in dthe_get_dev()
Date: Thu, 27 Aug 2026 16:27:07 +0530 [thread overview]
Message-ID: <20260827105711.527182-2-t-pratham@ti.com> (raw)
In-Reply-To: <20260827105711.527182-1-t-pratham@ti.com>
From: Mert Seftali <mertsftl@gmail.com>
dthe_get_dev() fetches a device from the global device list with
list_first_entry() and then checks the result for NULL. However,
list_first_entry() never returns NULL: on an empty list it returns a
bogus pointer computed from the list head. The NULL check is therefore
dead code, and an empty list would be treated as a valid entry and
moved around as if it were a real device.
Use list_first_entry_or_null() so the existing NULL check works as
intended and an empty list is handled gracefully.
[pratham:]
Add null checks on dev_data in callers of dthe_get_dev().
Fixes: 52f641bc63a4 ("crypto: ti - Add driver for DTHE V2 AES Engine (ECB, CBC)")
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <error27@gmail.com>
Closes: https://lore.kernel.org/r/202606111933.69GGTKxr-lkp@intel.com/
Signed-off-by: Mert Seftali <mertsftl@gmail.com>
Co-developed-by: T Pratham <t-pratham@ti.com>
Signed-off-by: T Pratham <t-pratham@ti.com>
---
drivers/crypto/ti/dthev2-aes.c | 9 +++++++++
drivers/crypto/ti/dthev2-common.c | 2 +-
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/drivers/crypto/ti/dthev2-aes.c b/drivers/crypto/ti/dthev2-aes.c
index eb5cd902dfb59..c025b08c49930 100644
--- a/drivers/crypto/ti/dthev2-aes.c
+++ b/drivers/crypto/ti/dthev2-aes.c
@@ -112,6 +112,9 @@ static int dthe_cipher_init_tfm(struct crypto_skcipher *tfm)
struct dthe_tfm_ctx *ctx = crypto_skcipher_ctx(tfm);
struct dthe_data *dev_data = dthe_get_dev(ctx);
+ if (!dev_data)
+ return -ENODEV;
+
ctx->dev_data = dev_data;
ctx->keylen = 0;
@@ -124,6 +127,9 @@ static int dthe_cipher_init_tfm_fallback(struct crypto_skcipher *tfm)
struct dthe_data *dev_data = dthe_get_dev(ctx);
const char *alg_name = crypto_tfm_alg_name(crypto_skcipher_tfm(tfm));
+ if (!dev_data)
+ return -ENODEV;
+
ctx->dev_data = dev_data;
ctx->keylen = 0;
@@ -572,6 +578,9 @@ static int dthe_aead_init_tfm(struct crypto_aead *tfm)
struct dthe_tfm_ctx *ctx = crypto_aead_ctx(tfm);
struct dthe_data *dev_data = dthe_get_dev(ctx);
+ if (!dev_data)
+ return -ENODEV;
+
ctx->dev_data = dev_data;
const char *alg_name = crypto_tfm_alg_name(crypto_aead_tfm(tfm));
diff --git a/drivers/crypto/ti/dthev2-common.c b/drivers/crypto/ti/dthev2-common.c
index a2ad79bec105a..cc02449382673 100644
--- a/drivers/crypto/ti/dthev2-common.c
+++ b/drivers/crypto/ti/dthev2-common.c
@@ -40,7 +40,7 @@ struct dthe_data *dthe_get_dev(struct dthe_tfm_ctx *ctx)
return ctx->dev_data;
spin_lock_bh(&dthe_dev_list.lock);
- dev_data = list_first_entry(&dthe_dev_list.dev_list, struct dthe_data, list);
+ dev_data = list_first_entry_or_null(&dthe_dev_list.dev_list, struct dthe_data, list);
if (dev_data)
list_move_tail(&dev_data->list, &dthe_dev_list.dev_list);
spin_unlock_bh(&dthe_dev_list.lock);
--
2.34.1
next prev parent reply other threads:[~2026-08-27 10:58 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-27 10:57 [PATCH 0/5] Fix several issues in DTHEv2 driver T Pratham
2026-08-27 10:57 ` T Pratham [this message]
2026-08-27 10:57 ` [PATCH 2/5] crypto: ti - Fix potential deadlock and allocation bugs in DTHEv2 T Pratham
2026-08-27 10:57 ` [PATCH 3/5] crypto: ti - Fix potential memory corruption on highmem pages T Pratham
2026-08-27 10:57 ` [PATCH 4/5] crypto: ti - Trim scatterlists to correct length in AES T Pratham
2026-08-27 10:57 ` [PATCH 5/5] crypto: ti - Fix use-after-free of dev_data on DTHEv2 driver removal T Pratham
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=20260827105711.527182-2-t-pratham@ti.com \
--to=t-pratham@ti.com \
--cc=davem@davemloft.net \
--cc=error27@gmail.com \
--cc=herbert@gondor.apana.org.au \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lkp@intel.com \
--cc=m-chawdhry@ti.com \
--cc=mertsftl@gmail.com \
--cc=praneeth@ti.com \
--cc=sebin.francis@ti.com \
--cc=vishalm@ti.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox