Skip to content

ptp: reject frequency adjustments that overflow scaled_ppm_to_ppb()

Deep Shah linux-kselftest lkml netdev 3 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest2 patches 3 repliesIn review 1 of 2 applied
  2. v22 patches 3 repliesSuperseded
  3. v12 patches 3 repliesSuperseded

Changes in v3 from the cover letter

- retarget at net-next and drop the Fixes tag (Jakub Kicinski)
- patch 1: unchanged
- patch 2:
- cast the test value to the type of tx.freq rather than guarding on __SIZEOF_LONG__, which skipped the assignment on x32 and other y2038 configurations and failed the test there (Simon Horman)
- add the built binary to .gitignore

Patches in v3 1 of 2 applied

#Subject and filesSizeRepliesApplied
1/2ptp: reject frequency adjustments that overflow scaled_ppm_to_ppb()drivers/ptp/ptp_clock.c+13 -11 replyApplied
2/2selftests: ptp: add a regression test for the frequency adjustment overflowtools/testing/selftests/ptp/.gitignore tools/testing/selftests/ptp/Makefile tools/testing/selftests/ptp/ptp_freq_overflow.c+103 -11 reply

Reviews trailers per patch

All 2 patches have a Reviewed-by or Acked-by.

PatchVadim FedorenkoRichard Cochran
1/2R-b A-b
2/2A-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v3 thread

Cover letter [PATCH net-next v3 0/2] ptp: reject frequency adjustments that overflow scaled_ppm_to_ppb()

ptp_clock_adjtime() validates an ADJ_FREQUENCY request by converting tx->freq to ppb and comparing it against ops->max_adj. On 64-bit systems that conversion can overflow s64 and wrap the result back into range, so a crafted tx->freq bypasses the check and reaches ->adjfine() unclamped.

No real user space asks for such a frequency, so this is hardening rather than a fix anyone is waiting on, and it is targeted at net-next with no Fixes tag per Jakub's feedback on v2.

Patch 1 rejects the overflow in ptp_clock_adjtime().
Patch 2 adds a regression test that crafts struct timex.freq directly (testptp's int-ppb path cannot express the value) and confirms it is rejected with -ERANGE.

Changes in v3:
- retarget at net-next and drop the Fixes tag (Jakub Kicinski)
- patch 1: unchanged
- patch 2:
- cast the test value to the type of tx.freq rather than guarding on __SIZEOF_LONG__, which skipped the assignment on x32 and other y2038 configurations and failed the test there (Simon Horman)
- add the built binary to .gitignore

Changes in v2:
- patch 1: added Reviewed-by from Vadim Fedorenko.
- patch 2 (all from Simon Horman's review):
- cast fd to unsigned before the shift in FD_TO_CLOCKID (UBSan)
- avoid a -Woverflow warning on 32-bit
- save and restore the clock frequency
- skip instead of fail on -EBUSY (free-running clock)

Link to v1:
https://lore.kernel.org/netdev/[email protected]/
Link to v2:
https://lore.kernel.org/netdev/[email protected]/

Deep Shah (2):
ptp: reject frequency adjustments that overflow scaled_ppm_to_ppb()
selftests: ptp: add a regression test for the frequency adjustment
overflow

 drivers/ptp/ptp_clock.c                       |  14 ++-
 tools/testing/selftests/ptp/.gitignore        |   1 +
 tools/testing/selftests/ptp/Makefile          |   2 +-
 .../testing/selftests/ptp/ptp_freq_overflow.c | 101 ++++++++++++++++++
 4 files changed, 116 insertions(+), 2 deletions(-)
 create mode 100644 tools/testing/selftests/ptp/ptp_freq_overflow.c

base-commit: 69963a0678a347d57c4ac8b16939dba216eb95ce

Signature · 1 line
2.43.0