Skip to contentSkip to conversation

perf alsr: Add missing SIMD handling in aslr_tool__process_sample()

PATCH Applied Dapeng Mi 4 participants 11 messages Sep 15 – Sep 22 perf events

v1 of 2 Applied Latest is v2 →

lore
Share & tools
lore

Dapeng Mi

author
#0 lore raw

PATCH 1/2 perf alsr: Add missing SIMD handling in aslr_tool__process_sample()

Currently the SIMD register sampling is supported, but the corresponding handling is missed in aslr_tool__process_sample(). This can break parsing of the sample record.

Add the missing SIMD register handling in aslr_tool__process_sample().

---

These two patches fix Sashiko reported defects for the patchset:
"Perf tools: Support eGPRs/SSP/SIMD registers sampling"
https://lore.kernel.org/all/[email protected]/

 tools/perf/util/aslr.c | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
tools/perf/util/aslr.c +31 -0
index 027695d96779..a097084201a0 100644
@@ -19,6 +19,7 @@
 #include <internal/lib.h>  /* page_size */
 #include <linux/compiler.h>
 #include <linux/zalloc.h>
+#include <linux/overflow.h>
 #include <errno.h>
 #include <inttypes.h>
 #include <unistd.h>
@@ -992,6 +993,34 @@ static int aslr_tool__process_sample(const struct perf_tool *tool,
 				COPY_U64();
 		}
 	}
+
+#define CHECK_SIMD() \
+	do { \
+		if (abi & PERF_SAMPLE_REGS_ABI_SIMD) { \
+			u64 nr_vector, vec_qwords; \
+			u64 nr_pred, pred_qwords; \
+			u64 header_len, vec_len, pred_len, simd_len; \
+			if (CHECK_BOUNDS(nr + 4, nr + 4)) { \
+				ret = -EFAULT; \
+				goto out_put; \
+			} \
+			header_len = 4;	\
+			nr_vector = in_array[i + nr]; \
+			vec_qwords = in_array[i + nr + 1]; \
+			nr_pred = in_array[i + nr + 2]; \
+			pred_qwords = in_array[i + nr + 3]; \
+			if (check_mul_overflow(nr_vector, vec_qwords, &vec_len) || \
+			    check_mul_overflow(nr_pred, pred_qwords, &pred_len) || \
+			    check_add_overflow(vec_len, pred_len, &simd_len) || \
+			    check_add_overflow(header_len, simd_len, &simd_len) || \
+			    check_add_overflow(nr, simd_len, &nr) || \
+			    nr > max_i - i) { \
+				ret = -EFAULT; \
+				goto out_put; \
+			} \
+		} \
+	} while (0)
+
 	if (orig_sample_type & PERF_SAMPLE_REGS_USER) {
 		u64 abi;
 
@@ -1007,6 +1036,7 @@ static int aslr_tool__process_sample(const struct perf_tool *tool,
 				ret = -EFAULT;
 				goto out_put;
 			}
+			CHECK_SIMD();
 			i += nr;
 		}
 	}
@@ -1061,6 +1091,7 @@ static int aslr_tool__process_sample(const struct perf_tool *tool,
 				ret = -EFAULT;
 				goto out_put;
 			}
+			CHECK_SIMD();
 			i += nr;
 		}
 	}

base-commit: 91b0782fc9e9d2f0a40b5256146e014802fdbb36

Signature · 1 line
2.34.1
author
#1 lore raw

PATCH 2/2 perf util: Explicitly include required headers

Sashiko complains "the perf tool can be compiled with musl libc, which enforces strict POSIX namespace separation and does not implicitly include headers. Relying on implicit header inclusion can cause build failures under musl."

Include the required headers explicitly to avoid such failures.

---
 tools/perf/util/parse-regs-options.c           | 1 +
 tools/perf/util/perf-regs-arch/perf_regs_x86.c | 2 ++
 tools/perf/util/session.c                      | 5 +++++
 3 files changed, 8 insertions(+)
tools/perf/util/parse-regs-options.c +1 -0
index 709fcfb077a2..e70393388fae 100644
@@ -3,6 +3,7 @@
 #include <stdlib.h>
 #include <stdint.h>
 #include <string.h>
+#include <strings.h>
 #include <stdio.h>
 #include "util/debug.h"
 #include <dwarf-regs.h>
tools/perf/util/perf-regs-arch/perf_regs_x86.c +2 -0
index fb6cf34f42f2..ea1d402b0893 100644
@@ -3,6 +3,8 @@
 #include <errno.h>
 #include <string.h>
 #include <regex.h>
+#include <unistd.h>
+#include <stdbool.h>
 #include <linux/kernel.h>
 #include <linux/zalloc.h>
 
tools/perf/util/session.c +5 -0
index a5b596cd14be..04fba6fb02e8 100644
@@ -1,4 +1,9 @@
 // SPDX-License-Identifier: GPL-2.0
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <string.h>
+#include <assert.h>
 #include <errno.h>
 #include <signal.h>
 #include <inttypes.h>
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH 2/2] perf util: Explicitly include required headers

Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 8 lines

Sashiko complains "the perf tool can be compiled with musl libc, which enforces strict POSIX namespace separation and does not implicitly include headers. Relying on implicit header inclusion can cause build failures under musl."

Include the required headers explicitly to avoid such failures.

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
reviewer Reviewed-by on v1 2/2
#3 lore raw

Re: [PATCH 2/2] perf util: Explicitly include required headers

In reply to Dapeng Mi
Quoted 9 lines · Dapeng Mi

Sashiko complains "the perf tool can be compiled with musl libc, which enforces strict POSIX namespace separation and does not implicitly include headers. Relying on implicit header inclusion can cause build failures under musl."

Include the required headers explicitly to avoid such failures.

Thanks,
Ian

Quoted 48 lines
---
 tools/perf/util/parse-regs-options.c           | 1 +
 tools/perf/util/perf-regs-arch/perf_regs_x86.c | 2 ++
 tools/perf/util/session.c                      | 5 +++++
 3 files changed, 8 insertions(+)
tools/perf/util/parse-regs-options.c +1 -0
index 709fcfb077a2..e70393388fae 100644
@@ -3,6 +3,7 @@
 #include <stdlib.h>
 #include <stdint.h>
 #include <string.h>
+#include <strings.h>
 #include <stdio.h>
 #include "util/debug.h"
 #include <dwarf-regs.h>
tools/perf/util/perf-regs-arch/perf_regs_x86.c +2 -0
index fb6cf34f42f2..ea1d402b0893 100644
@@ -3,6 +3,8 @@
 #include <errno.h>
 #include <string.h>
 #include <regex.h>
+#include <unistd.h>
+#include <stdbool.h>
 #include <linux/kernel.h>
 #include <linux/zalloc.h>
 
tools/perf/util/session.c +5 -1
index a5b596cd14be..04fba6fb02e8 100644
@@ -1,4 +1,9 @@
 // SPDX-License-Identifier: GPL-2.0
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <string.h>
+#include <assert.h>
 #include <errno.h>
 #include <signal.h>
 #include <inttypes.h>
--

2.34.1

#4 lore raw
In reply to Dapeng Mi
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 7 lines

Currently the SIMD register sampling is supported, but the corresponding handling is missed in aslr_tool__process_sample(). This can break parsing of the sample record.

Add the missing SIMD register handling in aslr_tool__process_sample().

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
author
#5 lore raw
In reply to Dapeng Mi

Kindly ping ...

@Arnaldo, @Namhyung, @Ian, not sure if you have bandwidth to review this small patchset which fixes the Sashiko found minor issues for the "Perf
tools: Support eGPRs/SSP/SIMD registers sampling" patchset?

If possible, it's better to be queued in this cycle, then we don't need extra backporting. Thanks.

Quoted 81 lines · Dapeng Mi

Currently the SIMD register sampling is supported, but the corresponding handling is missed in aslr_tool__process_sample(). This can break parsing of the sample record.

Add the missing SIMD register handling in aslr_tool__process_sample().

---

These two patches fix Sashiko reported defects for the patchset:
"Perf tools: Support eGPRs/SSP/SIMD registers sampling"
https://lore.kernel.org/all/[email protected]/

 tools/perf/util/aslr.c | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
tools/perf/util/aslr.c +31 -0
index 027695d96779..a097084201a0 100644
@@ -19,6 +19,7 @@
 #include <internal/lib.h>  /* page_size */
 #include <linux/compiler.h>
 #include <linux/zalloc.h>
+#include <linux/overflow.h>
 #include <errno.h>
 #include <inttypes.h>
 #include <unistd.h>
@@ -992,6 +993,34 @@ static int aslr_tool__process_sample(const struct perf_tool *tool,
 				COPY_U64();
 		}
 	}
+
+#define CHECK_SIMD() \
+	do { \
+		if (abi & PERF_SAMPLE_REGS_ABI_SIMD) { \
+			u64 nr_vector, vec_qwords; \
+			u64 nr_pred, pred_qwords; \
+			u64 header_len, vec_len, pred_len, simd_len; \
+			if (CHECK_BOUNDS(nr + 4, nr + 4)) { \
+				ret = -EFAULT; \
+				goto out_put; \
+			} \
+			header_len = 4;	\
+			nr_vector = in_array[i + nr]; \
+			vec_qwords = in_array[i + nr + 1]; \
+			nr_pred = in_array[i + nr + 2]; \
+			pred_qwords = in_array[i + nr + 3]; \
+			if (check_mul_overflow(nr_vector, vec_qwords, &vec_len) || \
+			    check_mul_overflow(nr_pred, pred_qwords, &pred_len) || \
+			    check_add_overflow(vec_len, pred_len, &simd_len) || \
+			    check_add_overflow(header_len, simd_len, &simd_len) || \
+			    check_add_overflow(nr, simd_len, &nr) || \
+			    nr > max_i - i) { \
+				ret = -EFAULT; \
+				goto out_put; \
+			} \
+		} \
+	} while (0)
+
 	if (orig_sample_type & PERF_SAMPLE_REGS_USER) {
 		u64 abi;
 
@@ -1007,6 +1036,7 @@ static int aslr_tool__process_sample(const struct perf_tool *tool,
 				ret = -EFAULT;
 				goto out_put;
 			}
+			CHECK_SIMD();
 			i += nr;
 		}
 	}
@@ -1061,6 +1091,7 @@ static int aslr_tool__process_sample(const struct perf_tool *tool,
 				ret = -EFAULT;
 				goto out_put;
 			}
+			CHECK_SIMD();
 			i += nr;
 		}
 	}

base-commit: 91b0782fc9e9d2f0a40b5256146e014802fdbb36

reviewer Reviewed-by
#6 lore raw
Quoted 9 lines · Dapeng

Kindly ping ...

@Arnaldo, @Namhyung, @Ian, not sure if you have bandwidth to review this small patchset which fixes the Sashiko found minor issues for the "Perf
tools: Support eGPRs/SSP/SIMD registers sampling" patchset?

If possible, it's better to be queued in this cycle, then we don't need extra backporting. Thanks.

Quoted 64 lines · Dapeng Mi
Quoted 63 lines

Currently the SIMD register sampling is supported, but the corresponding handling is missed in aslr_tool__process_sample(). This can break parsing of the sample record.

Add the missing SIMD register handling in aslr_tool__process_sample().

---

These two patches fix Sashiko reported defects for the patchset:
"Perf tools: Support eGPRs/SSP/SIMD registers sampling"
https://lore.kernel.org/all/[email protected]/

 tools/perf/util/aslr.c | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
tools/perf/util/aslr.c +29 -0
index 027695d96779..a097084201a0 100644
@@ -19,6 +19,7 @@
 #include <internal/lib.h>  /* page_size */
 #include <linux/compiler.h>
 #include <linux/zalloc.h>
+#include <linux/overflow.h>
 #include <errno.h>
 #include <inttypes.h>
 #include <unistd.h>
@@ -992,6 +993,34 @@ static int aslr_tool__process_sample(const struct perf_tool *tool,
                              COPY_U64();
              }
      }
+
+#define CHECK_SIMD() \
+     do { \
+             if (abi & PERF_SAMPLE_REGS_ABI_SIMD) { \
+                     u64 nr_vector, vec_qwords; \
+                     u64 nr_pred, pred_qwords; \
+                     u64 header_len, vec_len, pred_len, simd_len; \
+                     if (CHECK_BOUNDS(nr + 4, nr + 4)) { \
+                             ret = -EFAULT; \
+                             goto out_put; \
+                     } \
+                     header_len = 4; \
+                     nr_vector = in_array[i + nr]; \
+                     vec_qwords = in_array[i + nr + 1]; \
+                     nr_pred = in_array[i + nr + 2]; \
+                     pred_qwords = in_array[i + nr + 3]; \
+                     if (check_mul_overflow(nr_vector, vec_qwords, &vec_len) || \
+                         check_mul_overflow(nr_pred, pred_qwords, &pred_len) || \
+                         check_add_overflow(vec_len, pred_len, &simd_len) || \
+                         check_add_overflow(header_len, simd_len, &simd_len) || \
+                         check_add_overflow(nr, simd_len, &nr) || \
+                         nr > max_i - i) { \
+                             ret = -EFAULT; \
+                             goto out_put; \
+                     } \
+             } \
+     } while (0)
+
      if (orig_sample_type & PERF_SAMPLE_REGS_USER) {
              u64 abi;
 
Quoted 13 lines

tools/perf/util/aslr.c static int aslr_tool__process_sample(const struct perf_tool *tool, · line 1094

Quoted 13 lines
tools/perf/util/aslr.c +2 -0
@@ -1007,6 +1036,7 @@ static int aslr_tool__process_sample(const struct perf_tool *tool,
                              ret = -EFAULT;
                              goto out_put;
                      }
+                     CHECK_SIMD();
                      i += nr;
              }
      }
@@ -1061,6 +1091,7 @@ static int aslr_tool__process_sample(const struct perf_tool *tool,
                              ret = -EFAULT;
                              goto out_put;
                      }
+                     CHECK_SIMD();

nit: at the end of the function you could #undef CHECK_SIMD to make it more explicit that the macro only makes sense within the function.

Thanks,
Ian

Quoted 5 lines
Quoted 5 lines
tools/perf/util/aslr.c +0 -0
                      i += nr;
              }
      }

base-commit: 91b0782fc9e9d2f0a40b5256146e014802fdbb36

reviewer
#7 lore raw
Quoted 5 lines · Ian Rogers
Quoted 3 lines · Dapeng

Kindly ping ...

Quoted 8 lines
Quoted 6 lines

@Arnaldo, @Namhyung, @Ian, not sure if you have bandwidth to review this small patchset which fixes the Sashiko found minor issues for the "Perf
tools: Support eGPRs/SSP/SIMD registers sampling" patchset?

If possible, it's better to be queued in this cycle, then we don't need extra backporting. Thanks.

Oh, another nit: there's a typo in the commit message subject: s/alsr/aslr/g.

Thanks,
Ian

Quoted 89 lines
Quoted 64 lines · Dapeng Mi
Quoted 63 lines

Currently the SIMD register sampling is supported, but the corresponding handling is missed in aslr_tool__process_sample(). This can break parsing of the sample record.

Add the missing SIMD register handling in aslr_tool__process_sample().

---

These two patches fix Sashiko reported defects for the patchset:
"Perf tools: Support eGPRs/SSP/SIMD registers sampling"
https://lore.kernel.org/all/[email protected]/

 tools/perf/util/aslr.c | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
tools/perf/util/aslr.c +29 -0
index 027695d96779..a097084201a0 100644
@@ -19,6 +19,7 @@
 #include <internal/lib.h>  /* page_size */
 #include <linux/compiler.h>
 #include <linux/zalloc.h>
+#include <linux/overflow.h>
 #include <errno.h>
 #include <inttypes.h>
 #include <unistd.h>
@@ -992,6 +993,34 @@ static int aslr_tool__process_sample(const struct perf_tool *tool,
                              COPY_U64();
              }
      }
+
+#define CHECK_SIMD() \
+     do { \
+             if (abi & PERF_SAMPLE_REGS_ABI_SIMD) { \
+                     u64 nr_vector, vec_qwords; \
+                     u64 nr_pred, pred_qwords; \
+                     u64 header_len, vec_len, pred_len, simd_len; \
+                     if (CHECK_BOUNDS(nr + 4, nr + 4)) { \
+                             ret = -EFAULT; \
+                             goto out_put; \
+                     } \
+                     header_len = 4; \
+                     nr_vector = in_array[i + nr]; \
+                     vec_qwords = in_array[i + nr + 1]; \
+                     nr_pred = in_array[i + nr + 2]; \
+                     pred_qwords = in_array[i + nr + 3]; \
+                     if (check_mul_overflow(nr_vector, vec_qwords, &vec_len) || \
+                         check_mul_overflow(nr_pred, pred_qwords, &pred_len) || \
+                         check_add_overflow(vec_len, pred_len, &simd_len) || \
+                         check_add_overflow(header_len, simd_len, &simd_len) || \
+                         check_add_overflow(nr, simd_len, &nr) || \
+                         nr > max_i - i) { \
+                             ret = -EFAULT; \
+                             goto out_put; \
+                     } \
+             } \
+     } while (0)
+
      if (orig_sample_type & PERF_SAMPLE_REGS_USER) {
              u64 abi;
 
Quoted 13 lines

tools/perf/util/aslr.c static int aslr_tool__process_sample(const struct perf_tool *tool, · line 1094

Quoted 13 lines
tools/perf/util/aslr.c +2 -0
@@ -1007,6 +1036,7 @@ static int aslr_tool__process_sample(const struct perf_tool *tool,
                              ret = -EFAULT;
                              goto out_put;
                      }
+                     CHECK_SIMD();
                      i += nr;
              }
      }
@@ -1061,6 +1091,7 @@ static int aslr_tool__process_sample(const struct perf_tool *tool,
                              ret = -EFAULT;
                              goto out_put;
                      }
+                     CHECK_SIMD();

nit: at the end of the function you could #undef CHECK_SIMD to make it more explicit that the macro only makes sense within the function.

Thanks,
Ian

Quoted 5 lines
Quoted 5 lines
tools/perf/util/aslr.c +0 -0
                      i += nr;
              }
      }

base-commit: 91b0782fc9e9d2f0a40b5256146e014802fdbb36

author
#8 lore raw
Quoted 4 lines · Ian Rogers
Quoted 3 lines · Ian Rogers
Quoted 2 lines · Dapeng

Kindly ping ...

Quoted 8 lines
Quoted 7 lines
Quoted 6 lines

@Arnaldo, @Namhyung, @Ian, not sure if you have bandwidth to review this small patchset which fixes the Sashiko found minor issues for the "Perf
tools: Support eGPRs/SSP/SIMD registers sampling" patchset?

If possible, it's better to be queued in this cycle, then we don't need extra backporting. Thanks.

Oh, another nit: there's a typo in the commit message subject: s/alsr/aslr/g.

Sure. :)

Quoted 92 lines

Thanks,
Ian

Quoted 88 lines
Quoted 64 lines · Dapeng Mi
Quoted 63 lines

Currently the SIMD register sampling is supported, but the corresponding handling is missed in aslr_tool__process_sample(). This can break parsing of the sample record.

Add the missing SIMD register handling in aslr_tool__process_sample().

---

These two patches fix Sashiko reported defects for the patchset:
"Perf tools: Support eGPRs/SSP/SIMD registers sampling"
https://lore.kernel.org/all/[email protected]/

 tools/perf/util/aslr.c | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
tools/perf/util/aslr.c +29 -0
index 027695d96779..a097084201a0 100644
@@ -19,6 +19,7 @@
 #include <internal/lib.h>  /* page_size */
 #include <linux/compiler.h>
 #include <linux/zalloc.h>
+#include <linux/overflow.h>
 #include <errno.h>
 #include <inttypes.h>
 #include <unistd.h>
@@ -992,6 +993,34 @@ static int aslr_tool__process_sample(const struct perf_tool *tool,
                              COPY_U64();
              }
      }
+
+#define CHECK_SIMD() \
+     do { \
+             if (abi & PERF_SAMPLE_REGS_ABI_SIMD) { \
+                     u64 nr_vector, vec_qwords; \
+                     u64 nr_pred, pred_qwords; \
+                     u64 header_len, vec_len, pred_len, simd_len; \
+                     if (CHECK_BOUNDS(nr + 4, nr + 4)) { \
+                             ret = -EFAULT; \
+                             goto out_put; \
+                     } \
+                     header_len = 4; \
+                     nr_vector = in_array[i + nr]; \
+                     vec_qwords = in_array[i + nr + 1]; \
+                     nr_pred = in_array[i + nr + 2]; \
+                     pred_qwords = in_array[i + nr + 3]; \
+                     if (check_mul_overflow(nr_vector, vec_qwords, &vec_len) || \
+                         check_mul_overflow(nr_pred, pred_qwords, &pred_len) || \
+                         check_add_overflow(vec_len, pred_len, &simd_len) || \
+                         check_add_overflow(header_len, simd_len, &simd_len) || \
+                         check_add_overflow(nr, simd_len, &nr) || \
+                         nr > max_i - i) { \
+                             ret = -EFAULT; \
+                             goto out_put; \
+                     } \
+             } \
+     } while (0)
+
      if (orig_sample_type & PERF_SAMPLE_REGS_USER) {
              u64 abi;
 
Quoted 13 lines

tools/perf/util/aslr.c static int aslr_tool__process_sample(const struct perf_tool *tool, · line 1094

Quoted 13 lines
tools/perf/util/aslr.c +2 -0
@@ -1007,6 +1036,7 @@ static int aslr_tool__process_sample(const struct perf_tool *tool,
                              ret = -EFAULT;
                              goto out_put;
                      }
+                     CHECK_SIMD();
                      i += nr;
              }
      }
@@ -1061,6 +1091,7 @@ static int aslr_tool__process_sample(const struct perf_tool *tool,
                              ret = -EFAULT;
                              goto out_put;
                      }
+                     CHECK_SIMD();

nit: at the end of the function you could #undef CHECK_SIMD to make it more explicit that the macro only makes sense within the function.

Thanks,
Ian

Quoted 5 lines
Quoted 5 lines
tools/perf/util/aslr.c +0 -0
                      i += nr;
              }
      }

base-commit: 91b0782fc9e9d2f0a40b5256146e014802fdbb36

maintainer Applied
#9 lore raw
In reply to Ian Rogers
Quoted 10 lines · Ian Rogers
Quoted 9 lines · Ian Rogers
Quoted 7 lines · Dapeng

Kindly ping ...

@Arnaldo, @Namhyung, @Ian, not sure if you have bandwidth to review this small patchset which fixes the Sashiko found minor issues for the "Perf
tools: Support eGPRs/SSP/SIMD registers sampling" patchset?

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

If possible, it's better to be queued in this cycle, then we don't need extra backporting. Thanks.

Oh, another nit: there's a typo in the commit message subject: s/alsr/aslr/g.

Fixed.

Thanks, applied to perf-tools-next, for v7.4.

- Arnaldo

author
#10 lore raw
In reply to Ian Rogers
Quoted 75 lines · Ian Rogers
Quoted 8 lines · Dapeng

Kindly ping ...

@Arnaldo, @Namhyung, @Ian, not sure if you have bandwidth to review this small patchset which fixes the Sashiko found minor issues for the "Perf
tools: Support eGPRs/SSP/SIMD registers sampling" patchset?

If possible, it's better to be queued in this cycle, then we don't need extra backporting. Thanks.

Quoted 64 lines · Dapeng Mi
Quoted 63 lines

Currently the SIMD register sampling is supported, but the corresponding handling is missed in aslr_tool__process_sample(). This can break parsing of the sample record.

Add the missing SIMD register handling in aslr_tool__process_sample().

---

These two patches fix Sashiko reported defects for the patchset:
"Perf tools: Support eGPRs/SSP/SIMD registers sampling"
https://lore.kernel.org/all/[email protected]/

 tools/perf/util/aslr.c | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
tools/perf/util/aslr.c +29 -0
index 027695d96779..a097084201a0 100644
@@ -19,6 +19,7 @@
 #include <internal/lib.h>  /* page_size */
 #include <linux/compiler.h>
 #include <linux/zalloc.h>
+#include <linux/overflow.h>
 #include <errno.h>
 #include <inttypes.h>
 #include <unistd.h>
@@ -992,6 +993,34 @@ static int aslr_tool__process_sample(const struct perf_tool *tool,
                              COPY_U64();
              }
      }
+
+#define CHECK_SIMD() \
+     do { \
+             if (abi & PERF_SAMPLE_REGS_ABI_SIMD) { \
+                     u64 nr_vector, vec_qwords; \
+                     u64 nr_pred, pred_qwords; \
+                     u64 header_len, vec_len, pred_len, simd_len; \
+                     if (CHECK_BOUNDS(nr + 4, nr + 4)) { \
+                             ret = -EFAULT; \
+                             goto out_put; \
+                     } \
+                     header_len = 4; \
+                     nr_vector = in_array[i + nr]; \
+                     vec_qwords = in_array[i + nr + 1]; \
+                     nr_pred = in_array[i + nr + 2]; \
+                     pred_qwords = in_array[i + nr + 3]; \
+                     if (check_mul_overflow(nr_vector, vec_qwords, &vec_len) || \
+                         check_mul_overflow(nr_pred, pred_qwords, &pred_len) || \
+                         check_add_overflow(vec_len, pred_len, &simd_len) || \
+                         check_add_overflow(header_len, simd_len, &simd_len) || \
+                         check_add_overflow(nr, simd_len, &nr) || \
+                         nr > max_i - i) { \
+                             ret = -EFAULT; \
+                             goto out_put; \
+                     } \
+             } \
+     } while (0)
+
      if (orig_sample_type & PERF_SAMPLE_REGS_USER) {
              u64 abi;
 
Quoted 15 lines
Quoted 5 lines
Quoted 5 lines
tools/perf/util/aslr.c +1 -0
@@ -1007,6 +1036,7 @@ static int aslr_tool__process_sample(const struct perf_tool *tool,
                              ret = -EFAULT;
                              goto out_put;
                      }
+                     CHECK_SIMD();
Quoted 8 lines

tools/perf/util/aslr.c static int aslr_tool__process_sample(const struct perf_tool *tool, · line 1094

Quoted 8 lines
tools/perf/util/aslr.c +1 -0
                      i += nr;
              }
      }
@@ -1061,6 +1091,7 @@ static int aslr_tool__process_sample(const struct perf_tool *tool,
                              ret = -EFAULT;
                              goto out_put;
                      }
+                     CHECK_SIMD();

nit: at the end of the function you could #undef CHECK_SIMD to make it more explicit that the macro only makes sense within the function.

Sure. Thanks.

Quoted 9 lines

Thanks,
Ian

Quoted 5 lines
Quoted 5 lines
tools/perf/util/aslr.c +0 -0
                      i += nr;
              }
      }

base-commit: 91b0782fc9e9d2f0a40b5256146e014802fdbb36