[02/10] libsframe: guard against malformed rep_block_size
Checks
| Context |
Check |
Description |
| linaro-tcwg-bot/tcwg_binutils_build--master-arm |
success
|
Build passed
|
| linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 |
success
|
Build passed
|
| linaro-tcwg-bot/tcwg_binutils_check--master-aarch64 |
success
|
Test passed
|
| linaro-tcwg-bot/tcwg_binutils_check--master-arm |
success
|
Test passed
|
Commit Message
From: Indu Bhagat <indu.bhagat@oracle.com>
When checking for an applicable FRE, guard against invalid data in
rep_block_size, lest there be an arithmetic exception caused by division
by zero. Similar code was flagged by Sashiko in the stacktracer patches
for Linux kernel earlier.
---
libsframe/sframe.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
Comments
On 8/28/2026 12:41 AM, Indu Bhagat wrote:
> From: Indu Bhagat <indu.bhagat@oracle.com>
>
> When checking for an applicable FRE, guard against invalid data in
> rep_block_size, lest there be an arithmetic exception caused by division
> by zero. Similar code was flagged by Sashiko in the stacktracer patches
> for Linux kernel earlier.
> ---
> libsframe/sframe.c | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
Reviewed-by: Jens Remus <jremus@linux.ibm.com>
> diff --git a/libsframe/sframe.c b/libsframe/sframe.c
> @@ -600,7 +600,12 @@ sframe_fre_check_range_p (const sframe_decoder_ctx *dctx, uint32_t func_idx,
> /* For SFrame FDEs encoding information for repetitive pattern of insns,
> masking with the rep_block_size is necessary to find the matching FRE. */
> if (mask_p)
> - pc_offset = pc_offset % rep_block_size;
> + {
> + /* Treat a zero-sized repeat block as malformed input. */
> + if (rep_block_size == 0)
> + return false;
This works, as sframe_find_fre() will error with SFRAME_ERR_FDE_INVAL if
no matching FRE is found for the IP within the already located FDE.
> + pc_offset = pc_offset % rep_block_size;
> + }
>
> return (start_ip_offset <= pc_offset) && (end_ip_offset >= pc_offset);
> }
Regards,
Jens
@@ -600,7 +600,12 @@ sframe_fre_check_range_p (const sframe_decoder_ctx *dctx, uint32_t func_idx,
/* For SFrame FDEs encoding information for repetitive pattern of insns,
masking with the rep_block_size is necessary to find the matching FRE. */
if (mask_p)
- pc_offset = pc_offset % rep_block_size;
+ {
+ /* Treat a zero-sized repeat block as malformed input. */
+ if (rep_block_size == 0)
+ return false;
+ pc_offset = pc_offset % rep_block_size;
+ }
return (start_ip_offset <= pc_offset) && (end_ip_offset >= pc_offset);
}