[PATCH 0/7] ARM: support THREAD_INFO_IN_TASK (v3)

From: Keith Packard
Date: Tue Sep 07 2021 - 18:01:03 EST


Placing thread_info in the kernel stack leaves it vulnerable to stack
overflow attacks. This short series addresses that by using the
existing THREAD_INFO_IN_TASK infrastructure.

This is the third version of this series, in this version the changes
are restricted to hardware which provides the TPIDRPRW register. This
register is repurposed from holding the per_cpu_offset value to
holding the 'current' value as that allows fetching this value
atomically so that it can be used in a preemptable context.

The series is broken into seven pieces:

1) Change the secondary_start_kernel API to receive the cpu
number. This avoids needing to be able to find this value independently in
future patches.

2) Change the secondary_start_kernel API to also receive the 'task'
value. Passing the value to this function also avoids needing to
be able to discover it independently.

3) A cleanup which avoids assuming that THREAD_INFO_IN_TASK is not set.

4) A hack, borrowed from the powerpc arch, which allows locating the 'cpu'
field in either thread_info or task_struct, without requiring linux/sched.h
to be included in asm/smp.h

5) Disable the optimization storing per_cpu_offset in TPIDRPRW. This leaves
the register free to hold 'current' instead.

6) Use TPIDRPRW for 'current'. This is enabled for either CPU_V6K or CPU_V7,
but not if CPU_V6 is also enabled.

7) Enable THREAD_INFO_IN_TASK whenever TPIDRPRW is used to hold 'current'.

Signed-off-by: Keith Packard <keithpac@xxxxxxxxxx>