* [PATCH] s390/zcrypt: Put the opened zcdn device in zcrypt_release()
@ 2026-12-03 6:27 Yige Jiang
2026-12-03 6:37 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Yige Jiang @ 2026-12-03 6:27 UTC (permalink / raw)
To: Harald Freudenberger, Holger Dengler
Cc: Yige Jiang, Heiko Carstens, Vasily Gorbik, Alexander Gordeev,
Christian Borntraeger, Sven Schnelle, linux-s390, linux-kernel,
stable
zcrypt_open() keeps the device reference returned by
find_zcdndev_by_devt() and stores a pointer to that device's permissions
in filp->private_data. zcrypt_release() instead looks the device up
again by its devt and drops two references on the result.
If the original zcdn device is destroyed while the file is open, the
lookup can find no device or a new device using the same minor. The
original reference then leaks. In the latter case the replacement
device also loses a reference it never handed out, which can cause
use-after-free when it is subsequently destroyed.
Recover the originally opened device from filp->private_data and put
only that device. The global ap_perms pointer identifies files for
which zcrypt_open() took no zcdn reference.
Fixes: 00fab2350e6b ("s390/zcrypt: multiple zcrypt device nodes support")
Cc: stable@vger.kernel.org
Signed-off-by: Yige Jiang <yigejiang86@gmail.com>
---
Based on s390 fixes as merged in next-20261201.
Compile-tested on next-20261104: s390x, GCC 14.2.0, W=1,
CONFIG_AP=y and CONFIG_ZCRYPT=m.
Baseline and patched objects built without warnings.
The code changes are the same as in that build.
No hardware or runtime test was performed.
drivers/s390/crypto/zcrypt_api.c | 17 +++++++----------
1 file changed, 7 insertions(+), 10 deletions(-)
diff --git a/drivers/s390/crypto/zcrypt_api.c b/drivers/s390/crypto/zcrypt_api.c
index 80435fd8e6ad6107a4d47a811b223b35eed5a160..ae3b4b4babec8eaf8e996ccdc3c1babae3074d9f 100644
--- a/drivers/s390/crypto/zcrypt_api.c
+++ b/drivers/s390/crypto/zcrypt_api.c
@@ -528,17 +528,14 @@ static int zcrypt_open(struct inode *inode, struct file *filp)
*/
static int zcrypt_release(struct inode *inode, struct file *filp)
{
- if (filp->f_inode->i_cdev == &zcrypt_cdev) {
- struct zcdn_device *zcdndev;
+ struct ap_perms *perms = filp->private_data;
- mutex_lock(&ap_attr_mutex);
- zcdndev = find_zcdndev_by_devt(filp->f_inode->i_rdev);
- mutex_unlock(&ap_attr_mutex);
- if (zcdndev) {
- /* 2 puts here: one for find, one for open */
- put_device(&zcdndev->device);
- put_device(&zcdndev->device);
- }
+ /* put the reference zcrypt_open() took on this zcdn device */
+ if (perms != &ap_perms) {
+ struct zcdn_device *zcdndev =
+ container_of(perms, struct zcdn_device, perms);
+
+ put_device(&zcdndev->device);
}
atomic_dec(&zcrypt_open_count);
base-commit: a07bc01bec2337151166442b15047b8861c4b23e
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] s390/zcrypt: Put the opened zcdn device in zcrypt_release()
2026-12-03 6:27 [PATCH] s390/zcrypt: Put the opened zcdn device in zcrypt_release() Yige Jiang
@ 2026-12-03 6:37 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-12-03 6:37 UTC (permalink / raw)
To: Yige Jiang
Cc: linux-s390, Heiko Carstens, Vasily Gorbik, Alexander Gordeev,
Christian Borntraeger
> zcrypt_open() keeps the device reference returned by
> find_zcdndev_by_devt() and stores a pointer to that device's permissions
> in filp->private_data. zcrypt_release() instead looks the device up
> again by its devt and drops two references on the result.
>
> If the original zcdn device is destroyed while the file is open, the
> lookup can find no device or a new device using the same minor. The
> original reference then leaks. In the latter case the replacement
> device also loses a reference it never handed out, which can cause
> use-after-free when it is subsequently destroyed.
>
> Recover the originally opened device from filp->private_data and put
> only that device. The global ap_perms pointer identifies files for
> which zcrypt_open() took no zcdn reference.
>
> Fixes: 00fab2350e6b ("s390/zcrypt: multiple zcrypt device nodes support")
> Cc: stable@vger.kernel.org
> Signed-off-by: Yige Jiang <yigejiang86@gmail.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203032056.db46df7057fc.zcrypt-zcdn@gmail.com?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-03 6:37 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 6:27 [PATCH] s390/zcrypt: Put the opened zcdn device in zcrypt_release() Yige Jiang
2026-12-03 6:37 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox