android_kernel_xiaomi_sm8350/kernel/sched
Linus Torvalds f3359f5fc9 sched_getaffinity: don't assume 'cpumask_size()' is fully initialized
[ Upstream commit 6015b1aca1a233379625385feb01dd014aca60b5 ]

The getaffinity() system call uses 'cpumask_size()' to decide how big
the CPU mask is - so far so good.  It is indeed the allocation size of a
cpumask.

But the code also assumes that the whole allocation is initialized
without actually doing so itself.  That's wrong, because we might have
fixed-size allocations (making copying and clearing more efficient), but
not all of it is then necessarily used if 'nr_cpu_ids' is smaller.

Having checked other users of 'cpumask_size()', they all seem to be ok,
either using it purely for the allocation size, or explicitly zeroing
the cpumask before using the size in bytes to copy it.

See for example the ublk_ctrl_get_queue_affinity() function that uses
the proper 'zalloc_cpumask_var()' to make sure that the whole mask is
cleared, whether the storage is on the stack or if it was an external
allocation.

Fix this by just zeroing the allocation before using it.  Do the same
for the compat version of sched_getaffinity(), which had the same logic.

Also, for consistency, make sched_getaffinity() use 'cpumask_bits()' to
access the bits.  For a cpumask_var_t, it ends up being a pointer to the
same data either way, but it's just a good idea to treat it like you
would a 'cpumask_t'.  The compat case already did that.

Reported-by: Ryan Roberts <ryan.roberts@arm.com>
Link: https://lore.kernel.org/lkml/7d026744-6bd6-6827-0471-b5e8eae0be3f@arm.com/
Cc: Yury Norov <yury.norov@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2023-04-05 11:16:42 +02:00
..
autogroup.c
autogroup.h
clock.c
completion.c
core.c sched_getaffinity: don't assume 'cpumask_size()' is fully initialized 2023-04-05 11:16:42 +02:00
cpuacct.c
cpudeadline.c
cpudeadline.h
cpufreq_schedutil.c
cpufreq.c
cpupri.c
cpupri.h
cputime.c
deadline.c sched/deadline,rt: Remove unused parameter from pick_next_[rt|dl]_entity() 2023-03-11 16:43:35 +01:00
debug.c
fair.c sched/fair: Sanitize vruntime of entity being migrated 2023-04-05 11:16:41 +02:00
features.h
idle.c
isolation.c
loadavg.c
Makefile
membarrier.c
pelt.c
pelt.h
psi.c
rt.c sched/rt: pick_next_rt_entity(): check list_entry 2023-03-11 16:43:35 +01:00
sched-pelt.h
sched.h
stats.c
stats.h
stop_task.c
swait.c
topology.c
wait_bit.c
wait.c