Signed-off-by: Khem Raj <raj.k...@gmail.com> --- ...oration-of-MSA-context-in-non-MSA-kernels.patch | 76 ++++++++++++++++++++++ meta/recipes-kernel/linux/linux-yocto_4.4.bb | 1 + 2 files changed, 77 insertions(+) create mode 100644 meta/recipes-kernel/linux/linux-yocto/v2-MIPS-Prevent-restoration-of-MSA-context-in-non-MSA-kernels.patch
diff --git a/meta/recipes-kernel/linux/linux-yocto/v2-MIPS-Prevent-restoration-of-MSA-context-in-non-MSA-kernels.patch b/meta/recipes-kernel/linux/linux-yocto/v2-MIPS-Prevent-restoration-of-MSA-context-in-non-MSA-kernels.patch new file mode 100644 index 0000000..8511df6 --- /dev/null +++ b/meta/recipes-kernel/linux/linux-yocto/v2-MIPS-Prevent-restoration-of-MSA-context-in-non-MSA-kernels.patch @@ -0,0 +1,76 @@ +From patchwork Thu Apr 21 17:04:53 2016 +Content-Type: text/plain; charset="utf-8" +MIME-Version: 1.0 +Content-Transfer-Encoding: 7bit +Subject: [v2] MIPS: Prevent "restoration" of MSA context in non-MSA kernels +From: Paul Burton <paul.bur...@imgtec.com> +X-Patchwork-Id: 13164 +Message-Id: <1461258293-8863-1-git-send-email-paul.bur...@imgtec.com> +To: <linux-m...@linux-mips.org>, Ralf Baechle <r...@linux-mips.org> +Cc: Michal Toman <michal.to...@imgtec.com>, + Paul Burton <paul.bur...@imgtec.com>, James Hogan <james.ho...@imgtec.com>, + "stable # v4 . 3+" <sta...@vger.kernel.org> +Date: Thu, 21 Apr 2016 18:04:53 +0100 + +If a kernel doesn't support MSA context (ie. CONFIG_CPU_HAS_MSA=n) then +it will only keep 64 bits per FP register in thread context, and the +calls to set_fpr64 in restore_msa_extcontext will overrun the end of the +FP register context into the FCSR & MSACSR values. GCC 6.x has become +smart enough to detect this & complain like so: + + arch/mips/kernel/signal.c: In function 'protected_restore_fp_context': + ./arch/mips/include/asm/processor.h:114:17: error: array subscript is above array bounds [-Werror=array-bounds] + fpr->val##width[FPR_IDX(width, idx)] = val; \ + ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~ + ./arch/mips/include/asm/processor.h:118:1: note: in expansion of macro 'BUILD_FPR_ACCESS' + BUILD_FPR_ACCESS(64) + +The only way to trigger this code to run would be for a program to set +up an artificial extended MSA context structure following a sigframe & +execute sigreturn. Whilst this doesn't allow a program to write to any +state that it couldn't already, it makes little sense to allow this +"restoration" of MSA context in a system that doesn't support MSA. + +Fix this by killing a program with SIGSYS if it tries something as crazy +as "restoring" fake MSA context in this way, also fixing the build error +& allowing for most of restore_msa_extcontext to be optimised out of +kernels without support for MSA. + +Signed-off-by: Paul Burton <paul.bur...@imgtec.com> +Reported-by: Michal Toman <michal.to...@imgtec.com> +Fixes: bf82cb30c7e5 ("MIPS: Save MSA extended context around signals") +Cc: James Hogan <james.ho...@imgtec.com> +Cc: stable <sta...@vger.kernel.org> # v4.3+ +--- + +Changes in v2: +- Prevent potential for malformed errno/signal from protected_restore_fp_context. + + arch/mips/kernel/signal.c | 7 +++++-- + 1 file changed, 5 insertions(+), 2 deletions(-) + +diff --git a/arch/mips/kernel/signal.c b/arch/mips/kernel/signal.c +index bf792e2..fc7c1f0 100644 +--- a/arch/mips/kernel/signal.c ++++ b/arch/mips/kernel/signal.c +@@ -195,6 +195,9 @@ static int restore_msa_extcontext(void __user *buf, unsigned int size) + unsigned int csr; + int i, err; + ++ if (!config_enabled(CONFIG_CPU_HAS_MSA)) ++ return SIGSYS; ++ + if (size != sizeof(*msa)) + return -EINVAL; + +@@ -398,8 +401,8 @@ int protected_restore_fp_context(void __user *sc) + } + + fp_done: +- if (used & USED_EXTCONTEXT) +- err |= restore_extcontext(sc_to_extcontext(sc)); ++ if (!err && (used & USED_EXTCONTEXT)) ++ err = restore_extcontext(sc_to_extcontext(sc)); + + return err ?: sig; + } diff --git a/meta/recipes-kernel/linux/linux-yocto_4.4.bb b/meta/recipes-kernel/linux/linux-yocto_4.4.bb index fbb592a..a55ac93 100644 --- a/meta/recipes-kernel/linux/linux-yocto_4.4.bb +++ b/meta/recipes-kernel/linux/linux-yocto_4.4.bb @@ -24,6 +24,7 @@ SRCREV_meta ?= "9ab4787fe2aea2ae0fcc31a5e067eaba19ef64c8" SRC_URI = "git://git.yoctoproject.org/linux-yocto-4.4.git;name=machine;branch=${KBRANCH}; \ git://git.yoctoproject.org/yocto-kernel-cache;type=kmeta;name=meta;branch=yocto-4.4;destsuffix=${KMETA} \ file://0001-powerpc-ptrace-Fix-out-of-bounds-array-access-warnin.patch \ + file://v2-MIPS-Prevent-restoration-of-MSA-context-in-non-MSA-kernels.patch \ " LINUX_VERSION ?= "4.4.3" -- 2.8.2 -- _______________________________________________ Openembedded-core mailing list Openembedded-core@lists.openembedded.org http://lists.openembedded.org/mailman/listinfo/openembedded-core