binfmt_elf: partially sanitize PRSTATUS_SIZE and SET_PR_FPVALID
[linux-block.git] / fs / compat_binfmt_elf.c
CommitLineData
2522fe45 1// SPDX-License-Identifier: GPL-2.0-only
2f79e48a
RM
2/*
3 * 32-bit compatibility support for ELF format executables and core dumps.
4 *
5 * Copyright (C) 2007 Red Hat, Inc. All rights reserved.
6 *
2f79e48a
RM
7 * Red Hat Author: Roland McGrath.
8 *
9 * This file is used in a 64-bit kernel that wants to support 32-bit ELF.
10 * asm/elf.h is responsible for defining the compat_* and COMPAT_* macros
11 * used below, with definitions appropriate for 32-bit ABI compatibility.
12 *
13 * We use macros to rename the ABI types and machine-dependent
14 * functions used in binfmt_elf.c to compat versions.
15 */
16
17#include <linux/elfcore-compat.h>
18#include <linux/time.h>
19
00e19cee
DM
20#define ELF_COMPAT 1
21
2f79e48a
RM
22/*
23 * Rename the basic ELF layout types to refer to the 32-bit class of files.
24 */
25#undef ELF_CLASS
26#define ELF_CLASS ELFCLASS32
27
28#undef elfhdr
29#undef elf_phdr
1fcccbac 30#undef elf_shdr
2f79e48a
RM
31#undef elf_note
32#undef elf_addr_t
00e19cee 33#undef ELF_GNU_PROPERTY_ALIGN
2f79e48a
RM
34#define elfhdr elf32_hdr
35#define elf_phdr elf32_phdr
1fcccbac 36#define elf_shdr elf32_shdr
2f79e48a
RM
37#define elf_note elf32_note
38#define elf_addr_t Elf32_Addr
00e19cee 39#define ELF_GNU_PROPERTY_ALIGN ELF32_GNU_PROPERTY_ALIGN
2f79e48a 40
49ae4d4b
DV
41/*
42 * Some data types as stored in coredump.
43 */
2aa362c4 44#define user_long_t compat_long_t
49ae4d4b 45#define user_siginfo_t compat_siginfo_t
fa4751f4 46#define copy_siginfo_to_external copy_siginfo_to_external32
49ae4d4b 47
2f79e48a
RM
48/*
49 * The machine-dependent core note format types are defined in elfcore-compat.h,
50 * which requires asm/elf.h to define compat_elf_gregset_t et al.
51 */
52#define elf_prstatus compat_elf_prstatus
53#define elf_prpsinfo compat_elf_prpsinfo
54
e2bb80d5
AB
55#undef ns_to_kernel_old_timeval
56#define ns_to_kernel_old_timeval ns_to_old_timeval32
2f79e48a
RM
57
58/*
59 * To use this file, asm/elf.h must define compat_elf_check_arch.
60 * The other following macros can be defined if the compat versions
61 * differ from the native ones, or omitted when they match.
62 */
63
64#undef ELF_ARCH
65#undef elf_check_arch
66#define elf_check_arch compat_elf_check_arch
67
68#ifdef COMPAT_ELF_PLATFORM
69#undef ELF_PLATFORM
70#define ELF_PLATFORM COMPAT_ELF_PLATFORM
71#endif
72
73#ifdef COMPAT_ELF_HWCAP
74#undef ELF_HWCAP
75#define ELF_HWCAP COMPAT_ELF_HWCAP
76#endif
77
66d6e3b3
AB
78#ifdef COMPAT_ELF_HWCAP2
79#undef ELF_HWCAP2
80#define ELF_HWCAP2 COMPAT_ELF_HWCAP2
81#endif
82
2f79e48a
RM
83#ifdef COMPAT_ARCH_DLINFO
84#undef ARCH_DLINFO
85#define ARCH_DLINFO COMPAT_ARCH_DLINFO
86#endif
87
88#ifdef COMPAT_ELF_ET_DYN_BASE
89#undef ELF_ET_DYN_BASE
90#define ELF_ET_DYN_BASE COMPAT_ELF_ET_DYN_BASE
91#endif
92
93#ifdef COMPAT_ELF_EXEC_PAGESIZE
94#undef ELF_EXEC_PAGESIZE
95#define ELF_EXEC_PAGESIZE COMPAT_ELF_EXEC_PAGESIZE
96#endif
97
8a00dd00
AV
98#ifdef COMPAT_PRSTATUS_SIZE
99#define PRSTATUS_SIZE COMPAT_PRSTATUS_SIZE
100#endif
101
102#ifdef COMPAT_SET_PR_FPVALID
103#define SET_PR_FPVALID(S) COMPAT_SET_PR_FPVALID(S)
104#endif
105
2f79e48a
RM
106#ifdef COMPAT_ELF_PLAT_INIT
107#undef ELF_PLAT_INIT
108#define ELF_PLAT_INIT COMPAT_ELF_PLAT_INIT
109#endif
110
111#ifdef COMPAT_SET_PERSONALITY
112#undef SET_PERSONALITY
113#define SET_PERSONALITY COMPAT_SET_PERSONALITY
114#endif
115
116#ifdef compat_start_thread
bc3d7bf6
GKB
117#define COMPAT_START_THREAD(ex, regs, new_ip, new_sp) \
118 compat_start_thread(regs, new_ip, new_sp)
119#endif
120
121#ifdef COMPAT_START_THREAD
122#undef START_THREAD
123#define START_THREAD COMPAT_START_THREAD
2f79e48a
RM
124#endif
125
9a29a671
GKB
126#ifdef compat_arch_setup_additional_pages
127#define COMPAT_ARCH_SETUP_ADDITIONAL_PAGES(bprm, ex, interpreter) \
128 compat_arch_setup_additional_pages(bprm, interpreter)
129#endif
130
131#ifdef COMPAT_ARCH_SETUP_ADDITIONAL_PAGES
2f79e48a
RM
132#undef ARCH_HAS_SETUP_ADDITIONAL_PAGES
133#define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
9a29a671
GKB
134#undef ARCH_SETUP_ADDITIONAL_PAGES
135#define ARCH_SETUP_ADDITIONAL_PAGES COMPAT_ARCH_SETUP_ADDITIONAL_PAGES
2f79e48a
RM
136#endif
137
6e0d6ac5
KC
138#ifdef compat_elf_read_implies_exec
139#undef elf_read_implies_exec
140#define elf_read_implies_exec compat_elf_read_implies_exec
141#endif
142
2f79e48a
RM
143/*
144 * Rename a few of the symbols that binfmt_elf.c will define.
145 * These are all local so the names don't really matter, but it
146 * might make some debugging less confusing not to duplicate them.
147 */
148#define elf_format compat_elf_format
149#define init_elf_binfmt init_compat_elf_binfmt
150#define exit_elf_binfmt exit_compat_elf_binfmt
151
152/*
153 * We share all the actual code with the native (64-bit) version.
154 */
155#include "binfmt_elf.c"