]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/3.18.85/mips-fix-an-n32-core-file-generation-regset-support-regression.patch
4.9-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 3.18.85 / mips-fix-an-n32-core-file-generation-regset-support-regression.patch
1 From 547da673173de51f73887377eb275304775064ad Mon Sep 17 00:00:00 2001
2 From: "Maciej W. Rozycki" <macro@mips.com>
3 Date: Tue, 7 Nov 2017 19:09:20 +0000
4 Subject: MIPS: Fix an n32 core file generation regset support regression
5
6 From: Maciej W. Rozycki <macro@mips.com>
7
8 commit 547da673173de51f73887377eb275304775064ad upstream.
9
10 Fix a commit 7aeb753b5353 ("MIPS: Implement task_user_regset_view.")
11 regression, then activated by commit 6a9c001b7ec3 ("MIPS: Switch ELF
12 core dumper to use regsets.)", that caused n32 processes to dump o32
13 core files by failing to set the EF_MIPS_ABI2 flag in the ELF core file
14 header's `e_flags' member:
15
16 $ file tls-core
17 tls-core: ELF 32-bit MSB executable, MIPS, N32 MIPS64 rel2 version 1 (SYSV), [...]
18 $ ./tls-core
19 Aborted (core dumped)
20 $ file core
21 core: ELF 32-bit MSB core file MIPS, MIPS-I version 1 (SYSV), SVR4-style
22 $
23
24 Previously the flag was set as the result of a:
25
26 statement placed in arch/mips/kernel/binfmt_elfn32.c, however in the
27 regset case, i.e. when CORE_DUMP_USE_REGSET is set, ELF_CORE_EFLAGS is
28 no longer used by `fill_note_info' in fs/binfmt_elf.c, and instead the
29 `->e_flags' member of the regset view chosen is. We have the views
30 defined in arch/mips/kernel/ptrace.c, however only an o32 and an n64
31 one, and the latter is used for n32 as well. Consequently an o32 core
32 file is incorrectly dumped from n32 processes (the ELF32 vs ELF64 class
33 is chosen elsewhere, and the 32-bit one is correctly selected for n32).
34
35 Correct the issue then by defining an n32 regset view and using it as
36 appropriate. Issue discovered in GDB testing.
37
38 Fixes: 7aeb753b5353 ("MIPS: Implement task_user_regset_view.")
39 Signed-off-by: Maciej W. Rozycki <macro@mips.com>
40 Cc: Ralf Baechle <ralf@linux-mips.org>
41 Cc: Djordje Todorovic <djordje.todorovic@rt-rk.com>
42 Cc: linux-mips@linux-mips.org
43 Patchwork: https://patchwork.linux-mips.org/patch/17617/
44 Signed-off-by: James Hogan <jhogan@kernel.org>
45 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
46
47 ---
48 arch/mips/kernel/ptrace.c | 17 +++++++++++++++++
49 1 file changed, 17 insertions(+)
50
51 --- a/arch/mips/kernel/ptrace.c
52 +++ b/arch/mips/kernel/ptrace.c
53 @@ -522,6 +522,19 @@ static const struct user_regset_view use
54 .n = ARRAY_SIZE(mips64_regsets),
55 };
56
57 +#ifdef CONFIG_MIPS32_N32
58 +
59 +static const struct user_regset_view user_mipsn32_view = {
60 + .name = "mipsn32",
61 + .e_flags = EF_MIPS_ABI2,
62 + .e_machine = ELF_ARCH,
63 + .ei_osabi = ELF_OSABI,
64 + .regsets = mips64_regsets,
65 + .n = ARRAY_SIZE(mips64_regsets),
66 +};
67 +
68 +#endif /* CONFIG_MIPS32_N32 */
69 +
70 #endif /* CONFIG_64BIT */
71
72 const struct user_regset_view *task_user_regset_view(struct task_struct *task)
73 @@ -533,6 +546,10 @@ const struct user_regset_view *task_user
74 if (test_tsk_thread_flag(task, TIF_32BIT_REGS))
75 return &user_mips_view;
76 #endif
77 +#ifdef CONFIG_MIPS32_N32
78 + if (test_tsk_thread_flag(task, TIF_32BIT_ADDR))
79 + return &user_mipsn32_view;
80 +#endif
81 return &user_mips64_view;
82 #endif
83 }