Skip to content

Commit 6353abd

Browse files
royenheartnamhyung
authored andcommitted
perf record: Fix memset out-of-range error
Modified the object of 'memset' from '&lost.lost' to '&lost' in record__read_lost_samples. This allows 'memset' to access memory properly without causing out-of-bounds problems. The problems got from builtin-record.c are: In file included from /usr/include/string.h:495, from util/parse-events.h:13, from builtin-record.c:14: In function 'memset', inlined from 'record__read_lost_samples' at builtin-record.c:1958:6, inlined from '__cmd_record.constprop' at builtin-record.c:2817:2: /usr/include/x86_64-linux-gnu/bits/string_fortified.h:71:10: error: '__builtin_memset' offset [17, 64] from the object at 'lost' is out of the bounds of referenced subobject 'lost' with type 'struct perf_record_lost_samples' at offset 0 [-Werror=array-bounds] 71|return __builtin___memset_chk (__dest,__ch,__len,__bos0 (__dest)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The error arised when performing a memset operation on the 'lost' variable, the bytes of 'sizeof(lost)' exceeds that of '&lost.lost', which are 64 and 16. Fixes: 6c1785c ("perf record: Ensure space for lost samples") Signed-off-by: Haoze Xie <[email protected]> Signed-off-by: Yuan Tan <[email protected]> Link: https://lore.kernel.org/r/11e12f171b846577cac698cd3999db3d7f6c4d03.1720372317.git.royenheart@gmail.com Signed-off-by: Namhyung Kim <[email protected]>
1 parent 306f921 commit 6353abd

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

tools/perf/builtin-record.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1955,7 +1955,7 @@ static void record__read_lost_samples(struct record *rec)
19551955
}
19561956

19571957
if (count.lost) {
1958-
memset(&lost.lost, 0, sizeof(lost));
1958+
memset(&lost, 0, sizeof(lost));
19591959
lost.lost.header.type = PERF_RECORD_LOST_SAMPLES;
19601960
__record__save_lost_samples(rec, evsel, &lost.lost,
19611961
x, y, count.lost, 0);
@@ -1965,7 +1965,7 @@ static void record__read_lost_samples(struct record *rec)
19651965

19661966
lost_count = perf_bpf_filter__lost_count(evsel);
19671967
if (lost_count) {
1968-
memset(&lost.lost, 0, sizeof(lost));
1968+
memset(&lost, 0, sizeof(lost));
19691969
lost.lost.header.type = PERF_RECORD_LOST_SAMPLES;
19701970
__record__save_lost_samples(rec, evsel, &lost.lost, 0, 0, lost_count,
19711971
PERF_RECORD_MISC_LOST_SAMPLES_BPF);

0 commit comments

Comments
 (0)