aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven Rostedt (Google) <rostedt@goodmis.org>2022-01-19 10:57:41 -0500
committerSteven Rostedt (Google) <rostedt@goodmis.org>2022-02-02 21:39:33 -0500
commit915e7f58eb59530412595b69e9511c5933014c0c (patch)
treef6aa9ae8c68029629362070f38fb1f64a842afc5
parent624551ee4690ea61d8cbc2edb63324768329db82 (diff)
downloadlibtracefs-915e7f58eb59530412595b69e9511c5933014c0c.tar.gz
libtracefs: Do not count CPUs beyond set size in get_affinity
If the string of CPUs has bits set that are beyond the size that the passed in cpu_set_t size can hold, do not set them. This relies on the _S version of the CPU_SET macros from not crashing if the size if too big. One would think that the _S versions would be made specifically to protect against being too big. If a CPU is set in the string but is outside the size limit of the cpu_set_t passed in, then do not add it to the count that is returned by tracefs_instance_get_affinity_set(). Link: https://lore.kernel.org/linux-trace-devel/20220119155741.1766541-5-rostedt@goodmis.org Link: https://lore.kernel.org/all/CAPpZLN4n=L-ZHCXM+LDRiQu0XwR4iCnGeCKJOuOWenkz2EhESA@mail.gmail.com/ Reported-by: Tzvetomir Stoyanov <tz.stoyanov@gmail.com> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
-rw-r--r--src/tracefs-instance.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/tracefs-instance.c b/src/tracefs-instance.c
index db51af3..1493938 100644
--- a/src/tracefs-instance.c
+++ b/src/tracefs-instance.c
@@ -1000,7 +1000,16 @@ static inline int update_cpu_set(int cpus, int cpu_set, int cpu,
return 0;
CPU_SET_S(cpu_set + cpu, set_size, set);
- return 1;
+
+ /*
+ * It is possible that the passed in set_size is not big enough
+ * to hold the cpu we just set. If that's the case, do not report
+ * it as being set.
+ *
+ * The CPU_ISSET_S() should return false if the CPU given to it
+ * is bigger than the set itself.
+ */
+ return CPU_ISSET_S(cpu_set + cpu, set_size, set) ? 1 : 0;
}
/**