Skip to content

Commit b67336e

Browse files
Maciej W. Rozyckiralfbaechle
authored andcommitted
MIPS: Validate PR_SET_FP_MODE prctl(2) requests against the ABI of the task
Fix an API loophole introduced with commit 9791554 ("MIPS,prctl: add PR_[GS]ET_FP_MODE prctl options for MIPS"), where the caller of prctl(2) is incorrectly allowed to make a change to CP0.Status.FR or CP0.Config5.FRE register bits even if CONFIG_MIPS_O32_FP64_SUPPORT has not been enabled, despite that an executable requesting the mode requested via ELF file annotation would not be allowed to run in the first place, or for n64 and n64 ABI tasks which do not have non-default modes defined at all. Add suitable checks to `mips_set_process_fp_mode' and bail out if an invalid mode change has been requested for the ABI in effect, even if the FPU hardware or emulation would otherwise allow it. Always succeed however without taking any further action if the mode requested is the same as one already in effect, regardless of whether any mode change, should it be requested, would actually be allowed for the task concerned. Signed-off-by: Maciej W. Rozycki <macro@mips.com> Fixes: 9791554 ("MIPS,prctl: add PR_[GS]ET_FP_MODE prctl options for MIPS") Reviewed-by: Paul Burton <paul.burton@mips.com> Cc: James Hogan <james.hogan@mips.com> Cc: linux-mips@linux-mips.org Cc: linux-kernel@vger.kernel.org Cc: stable@vger.kernel.org # 4.0+ Patchwork: https://patchwork.linux-mips.org/patch/17800/ Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
1 parent c8c5a3a commit b67336e

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

‎arch/mips/kernel/process.c‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,18 @@ int mips_set_process_fp_mode(struct task_struct *task, unsigned int value)
705705
struct task_struct *t;
706706
int max_users;
707707

708+
/* If nothing to change, return right away, successfully. */
709+
if (value == mips_get_process_fp_mode(task))
710+
return 0;
711+
712+
/* Only accept a mode change if 64-bit FP enabled for o32. */
713+
if (!IS_ENABLED(CONFIG_MIPS_O32_FP64_SUPPORT))
714+
return -EOPNOTSUPP;
715+
716+
/* And only for o32 tasks. */
717+
if (IS_ENABLED(CONFIG_64BIT) && !test_thread_flag(TIF_32BIT_REGS))
718+
return -EOPNOTSUPP;
719+
708720
/* Check the value is valid */
709721
if (value & ~known_bits)
710722
return -EOPNOTSUPP;

0 commit comments

Comments
 (0)