|
|
|
|
|
by 1udfx9cf8azi0
814 days ago
|
|
if (nbytes < sizeof(*hwrpb))
return -1;
if (copy_to_user(buffer, hwrpb, nbytes) != 0)
return -2;
The fix that was done was: if (nbytes > sizeof(*hwrpb))
But I think the correct fix is: if (copy_to_user(buffer, hwrpb, sizeof(*hwrpb)) != 0)
It never makes sense to copy out of the hwrpb pointer any size other than sizeof(*hwrpb). |
|
and sizeof(hwrpb) is now 16 bytes, then you will be copying 12 bytes of data too many from the caller, potentially reading into memory it doesn't own. I would say that should be avoided.
The better solution I believe would be to only copy the minimum amount of bytes supported by caller & callee. So:
nbytes = MIN(nbytes, sizeof(hwrpb));
Which should ensure backwards and forwards compatibility, assuming the version info of hwrpb->size is respected then the fact that part of the hwrpb struct isn't initialized shouldn't matter.