Skip to contentSkip to conversation

s390/zcrypt: Fix a size determination in zcrypt_unlocked_ioctl()

PATCH In review Zhenzhong Duan 2 participants 2 messages Sep 22, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 s390/zcrypt: Fix a size determination in zcrypt_unlocked_ioctl()

With new ioctl(ZCRYPT_PERDEV_REQCNT) introduced, kernel use dynamic allocation for the 256 element array of unsigned integers for the number of successfully completed requests per device. It's not a static array of 64 elements any more.

Fixes af4a72276d49 ("s390/zcrypt: Support up to 256 crypto adapters.")
---
 drivers/s390/crypto/zcrypt_api.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/s390/crypto/zcrypt_api.c +1 -1
index 4dbbfd88262c..5c3f3f89e2f3 100644
@@ -1449,7 +1449,7 @@ static long zcrypt_unlocked_ioctl(struct file *filp, unsigned int cmd,
 		if (!reqcnt)
 			return -ENOMEM;
 		zcrypt_perdev_reqcnt(reqcnt, AP_DEVICES);
-		if (copy_to_user((int __user *) arg, reqcnt, sizeof(reqcnt)))
+		if (copy_to_user((int __user *) arg, reqcnt, sizeof(u32) * AP_DEVICES))
 			rc = -EFAULT;
 		kfree(reqcnt);
 		return rc;
Signature · 1 line
2.25.1
#1 lore raw
Quoted 7 lines · Zhenzhong Duan

With new ioctl(ZCRYPT_PERDEV_REQCNT) introduced, kernel use dynamic allocation for the 256 element array of unsigned integers for the number of successfully completed requests per device. It's not a static array of 64 elements any more.

Fixes af4a72276d49 ("s390/zcrypt: Support up to 256 crypto adapters.")

Thanks for the patch, but we have a similar patch already queued internally. (Found with coccicheck).

Quoted 18 lines
---
 drivers/s390/crypto/zcrypt_api.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/s390/crypto/zcrypt_api.c +1 -1
index 4dbbfd88262c..5c3f3f89e2f3 100644
@@ -1449,7 +1449,7 @@ static long zcrypt_unlocked_ioctl(struct file *filp, unsigned int cmd,
 		if (!reqcnt)
 			return -ENOMEM;
 		zcrypt_perdev_reqcnt(reqcnt, AP_DEVICES);
-		if (copy_to_user((int __user *) arg, reqcnt, sizeof(reqcnt)))
+		if (copy_to_user((int __user *) arg, reqcnt, sizeof(u32) * AP_DEVICES))
 			rc = -EFAULT;
 		kfree(reqcnt);
 		return rc;