mpt3sas: downgrade full copy_from_user to access_ok check
Subsystems (2)
PATCH 1/1 mpt3sas: downgrade full copy_from_user to access_ok check
Since right after the user copy, we are going to memset(&karg, 0, sizeof(karg)), I guess an access_ok check is enough?
--- drivers/scsi/mpt3sas/mpt3sas_ctl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/mpt3sas/mpt3sas_ctl.c +1 -1
@@ -1065,7 +1065,7 @@ _ctl_getiocinfo(struct MPT3SAS_ADAPTER *ioc, void __user *arg) {struct mpt3_ioctl_iocinfo karg; -if (copy_from_user (&karg, arg,sizeof (karg))) { +if (!access_ok (VERIFY_READ , arg,sizeof (karg))) {pr_err ("failure at %s:%d/%s()!\n" , __FILE__, __LINE__, __func__);return -EFAULT ;
Signature · 1 line
2.7.4
Quoted 2 lines · Meng Xu
Since right after the user copy, we are going to
memset(&karg, 0, sizeof(karg)), I guess anaccess_okcheck is enough?
The right thing is to remove it entirely.
Quoted 2 lines · Meng Xu
Since right after the user copy, we are going to
memset(&karg, 0, sizeof(karg)), I guess anaccess_okcheck is enough?
access_ok() is *NOT* "will copy_from_user() succeed?" Not even close. On a bunch of architectures (sparc64, for one) access_ok() is always true.
All it does is checking that address is not a kernel one - e.g. on i386 anything in range 0..3Gb qualifies. Whether anything's mapped at that address or not.
Why bother with that copy_from_user() at all? The same ioctl() proceeds to copy_to_user() on exact same range; all you get from it is "if the area passed by caller is writable, but not readable, fail with -EFAULT". Who cares?
Just drop that copy_from_user() completely. Anything access_ok() might've caught will be caught by copy_to_user() anyway.
Quoted 15 lines · Al Viro
Quoted 2 lines · Meng Xu
Since right after the user copy, we are going to
memset(&karg, 0, sizeof(karg)), I guess anaccess_okcheck is enough?
access_ok()is *NOT* "willcopy_from_user()succeed?" Not even close. On a bunch of architectures (sparc64, for one)access_ok()is always true.All it does is checking that address is not a kernel one - e.g. on i386 anything in range 0..3Gb qualifies. Whether anything's mapped at that address or not.
Quoted 7 lines
Why bother with that
copy_from_user()at all? The sameioctl()proceeds tocopy_to_user()on exact same range; all you get from it is "if the area passed by caller is writable, but not readable, fail with-EFAULT". Who cares?Just drop that
copy_from_user()completely. Anythingaccess_ok()might've caught will be caught bycopy_to_user()anyway.
Yes, Christoph has suggested the same thing and I have submitted another patch with copy_from_user removed entirely.