Linux s390 Architecture development
 help / color / mirror / Atom feed
From: Yige Jiang <yigejiang86@gmail.com>
To: Harald Freudenberger <freude@linux.ibm.com>,
	Holger Dengler <dengler@linux.ibm.com>
Cc: Yige Jiang <yigejiang86@gmail.com>,
	Heiko Carstens <hca@linux.ibm.com>,
	Vasily Gorbik <gor@linux.ibm.com>,
	Alexander Gordeev <agordeev@linux.ibm.com>,
	Christian Borntraeger <borntraeger@linux.ibm.com>,
	Sven Schnelle <svens@linux.ibm.com>,
	linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: [PATCH] s390/zcrypt: Put the opened zcdn device in zcrypt_release()
Date: Thu,  3 Dec 2026 14:27:50 +0800	[thread overview]
Message-ID: <20261203032056.db46df7057fc.zcrypt-zcdn@gmail.com> (raw)

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

             reply	other threads:[~2026-12-03  6:27 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03  6:27 Yige Jiang [this message]
2026-12-03  6:37 ` [PATCH] s390/zcrypt: Put the opened zcdn device in zcrypt_release() sashiko-bot

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=20261203032056.db46df7057fc.zcrypt-zcdn@gmail.com \
    --to=yigejiang86@gmail.com \
    --cc=agordeev@linux.ibm.com \
    --cc=borntraeger@linux.ibm.com \
    --cc=dengler@linux.ibm.com \
    --cc=freude@linux.ibm.com \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=svens@linux.ibm.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