RAS: Fix ARM processor error bounds checking
Quoted 78 lines
Commit
87880af2d24e("APEI/GHES: ARM processor Error: don't go past allocated memory") and commit05954511b73e("RAS: Report all ARM processor CPER information to userspace") introduced bounds checking for malformed ARM processor error records inlog_arm_hw_error(). However, two issues remain:1. The
ctx_infobounds check condition is inverted: it addsctx_info->sizewhen the context header is already past the end of the section instead of when it is within bounds.2. When
vsei_len< 0, the error path does not verifypei_lenandctx_len. Since these are derived fromerr_info_numandcontext_info_num, they may describe regions beyond the allocated record, causingtrace_arm_event()to read out of bounds.Patch 1 fixes the inverted bounds check for context info iteration. Patch 2 sanitizes pei_len/ctx_len/ven_err_data in the
vsei_len< 0 error path to prevent out-of-bounds reads intrace_arm_event().The
ctx_info->sizeoverflow (a size over0x7fffffffmaking the signed sz negative, as reported by Hanjun Guo) is deliberately left unaddressed in this series: a size overflow implies a corrupted firmware record, and thensection_lengthmay be corrupted as well. For example, a real section length of 1024 could be reported as 16000, and the context walk can go out of bounds even without any size overflow. Guardingctx_info->sizealone therefore does not add meaningful protection.Changes in v6:
- Drop patch 3 ("RAS: Fix integer overflow in ARM processor error context walk"): an overflowingctx_info->sizeimplies a corrupted firmware record, in which casesection_lengthmay be corrupted as well, and the context walk can go out of bounds even without a size overflow, so guardingctx_info->sizealone does not add meaningful protection.
- Add a note to the patch 1 commit message with the same reasoning, as cover letters are not preserved in git history.
- No code changes in this version.Changes in v5:
- Collect Reviewed-by tags from Hanjun Guo for patches 1 and 2.
- Added comments to patch 3.
- No code changes in this version.Changes in v4:
- Remove the empty line between the Fixes: and Signed-off-by: tags in patches 1 and 2, per Hanjun Guo's comments.
- Add braces around the else branch that assignsven_err_datain patch 2, as suggested by Hanjun Guo.
- Add new patch 3 to check each context entry with 64-bit arithmetic and stop the walk at the first entry that does not fit in the section, so actx_info->sizeover0x7fffffffcannot overflow the signed int sz and walkctx_infopast the section, addressing Hanjun Guo's overflow comment.Changes in v3:
- There was no change, and the email was sent by mistake.Changes in v2:
- Split the original single patch into two separate patches, one for each distinct fix, to ease review and backporting.v5:
RAS: Fix ARM processor error bounds checking
https://lore.kernel.org/all/[email protected]/v4:
RAS: Fix ARM processor error bounds checking
https://lore.kernel.org/all/[email protected]/v2:
RAS: Fix ARM processor error bounds checking
https://lore.kernel.org/all/[email protected]/v1:
RAS: Fix out-of-rangesection_lengthin ARM processor error handling
https://lore.kernel.org/all/[email protected]/
Quoted 10 lines
Abbott Liu (2):
RAS: Fix inverted context info bounds check in ARM processor errors
RAS: Fix out-of-bounds read when tracingarm_eventdrivers/ras/ras.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-)Signature · 1 line
2.43.0
Hi,
Friendly ping on these patches in v6 versions:
https://lore.kernel.org/all/[email protected]/
Please let me know if there is anything inappropriate in the patch or if it is ready to be applied to the tree.
Best regards,
Abbott Liu