From: "Steven Rostedt (Google)" <rostedt@xxxxxxxxxxx> 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/all/CAPpZLN4n=L-ZHCXM+LDRiQu0XwR4iCnGeCKJOuOWenkz2EhESA@xxxxxxxxxxxxxx/ Reported-by: Tzvetomir Stoyanov <tz.stoyanov@xxxxxxxxx> Signed-off-by: Steven Rostedt (Google) <rostedt@xxxxxxxxxxx> --- src/tracefs-instance.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/tracefs-instance.c b/src/tracefs-instance.c index db51af3818f0..1493938fa445 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; } /** -- 2.33.0