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=1796404885; b=mqc2ATlohQ0HoS39GeqYyhzx3MJyyde6uYxrZP0Wx/BHX6PLhEq1B2gJacGv+Zkz7nJO JBW/N+9xJYCRRGP6UrV/zxg8vgdAXIUeVOi3RTLquclGzitmswOWg9sPnkg3owxv4nthS B7AunmGqAEMSQwRAqFkI9JfIpCIdxzOQnfNs5MjiUhwOtvvd1m3Q3slfiFVVncYCZe3GU Dl4lBGpn9qjdyHILoaNCBI1AB79A3nXbU2Q7W89ed9myHwLJY3Rnu8ihvcWXa7JQNntYg KrqSGYAcmkDg/aUlAyFyk4/l/P4Bp6DPNej2Mssel7SvrVok6KHLkgCFcGl13hR3TOQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796404885; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=M7FSdMPK+g/CAn3/xrcMvGuiYzzcEz66ROhpXjRlbag=; b=drhSoJ+EB3UodH2OIikmiuWmLkTYDh3XsQLk5usPPlBKHwtL8bIeMDsnTJa/cDz+8bfj DtmLsdX/rE8PR6DYRzS8B7YqB+NBE3JWYYBFKW18wRX4UxwUZwdw9Xw4/G4KU00ZfO6RK QK+ql1NIdLWGM9M8ch1WOYn91vOJKqdTQ5fUHctr5ViV1EfiuQBki80oOMAba6FfIq1TK emvzBDxjx99NG96YzDvuDXJnoUkShrk8+nOTIUmcldqA9+zHiyki2KH3hPWAumPCFn0Xn 9S/WjecQwpbC4uOErC1g3CAhpdxqPegVerSYGnNVxh3P3LDoRst3EHVdbXo0boa5C6A== 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=OVimRPdO; 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 74D1D606A680 for ; Fri, 4 Dec 2026 17:21:25 +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=OVimRPdO Received: by smtp.kernel.org (Postfix) with ESMTPSA id B8B561F0093B; Fri, 4 Dec 2026 17:21:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796404885; bh=M7FSdMPK+g/CAn3/xrcMvGuiYzzcEz66ROhpXjRlbag=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=OVimRPdOpB/jCLRG9ZZqsEo6tufSPb49x6++3gk067RZbGKI2rlE7/AyJRjY1/3r0 2lFUGDPDCO1MDJg7tiSJ/tKKNUbKYKnRUu5wB/6lgls44a59Q6g2960DruPGvwTtyQ 8Q6Q8NobUfbDbAF00SqK41WX/F9fKwKeNHV3bELfESwaZn/OGaDcOv4akOA8e04vWp 1rauXkm/aRLrmk9y+8cOpmLUNxUgSVF1Iw/D3zJwhZvxUgQ6xyQhlpp98pQZl+BjYs 3Isekq5YfN1p31rjVChxdpI4o/QHlV+lBLz9Ri7I+EAj9jAA/cZryyVXBTH6Yn0AiD nh6Hks7aRuVhA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v11 1/2] crypto: ti - Add support for SHA224/256/384/512 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-2-t-pratham@ti.com> References: <20261204164236.489112-1-t-pratham@ti.com> <20261204164236.489112-2-t-pratham@ti.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 17:21:24 +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 5 potential issues to consider: - [High] crypto: ti: re-registering hash_algs inflates statesize and cra_reqsize - [High] crypto: ti: unchecked 32-bit digestcnt overflow corrupts >=3D 4 GiB hashes - [Medium] crypto: ti - high-order kzalloc_objs() and double-zeroing in dthe_hash_run() - [Medium] crypto: ti: 10 ms busy-poll with sleep_us=3D0 in SCHED_FIFO engine kthreads - [Low] crypto: ti: dthev2: spurious CRYPTO_ALG_OPTIONAL_KEY on unkeyed SHA-2 algs -- commit 114a10ac679742bd6b521e9f3aec91e9406695f5 Author: T Pratham crypto: ti - Add support for SHA224/256/384/512 in DTHEv2 driver This commit adds SHA224, SHA256, SHA384, and SHA512 hashing engine support to the TI DTHEv2 crypto driver, splitting the crypto engine into separate AES and hash engine instances. > diff --git a/drivers/crypto/ti/dthev2-hash.c b/drivers/crypto/ti/dthev2-h= ash.c > new file mode 100644 > index 0000000000000..bc5931de55378 > --- /dev/null > +++ b/drivers/crypto/ti/dthev2-hash.c > @@ -0,0 +1,780 @@ [ ... ] > + /* Poll output ready status register */ > + if (!ret) > + ret =3D readl_relaxed_poll_timeout(sha_base_reg + DTHE_P_HASH_IRQSTATU= S, _status, > + (_status & DTHE_HASH_IRQSTATUS_OP_READY), > + 0, DTHE_POLL_TIMEOUT_INTERVAL); [Severity: Medium] Should this poll pass a non-zero sleep_us instead of busy-waiting for up to 10 ms inside a SCHED_FIFO kthread? Both hash_engine and aes_engine are created with crypto_engine_alloc_init(d= ev, 1), so dthe_hash_run_dma() and dthe_aead_read_tag() run at SCHED_FIFO priority. With DTHE_POLL_TIMEOUT_INTERVAL set to 10 * USEC_PER_MSEC and sleep_us =3D 0, a slow or stalled operation (or an AEAD DMA timeout, where dthe_aead_run() still calls dthe_aead_read_tag()) spins on the CPU for up to 10 ms, starving normal tasks, workqueues, and ksoftirqd. Since readl_relaxed_poll_timeout() reads the register before sleeping, a small non-zero sleep_us such as 10 us avoids extra latency when the status bit is already set while preventing multi-millisecond real-time spins. [ ... ] > + rctx->digestcnt =3D readl_relaxed(sha_base_reg + DTHE_P_HASH512_DIGEST_= COUNT); > + dthe_hash_flag_set(rctx, DTHE_HASH_FLAG_IDIGEST_AVAIL); [Severity: High] Can streaming 4 GiB or more silently overflow rctx->digestcnt and return a corrupted digest? DTHE_P_HASH512_DIGEST_COUNT and rctx->digestcnt are 32-bit byte counters, which dthe_hash_import() already enforces with a U32_MAX check. Neither dthe_hash_run() nor dthe_hash_run_dma() checks whether (u64)rctx->digestcnt + len_to_process exceeds U32_MAX, so a streamed message of 4 GiB or larger wraps the hardware counter modulo 2^32 and finalizes with the wrong length padding while returning 0. If a state exported at an exact 4 GiB boundary wraps to 0, dthe_hash_import= () also takes the early return for bytecnt =3D=3D 0 and silently resets the ha= sh to its initial state without restoring rctx->idigest. [ ... ] > + src =3D kzalloc_objs(*src, src_nents, GFP_KERNEL); > + if (!src) { > + ret =3D -ENOMEM; > + goto hash_buf_all; > + } > + > + sg_init_table(src, src_nents); [Severity: Medium] Can large multi-page scatterlists trigger costly high-order GFP_KERNEL allocations here, and does sg_init_table() redundantly zero the array a second time? For non-contiguous requests larger than 4 MB (over 1024 4 KB pages), kzalloc_objs() requests a high-order contiguous allocation inside the SCHED_FIFO hash_engine kthread, which can stall all queued hash requests in direct reclaim/compaction and fail with -ENOMEM under fragmentation since dthe_hash_run() has no software fallback. Switching to sg_alloc_table() and sg_free_table() avoids both the contiguous allocation and the double-zeroin= g, as dthe_copy_sg() and k3-udma already walk chained scatterlists with sg_next() and for_each_sg(). [ ... ] > + .cra_flags =3D CRYPTO_ALG_TYPE_AHASH | > + CRYPTO_ALG_ASYNC | > + CRYPTO_ALG_OPTIONAL_KEY | > + CRYPTO_ALG_KERN_DRIVER_ONLY | > + CRYPTO_ALG_ALLOCATES_MEMORY | > + CRYPTO_AHASH_ALG_BLOCK_ONLY, [Severity: Low] Why is CRYPTO_ALG_OPTIONAL_KEY set on the four unkeyed SHA-2 entries in hash_algs[] when none of them define a .setkey callback? CRYPTO_ALG_OPTIONAL_KEY is only for algorithms that provide a ->setkey() method with a default key; setting it here exposes a bogus flag to userspace via crypto_report_one() and would fail registration if ahash_prepare_alg() adds a consistency check. [ ... ] > +int dthe_register_hash_algs(void) > +{ > + return crypto_engine_register_ahashes(hash_algs, ARRAY_SIZE(hash_algs)); > +} > + > +void dthe_unregister_hash_algs(void) > +{ > + crypto_engine_unregister_ahashes(hash_algs, ARRAY_SIZE(hash_algs)); > +} [Severity: High] Does re-registering the static hash_algs[] array inflate statesize and cra_reqsize on every unbind/rebind? Because hash_algs[] sets CRYPTO_AHASH_ALG_BLOCK_ONLY, ahash_prepare_alg() adds cra_blocksize + 1 to both fields in place on every registration, and crypto_unregister_ahash() does not undo it: crypto/ahash.c:ahash_prepare_alg() { ... if (base->cra_flags & CRYPTO_AHASH_ALG_BLOCK_ONLY) { ... base->cra_reqsize +=3D base->cra_blocksize + 1; alg->halg.statesize +=3D base->cra_blocksize + 1; ... } After a single sysfs unbind/rebind (or probe retry after dthe_register_aes_algs() fails), sha512-dthev2 statesize grows from 209 to 338, so crypto_ahash_export() copies the partial block to offsets 209..337 while dthe_hash_export() only writes offsets 0..79. That leaves 129 bytes of uninitialized stack memory in ahash_do_req_chain()'s state buffer to be imported and hashed into the fallback digest, and a third rebind pushes statesize past HASH_MAX_STATESIZE (345) and breaks ahash_do_req_chain() with -ENOSYS. Probing a second DTHEv2 instance while one is bound also calls dthe_register_algs() unconditionally, which mutates the live hash_algs[] and runs INIT_LIST_HEAD(&alg->cra_users) in __crypto_register_alg() on the already-registered algorithm before returning -EEXIST. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204164236.4891= 12-1-t-pratham@ti.com?part=3D1