Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Litex: clock: Undefined behavior due to unchecked return code #71728

Merged
merged 1 commit into from
Jun 10, 2024

Conversation

franc0is
Copy link
Contributor

Found via static analysis. Two separate error paths where failing to check the return code leads to undefined behavior:

  1. In litex_clk_get_phase, the divider stays set to 0 when litex_clk_get_clkout_divider errors out, which leads to a division by 0.
  2. In litex_clk_calc_duty_normal, the duty struct is used uninitialized if litex_clk_get_duty_cycle errors out.

In both case, checking the return code and returning early resolves the issue.

@franc0is franc0is changed the title Litex: clock: Undefined behavior due to uncheked return code Litex: clock: Undefined behavior due to unchecked return code Apr 21, 2024
@franc0is franc0is force-pushed the fbo-4 branch 2 times, most recently from 7d5bec3 to 47256b2 Compare April 21, 2024 02:50
@MaureenHelm
Copy link
Member

Please rebase to retrigger CI

@mateusz-holenko @kgugala please take a look

@fkokosinski fkokosinski self-requested a review May 29, 2024 07:19
Copy link
Member

@fkokosinski fkokosinski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Collaborator

@mateusz-holenko mateusz-holenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine to me

Found via static analysis. Two separate error paths where failing to
check the return code leads to undefined behavior:
1. In `litex_clk_get_phase`, the divider stays set to 0 when
   `litex_clk_get_clkout_divider` errors out, which leads to a division
by 0.
2. In `litex_clk_calc_duty_normal`, the `duty` struct is used
   uninitialized if `litex_clk_get_duty_cycle` errors out.

In both case, checking the return code and returning early resolves the
issue.

Signed-off-by: François Baldassari <[email protected]>
@kartben
Copy link
Collaborator

kartben commented Jun 7, 2024

rebased to trigger CI

@kartben kartben assigned fkokosinski and unassigned nordic-krch Jun 10, 2024
@kartben
Copy link
Collaborator

kartben commented Jun 10, 2024

re-assigning as per recent update to MAINTAINERS.yml

@jhedberg jhedberg merged commit e94af5b into zephyrproject-rtos:main Jun 10, 2024
71 of 77 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants