lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-ID: <e549c508-b3a2-4cba-b5ec-1a113286981c@web.de>
Date: Tue, 24 Sep 2024 18:18:05 +0200
From: Markus Elfring <Markus.Elfring@....de>
To: linux-s390@...r.kernel.org, Alexander Gordeev <agordeev@...ux.ibm.com>,
 Christian Bornträger <borntraeger@...ux.ibm.com>,
 Harald Freudenberger <freude@...ux.ibm.com>,
 Heiko Carstens <hca@...ux.ibm.com>, Holger Dengler <dengler@...ux.ibm.com>,
 Ingo Franzki <ifranzki@...ux.ibm.com>, Jules Irenge <jbi.octave@...il.com>,
 Sven Schnelle <svens@...ux.ibm.com>, Vasily Gorbik <gor@...ux.ibm.com>
Cc: LKML <linux-kernel@...r.kernel.org>, kernel-janitors@...r.kernel.org
Subject: [PATCH] s390/pkey: Use common error handling code in
 pkey_ioctl_kblob2protk3()

From: Markus Elfring <elfring@...rs.sourceforge.net>
Date: Tue, 24 Sep 2024 18:04:56 +0200

Add jump targets so that a bit of exception handling can be better reused
at the end of this function implementation.

Signed-off-by: Markus Elfring <elfring@...rs.sourceforge.net>
---
 drivers/s390/crypto/pkey_api.c | 31 +++++++++++++++++++------------
 1 file changed, 19 insertions(+), 12 deletions(-)

diff --git a/drivers/s390/crypto/pkey_api.c b/drivers/s390/crypto/pkey_api.c
index c20251e00cf9..78be7a633bf1 100644
--- a/drivers/s390/crypto/pkey_api.c
+++ b/drivers/s390/crypto/pkey_api.c
@@ -668,32 +668,31 @@ static int pkey_ioctl_kblob2protk3(struct pkey_kblob2pkey3 __user *utp)
 		return PTR_ERR(apqns);
 	kkey = _copy_key_from_user(ktp.key, ktp.keylen);
 	if (IS_ERR(kkey)) {
-		kfree(apqns);
-		return PTR_ERR(kkey);
+		rc = PTR_ERR(kkey);
+		goto free_apqns;
 	}
 	protkey = kmalloc(protkeylen, GFP_KERNEL);
 	if (!protkey) {
-		kfree(apqns);
 		kfree_sensitive(kkey);
-		return -ENOMEM;
+		rc = -ENOMEM;
+		goto free_apqns;
 	}
 	rc = key2protkey(apqns, ktp.apqn_entries, kkey, ktp.keylen,
 			 protkey, &protkeylen, &ktp.pkeytype);
 	pr_debug("key2protkey()=%d\n", rc);
 	kfree(apqns);
 	kfree_sensitive(kkey);
-	if (rc) {
-		kfree_sensitive(protkey);
-		return rc;
-	}
+	if (rc)
+		goto free_protkey;
+
 	if (ktp.pkey && ktp.pkeylen) {
 		if (protkeylen > ktp.pkeylen) {
-			kfree_sensitive(protkey);
-			return -EINVAL;
+			rc = -EINVAL;
+			goto free_protkey;
 		}
 		if (copy_to_user(ktp.pkey, protkey, protkeylen)) {
-			kfree_sensitive(protkey);
-			return -EFAULT;
+			rc = -EFAULT;
+			goto free_protkey;
 		}
 	}
 	kfree_sensitive(protkey);
@@ -702,6 +701,14 @@ static int pkey_ioctl_kblob2protk3(struct pkey_kblob2pkey3 __user *utp)
 		return -EFAULT;

 	return 0;
+
+free_apqns:
+	kfree(apqns);
+	return rc;
+
+free_protkey:
+	kfree_sensitive(protkey);
+	return rc;
 }

 static long pkey_unlocked_ioctl(struct file *filp, unsigned int cmd,
--
2.46.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ