fix off-by-one write in proc/cpuinfo hardware/revision parse - #414
fix off-by-one write in proc/cpuinfo hardware/revision parse#414soma0212 wants to merge 1 commit into
Conversation
|
Hi @soma0212! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
You'll need to sign the Contributor License Agreement |
|
Dupe of #408 |
|
Right, #408 predates this one and fixes the same off-by-one; I missed it when filing. The only behavioral difference is the exactly-max-length case: #408 truncates to 63 bytes and always null-terminates, while this keeps the full 64 bytes unterminated, which the strnlen(hardware, CPUINFO_HARDWARE_VALUE_MAX) consumers in chipset.c already handle. Both close the OOB write, so whichever approach you prefer to land works for me. I'll get the CLA sorted in the meantime. |
|
Will get the CLA signed. On the dupe, yes, same underlying bug and #408 predates this one. The practical difference is behavior at the limit: #408 truncates to MAX-1 and always null-terminates, so an exactly-64-byte Hardware value loses its last character, while this patch keeps the full value unterminated, which is what the chipset decoders already assume (they read these fields with strnlen(buf, MAX) in chipset.c). Either version closes the OOB write, so I'll defer to whichever approach you want to land, and I'm fine closing this one if you take #408. |
In
parse_line(src/arm/linux/cpuinfo.c) the Hardware and Revision handlers null-terminate withstate->hardware[value_length] = '\0'in the branch taken when the value fits. But the length guard uses> CPUINFO_HARDWARE_VALUE_MAX(and> CPUINFO_REVISION_VALUE_MAX), so a value whose length is exactly the max still takes that branch. Those destinations are exactly MAX bytes (64 and 9), so aHardwareline with a 64-byte value, or aRevisionline with a 9-byte value, writes the terminator one byte past the buffer.Change both comparisons to
>=so an equal-length value goes through the truncation path instead. That leaves the buffer full and unterminated, which is already the contract downstream code relies on (the chipset decoders read these fields withstrnlen(buf, MAX)), so keeping the bound at the write site is enough and no consumer needs to change.