From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F29F01A6827; Mon, 4 May 2026 14:16:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777904219; cv=none; b=SYzJLNdqh4EsSPe+igynJMLIveWlzDKX0d4sS5LbAB705R0geHdAEDcF6Y/+kkWXkGXefMXzIpICgxieZmdjabNunKNjDy9mr9G3fX6DtuLwFyKthT8TNX86H4af3zRyCgG/ZLq8iTviOWShqjYkugmExFJ3MzWBw215M/75f1I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777904219; c=relaxed/simple; bh=gH0WOQUKQJUhZ9/YtK947YTsDf7Gx3Bt9oZBv+bc1Sw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gIOVg+7/W+FuczJx6hmMDYFTe8D/q4jhiB1pVwT+iZ9AxSG6Gc7EBu6G5gL7KPnOsLuVcmkt8ko45MN8ut9i1E2wLwkvoyn2PxYEnFNthWm/q6SPOcheARUnKGfzBxQQnCqiKCqX/2oDPfZtcQRUunL0f6d7cOkgULKxtkmScpo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=FO+gw5rD; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="FO+gw5rD" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 48D5BC2BCB8; Mon, 4 May 2026 14:16:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1777904218; bh=gH0WOQUKQJUhZ9/YtK947YTsDf7Gx3Bt9oZBv+bc1Sw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FO+gw5rDDO2YurMFpEBrEXzqbIcmE2eYJ8+X3OzE4xayr6y03ce7l2KXmedsB39xd 82knJUWBYp5ZkvJSWTYOkJeFzURuWSuCJYDqSVlIdMnnCPmgb/C4N6C+mY9V7e4Egq 0eFzzPIxnBCt2hpbM892tzpmIF97GrbilMAn52lI= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Thorsten Blum , Herbert Xu Subject: [PATCH 6.18 228/275] crypto: atmel-sha204a - Fix potential UAF and memory leak in remove path Date: Mon, 4 May 2026 15:52:48 +0200 Message-ID: <20260504135151.531179940@linuxfoundation.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260504135142.929052779@linuxfoundation.org> References: <20260504135142.929052779@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Thorsten Blum commit bab1adf3b87e4bfac92c4f5963c63db434d561c1 upstream. Unregister the hwrng to prevent new ->read() calls and flush the Atmel I2C workqueue before teardown to prevent a potential UAF if a queued callback runs while the device is being removed. Drop the early return to ensure sysfs entries are removed and ->hwrng.priv is freed, preventing a memory leak. Fixes: da001fb651b0 ("crypto: atmel-i2c - add support for SHA204A random number generator") Cc: stable@vger.kernel.org Signed-off-by: Thorsten Blum Signed-off-by: Herbert Xu Signed-off-by: Greg Kroah-Hartman --- drivers/crypto/atmel-sha204a.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) --- a/drivers/crypto/atmel-sha204a.c +++ b/drivers/crypto/atmel-sha204a.c @@ -194,10 +194,8 @@ static void atmel_sha204a_remove(struct { struct atmel_i2c_client_priv *i2c_priv = i2c_get_clientdata(client); - if (atomic_read(&i2c_priv->tfm_count)) { - dev_emerg(&client->dev, "Device is busy, will remove it anyhow\n"); - return; - } + devm_hwrng_unregister(&client->dev, &i2c_priv->hwrng); + atmel_i2c_flush_queue(); sysfs_remove_group(&client->dev.kobj, &atmel_sha204a_groups);