From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796406446; b=yoLarW9L4HEmnntS8FcOb5N8nvnEzM7GDBpsFPjov7U1mcbR5G1lEs+QYjwQBpsHa+0z 721PL/dZlFc87N6UrBn1r6nmq+Y296mEdI2b26MaosVD0nMVdcq//PM982iGhvZoXBKoM lHnxugBOfkdRAnbHdl1OPAyOZLTtDTvFO2ntsYsmpYqi4g6kipCoEPlIWdaIFq3CsUBxg KHW9kgrPKaXFXUlRba/T7XodsoYVov9U90Rr3Aj3UknoogZ4+oBckolRBohpZdDisyMAd G3Ji9I2xmqRJKE4dAY5VLnmrOizJBwDWCDwwhmgNrNlZiGhdWINeuK0FVgqA6mZyh/w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796406446; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=adlJN4J5w6D1DMYxYnhUvrnd32PtehnvVONobxz+J6s=; b=2JqZkK41tzkXVsH9RW0+Fj0xu8fgXgvULcWqZi8DRfz4JPAW6q7GyHd9+QhjVoNjxo9/ 1i2Rw4Xus51OPPLAdqL8NQ9hhOeZReV+oFQS28lZO2+b/pC1Ba65cxnsguEWju0KAW/i7 wELpWTo6R1OLjm5rzYsgtxJAaYRIkb0AvmdfvfY918QO6JS+pW7FafaAL17+tfvnIwrz4 my5ti7scjL0BWVkKdgwk+W/Z8RMeYlH/MWkVLB1q3/RNfi6c+pgEb54GAzWHmhm3oUstq XAmfxCQTqhEBN0fDWoHND5uJtK1bJ/LAa6c459Ht/uiRz0RgjowdCXbpX9h4Q5VA1sA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=WYB2fmVp; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 408B7606A322 for ; Fri, 4 Dec 2026 17:47:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=WYB2fmVp Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4537A1F0093B; Fri, 4 Dec 2026 17:47:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796406446; bh=adlJN4J5w6D1DMYxYnhUvrnd32PtehnvVONobxz+J6s=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=WYB2fmVpu0gMn9c03msHQzwJKBRSnRfh14pBXckZWty8XwDjWASmNGVIQd754659O 9F9ZsigENmA4tlcXGDScsJ+PojaLEmLzjs8UYNcvNJPGBwqQ+Z+bhhh4y0YspUNQWZ lFs/mmUt7LfCKEjEh8iKoBYJ/KUYxN1KXISwp5uNJGIk28cxKNZ85NfjoiNNA4mSoV S2EkDtHLfZAVJbc0KXIHowOHD2VVciUooDpN8t4y8V7qz60weLWGrQQi0XCM5Jt7l2 OKLeAwLb7jiq/U4eGXCTgpI4VJFxHVWGnZ7fncuVyykDZkqx5kNI56H33qiY99+S4A 4I8A9r1y/rGLQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v11 2/2] crypto: ti - Add support for HMAC in DTHEv2 driver Reply-To: sashiko-reviews@lists.linux.dev To: "T Pratham" , "Herbert Xu" , "David S. Miller" Cc: "Sebin Francis" , "Manorit Chawdhry" , "Vishal Mahaveer" , "Praneeth Bajjuri" , linux-crypto@vger.kernel.org In-Reply-To: <20261204164236.489112-3-t-pratham@ti.com> References: <20261204164236.489112-1-t-pratham@ti.com> <20261204164236.489112-3-t-pratham@ti.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 17:47:23 +0000 X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 4 potential issues to consider: - [High] crypto: ti: HMAC key preprocess timeout clobbers aliased key before fallback - [Medium] crypto: ti: unnecessary synchronous engine round-trip in dthe_hmac_setkey() - [Medium] crypto: ti: unchecked 32-bit digestcnt wraparound on >=3D 4 GiB hash/HMAC inputs - [Medium] crypto: ti: missing SYSCONFIG setup in dthe_hmac_run_key_preprocess() -- commit 4ec372e68a21e24f2a8b0d6b5d5729e1692ea3c5 Author: T Pratham crypto: ti - Add support for HMAC in DTHEv2 driver This commit adds HMAC-SHA224/256/384/512 support to the TI DTHEv2 hashing engine driver, including hardware and software key preprocessing, state export/import handling, and algorithm registration. > diff --git a/drivers/crypto/ti/dthev2-hash.c b/drivers/crypto/ti/dthev2-h= ash.c > index bc5931de55378..12cfebf251628 100644 > --- a/drivers/crypto/ti/dthev2-hash.c > +++ b/drivers/crypto/ti/dthev2-hash.c [ ... ] > @@ -349,6 +375,47 @@ static int dthe_hash_run_dma(struct ahash_request *r= eq, struct scatterlist *src, > return ret; > } > =20 > +static int dthe_hmac_run_key_preprocess(struct crypto_ahash *tfm, struct= dthe_hash_req_ctx *rctx) > +{ > + struct dthe_data *dev_data =3D rctx->dev_data; > + struct dthe_hash_tfm_ctx *ctx =3D crypto_ahash_ctx(tfm); > + u32 hash_mode =3D ctx->hash_mode | DTHE_HASH_MODE_HMAC_KEY_PROCESSING; > + void __iomem *sha_base_reg =3D dev_data->regs + DTHE_P_HASH_BASE; > + u32 _status; > + int ret; > + > + for (int i =3D 0; i < (ctx->keylen / 2) / sizeof(u32); ++i) > + writel_relaxed(ctx->key[i], sha_base_reg + > + DTHE_P_HASH512_ODIGEST_A + > + (DTHE_REG_SIZE * i)); > + for (int i =3D 0; i < (ctx->keylen / 2) / sizeof(u32); ++i) > + writel_relaxed(ctx->key[i + (ctx->keylen / 2) / sizeof(u32)], > + sha_base_reg + > + DTHE_P_HASH512_IDIGEST_A + > + (DTHE_REG_SIZE * i)); > + writel_relaxed(hash_mode, sha_base_reg + DTHE_P_HASH512_MODE); > + writel_relaxed(0, sha_base_reg + DTHE_P_HASH512_LENGTH); > + > + ret =3D readl_relaxed_poll_timeout(sha_base_reg + DTHE_P_HASH_IRQSTATUS= , _status, > + (_status & DTHE_HASH_IRQSTATUS_OP_READY), > + 0, DTHE_POLL_TIMEOUT_INTERVAL); [Severity: Medium] Should dthe_hmac_run_key_preprocess() configure DTHE_P_HASH_SYSCONFIG and DTHE_P_HASH_IRQENABLE before triggering key preprocessing and polling DTHE_P_HASH_IRQSTATUS? dthe_probe() never initializes those registers, so an HMAC setkey() before any DMA hash leaves them at reset defaults. After a DMA hash, dthe_hash_run_dma() leaves DTHE_HASH_SYSCONFIG_DMA_EN set during this register-only operation. By contrast, the sibling EIP-57 driver in drivers/crypto/omap-sham.c (omap_sham_write_ctrl_omap4()) explicitly configures SHA_REG_IRQENA and clears DMA_EN for non-DMA operations. > + > + for (int i =3D 0; i < ctx->idigest_size / sizeof(u32); ++i) > + ctx->istate[i] =3D readl_relaxed(sha_base_reg + > + DTHE_P_HASH512_IDIGEST_A + > + (DTHE_REG_SIZE * i)); > + > + for (int i =3D 0; i < ctx->idigest_size / sizeof(u32); ++i) > + ctx->ostate[i] =3D readl_relaxed(sha_base_reg + > + DTHE_P_HASH512_ODIGEST_A + > + (DTHE_REG_SIZE * i)); > + > + /* Need to read this to trigger completion */ > + rctx->digestcnt =3D readl_relaxed(sha_base_reg + DTHE_P_HASH512_DIGEST_= COUNT); > + > + return ret; > +} [Severity: High] Does a timeout in readl_relaxed_poll_timeout() clobber ctx->key before the software fallback runs? In struct dthe_hash_tfm_ctx, ctx->istate and ctx->ostate share a union with ctx->key. Because these loops write into ctx->istate and ctx->ostate even when ret is -ETIMEDOUT, dthe_hmac_setkey() then calls dthe_hmac_preparekey_sw(ctx) on corrupted key bytes and returns 0. Subsequent hardware HMAC operations will silently compute invalid tags and disagree with crypto_ahash_fb(tfm), which received the original key. On error, the registers should be drained into a scratch variable instead of overwriting ctx->istate and ctx->ostate (or key should not alias them). [ ... ] > @@ -552,14 +627,20 @@ static int dthe_hash_import(struct ahash_request *r= eq, const void *in) > return -EOVERFLOW; > if (bytecnt > U32_MAX) > return -EOVERFLOW; > - if (bytecnt % bs) > + if (bytecnt < freshcnt || bytecnt % bs) > return -EINVAL; > =20 > rctx->flags =3D 0; > rctx->digestcnt =3D bytecnt; > =20 > - if (bytecnt =3D=3D 0) > + if (bytecnt =3D=3D freshcnt) { > + if (ctx->keylen > 0) { > + dthe_hash_state_from_sw(ctx, in, rctx->idigest); > + if (memcmp(rctx->idigest, ctx->istate, ctx->idigest_size)) > + return -EINVAL; > + } > return 0; > + } > =20 > dthe_hash_state_from_sw(ctx, in, rctx->idigest); > dthe_hash_flag_set(rctx, DTHE_HASH_FLAG_IDIGEST_AVAIL); > @@ -569,10 +650,12 @@ static int dthe_hash_init(struct ahash_request *req) > { > + struct crypto_ahash *tfm =3D crypto_ahash_reqtfm(req); > struct dthe_hash_req_ctx *rctx =3D ahash_request_ctx_dma(req); > + struct dthe_hash_tfm_ctx *ctx =3D crypto_ahash_ctx(tfm); > =20 > rctx->flags =3D 0; > - rctx->digestcnt =3D 0; > + rctx->digestcnt =3D (ctx->keylen > 0) ? crypto_ahash_blocksize(tfm) : 0; > =20 > return 0; > } [Severity: Medium] Can streaming 4 GiB (or 4 GiB minus blocksize for HMAC) silently wrap the 32-bit rctx->digestcnt? dthe_hash_import() rejects bytecnt > U32_MAX with -EOVERFLOW, but none of dthe_hash_update(), dthe_hash_final(), dthe_hash_run(), or dthe_hash_run_dma() check whether (u64)rctx->digestcnt + len_to_process exceeds U32_MAX. When DTHE_P_HASH512_DIGEST_COUNT wraps modulo 2^32, finalization computes padding with the wrapped length and silently returns a wrong digest or HMAC tag, and re-importing an HMAC state that wrapped to 0 fails in dthe_hash_import() with -EINVAL. [ ... ] > +static int dthe_hmac_setkey(struct crypto_ahash *tfm, const u8 *key, > + unsigned int keylen) > +{ > + struct dthe_hash_tfm_ctx *ctx =3D crypto_ahash_ctx(tfm); > + u8 *k =3D (u8 *)ctx->key; > + unsigned int max_keysize; > + > + memzero_explicit(ctx->key, sizeof(ctx->key)); > + ctx->keylen =3D 0; > + > + switch (ctx->hash_mode) { > + case DTHE_HASH_SHA512: > + case DTHE_HASH_SHA384: > + max_keysize =3D DTHE_HMAC_SHA512_MAX_KEYSIZE; > + break; > + case DTHE_HASH_SHA256: > + case DTHE_HASH_SHA224: > + max_keysize =3D DTHE_HMAC_SHA256_MAX_KEYSIZE; > + break; > + default: > + return -EINVAL; > + } > + > + if (keylen <=3D max_keysize) > + memcpy(k, key, keylen); > + else if (ctx->hash_mode =3D=3D DTHE_HASH_SHA512) > + sha512(key, keylen, k); > + else if (ctx->hash_mode =3D=3D DTHE_HASH_SHA384) > + sha384(key, keylen, k); > + else if (ctx->hash_mode =3D=3D DTHE_HASH_SHA256) > + sha256(key, keylen, k); > + else > + sha224(key, keylen, k); > + > + ctx->keylen =3D max_keysize; > + > + if (dthe_hmac_preparekey_hw(tfm)) > + dthe_hmac_preparekey_sw(ctx); > + > + return 0; > +} [Severity: Medium] Is the synchronous hardware round-trip in dthe_hmac_preparekey_hw() needed here when dthe_hmac_preparekey_sw() already exists? Every HMAC setkey() allocates a dummy request, contends on dthe_dev_list.lock and hash_engine->queue_lock, blocks behind queued bulk DMA hash requests on the single hash_engine kthread, and busy-polls DTHE_P_HASH_IRQSTATUS for up to 10 ms just to compute two SHA blocks. Because the HMAC algorithms set CRYPTO_ALG_NEED_FALLBACK, crypto_ahash_setkey() unconditionally prepares the key in software on crypto_ahash_fb(tfm) right afterward anyway. Calling dthe_hmac_preparekey_sw() directly with the caller's key and keylen (since hmac_sha*_preparekey() already hashes oversized keys) would avoid the contention and latency while removing dthe_hmac_preparekey_hw(), dthe_hmac_run_key_preprocess(), and the ctx->key union. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204164236.4891= 12-1-t-pratham@ti.com?part=3D2