Unverified Commit c191ebe4 authored by openeuler-ci-bot's avatar openeuler-ci-bot Committed by Gitee
Browse files

!10720 v2 s390/pkey: Wipe copies of clear-key structures on failure

parents 43ba60c0 a5973099
Loading
Loading
Loading
Loading
+9 −7
Original line number Diff line number Diff line
@@ -1365,9 +1365,7 @@ static long pkey_unlocked_ioctl(struct file *filp, unsigned int cmd,
		rc = cca_clr2seckey(kcs.cardnr, kcs.domain, kcs.keytype,
				    kcs.clrkey.clrkey, kcs.seckey.seckey);
		DEBUG_DBG("%s cca_clr2seckey()=%d\n", __func__, rc);
		if (rc)
			break;
		if (copy_to_user(ucs, &kcs, sizeof(kcs)))
		if (!rc && copy_to_user(ucs, &kcs, sizeof(kcs)))
			rc = -EFAULT;
		memzero_explicit(&kcs, sizeof(kcs));
		break;
@@ -1399,9 +1397,7 @@ static long pkey_unlocked_ioctl(struct file *filp, unsigned int cmd,
				      kcp.protkey.protkey,
				      &kcp.protkey.len, &kcp.protkey.type);
		DEBUG_DBG("%s pkey_clr2protkey()=%d\n", __func__, rc);
		if (rc)
			break;
		if (copy_to_user(ucp, &kcp, sizeof(kcp)))
		if (!rc && copy_to_user(ucp, &kcp, sizeof(kcp)))
			rc = -EFAULT;
		memzero_explicit(&kcp, sizeof(kcp));
		break;
@@ -1549,11 +1545,14 @@ static long pkey_unlocked_ioctl(struct file *filp, unsigned int cmd,
		if (copy_from_user(&kcs, ucs, sizeof(kcs)))
			return -EFAULT;
		apqns = _copy_apqns_from_user(kcs.apqns, kcs.apqn_entries);
		if (IS_ERR(apqns))
		if (IS_ERR(apqns)) {
			memzero_explicit(&kcs, sizeof(kcs));
			return PTR_ERR(apqns);
		}
		kkey = kzalloc(klen, GFP_KERNEL);
		if (!kkey) {
			kfree(apqns);
			memzero_explicit(&kcs, sizeof(kcs));
			return -ENOMEM;
		}
		rc = pkey_clr2seckey2(apqns, kcs.apqn_entries,
@@ -1563,15 +1562,18 @@ static long pkey_unlocked_ioctl(struct file *filp, unsigned int cmd,
		kfree(apqns);
		if (rc) {
			kfree_sensitive(kkey);
			memzero_explicit(&kcs, sizeof(kcs));
			break;
		}
		if (kcs.key) {
			if (kcs.keylen < klen) {
				kfree_sensitive(kkey);
				memzero_explicit(&kcs, sizeof(kcs));
				return -EINVAL;
			}
			if (copy_to_user(kcs.key, kkey, klen)) {
				kfree_sensitive(kkey);
				memzero_explicit(&kcs, sizeof(kcs));
				return -EFAULT;
			}
		}