diff options
| author | Kaushlendra Kumar <kaushlendra.kumar@intel.com> | 2026-10-29 20:02:00 +0530 |
|---|---|---|
| committer | Len Brown <len.brown@intel.com> | 2026-10-31 13:46:33 -0300 |
| commit | cfdb43387f3e6144bc374165ebf6deecb0324470 (patch) | |
| tree | cb76281b8204f046c8b023dc37a648838accca33 | |
| parent | 3d6fc92be1feb6436932979e4652174467e7a42a (diff) | |
tools/power turbostat: Fix PMT mmap size and bounds check
Remove assert(offset == 0), to allow non-zero PMT offsets.
Fix the pmt_mmio_open() mapping to round-up (offset + size).
Fix the offset bounds check to disallow running past the end of the region.
[lenb: commit message re-write]
Signed-off-by: Kaushlendra Kumar <kaushlendra.kumar@intel.com>
Signed-off-by: Len Brown <len.brown@intel.com>
| -rw-r--r-- | tools/power/x86/turbostat/turbostat.c | 6 |
1 files changed, 2 insertions, 4 deletions
diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c index 0ba51e67962d..f5a7654cf513 100644 --- a/tools/power/x86/turbostat/turbostat.c +++ b/tools/power/x86/turbostat/turbostat.c @@ -10266,13 +10266,11 @@ struct pmt_mmio *pmt_mmio_open(unsigned int target_guid) break; } - assert(offset == 0); - fd_pmt = openat(fd_telem_dir, "telem", O_RDONLY); if (fd_pmt == -1) goto loop_cleanup_and_break; - mmap_size = ROUND_UP_TO_PAGE_SIZE(size); + mmap_size = ROUND_UP_TO_PAGE_SIZE(offset + size); mmio = mmap(0, mmap_size, PROT_READ, MAP_SHARED, fd_pmt, 0); if (mmio != MAP_FAILED) { if (debug) @@ -10444,7 +10442,7 @@ int pmt_add_counter(unsigned int guid, unsigned int seq, const char *name, enum return 1; } - if (offset >= mmio->size) { + if (offset > mmio->size || mmio->size - offset < 8) { if (mode != PMT_OPEN_TRY) { fprintf(stderr, "%s: offset %u outside of PMT MMIO size %u\n", __func__, offset, mmio->size); exit(1); |
