xref: /linux/arch/s390/kernel/machine_kexec_file.c (revision 865e2acd)
171406883SPhilipp Rudo // SPDX-License-Identifier: GPL-2.0
271406883SPhilipp Rudo /*
371406883SPhilipp Rudo  * s390 code for kexec_file_load system call
471406883SPhilipp Rudo  *
571406883SPhilipp Rudo  * Copyright IBM Corp. 2018
671406883SPhilipp Rudo  *
771406883SPhilipp Rudo  * Author(s): Philipp Rudo <prudo@linux.vnet.ibm.com>
871406883SPhilipp Rudo  */
971406883SPhilipp Rudo 
10edce10eeSPhilipp Rudo #define pr_fmt(fmt)	"kexec: " fmt
11edce10eeSPhilipp Rudo 
1271406883SPhilipp Rudo #include <linux/elf.h>
13e23a8020SPhilipp Rudo #include <linux/errno.h>
1471406883SPhilipp Rudo #include <linux/kexec.h>
15c8424e77SThiago Jung Bauermann #include <linux/module_signature.h>
16e23a8020SPhilipp Rudo #include <linux/verification.h>
174aa93405SBaoquan He #include <linux/vmalloc.h>
1899feaa71SPhilipp Rudo #include <asm/boot_data.h>
19e23a8020SPhilipp Rudo #include <asm/ipl.h>
2071406883SPhilipp Rudo #include <asm/setup.h>
2171406883SPhilipp Rudo 
2271406883SPhilipp Rudo const struct kexec_file_ops * const kexec_file_loaders[] = {
238be01882SPhilipp Rudo 	&s390_kexec_elf_ops,
24e49bb0a2SPhilipp Rudo 	&s390_kexec_image_ops,
2571406883SPhilipp Rudo 	NULL,
2671406883SPhilipp Rudo };
2771406883SPhilipp Rudo 
2899d5cadfSJiri Bohac #ifdef CONFIG_KEXEC_SIG
s390_verify_sig(const char * kernel,unsigned long kernel_len)29e23a8020SPhilipp Rudo int s390_verify_sig(const char *kernel, unsigned long kernel_len)
30e23a8020SPhilipp Rudo {
31e23a8020SPhilipp Rudo 	const unsigned long marker_len = sizeof(MODULE_SIG_STRING) - 1;
32e23a8020SPhilipp Rudo 	struct module_signature *ms;
33e23a8020SPhilipp Rudo 	unsigned long sig_len;
340828c4a3SMichal Suchanek 	int ret;
35e23a8020SPhilipp Rudo 
36e23a8020SPhilipp Rudo 	/* Skip signature verification when not secure IPLed. */
37e23a8020SPhilipp Rudo 	if (!ipl_secure_flag)
38e23a8020SPhilipp Rudo 		return 0;
39e23a8020SPhilipp Rudo 
40e23a8020SPhilipp Rudo 	if (marker_len > kernel_len)
41e23a8020SPhilipp Rudo 		return -EKEYREJECTED;
42e23a8020SPhilipp Rudo 
43e23a8020SPhilipp Rudo 	if (memcmp(kernel + kernel_len - marker_len, MODULE_SIG_STRING,
44e23a8020SPhilipp Rudo 		   marker_len))
45e23a8020SPhilipp Rudo 		return -EKEYREJECTED;
46e23a8020SPhilipp Rudo 	kernel_len -= marker_len;
47e23a8020SPhilipp Rudo 
48e23a8020SPhilipp Rudo 	ms = (void *)kernel + kernel_len - sizeof(*ms);
49e23a8020SPhilipp Rudo 	kernel_len -= sizeof(*ms);
50e23a8020SPhilipp Rudo 
51e23a8020SPhilipp Rudo 	sig_len = be32_to_cpu(ms->sig_len);
52e23a8020SPhilipp Rudo 	if (sig_len >= kernel_len)
53e23a8020SPhilipp Rudo 		return -EKEYREJECTED;
54e23a8020SPhilipp Rudo 	kernel_len -= sig_len;
55e23a8020SPhilipp Rudo 
56e23a8020SPhilipp Rudo 	if (ms->id_type != PKEY_ID_PKCS7)
57e23a8020SPhilipp Rudo 		return -EKEYREJECTED;
58e23a8020SPhilipp Rudo 
59e23a8020SPhilipp Rudo 	if (ms->algo != 0 ||
60e23a8020SPhilipp Rudo 	    ms->hash != 0 ||
61e23a8020SPhilipp Rudo 	    ms->signer_len != 0 ||
62e23a8020SPhilipp Rudo 	    ms->key_id_len != 0 ||
63e23a8020SPhilipp Rudo 	    ms->__pad[0] != 0 ||
64e23a8020SPhilipp Rudo 	    ms->__pad[1] != 0 ||
65e23a8020SPhilipp Rudo 	    ms->__pad[2] != 0) {
66e23a8020SPhilipp Rudo 		return -EBADMSG;
67e23a8020SPhilipp Rudo 	}
68e23a8020SPhilipp Rudo 
690828c4a3SMichal Suchanek 	ret = verify_pkcs7_signature(kernel, kernel_len,
700828c4a3SMichal Suchanek 				     kernel + kernel_len, sig_len,
710828c4a3SMichal Suchanek 				     VERIFY_USE_SECONDARY_KEYRING,
720828c4a3SMichal Suchanek 				     VERIFYING_MODULE_SIGNATURE,
730828c4a3SMichal Suchanek 				     NULL, NULL);
740828c4a3SMichal Suchanek 	if (ret == -ENOKEY && IS_ENABLED(CONFIG_INTEGRITY_PLATFORM_KEYRING))
750828c4a3SMichal Suchanek 		ret = verify_pkcs7_signature(kernel, kernel_len,
76e23a8020SPhilipp Rudo 					     kernel + kernel_len, sig_len,
77e23a8020SPhilipp Rudo 					     VERIFY_USE_PLATFORM_KEYRING,
78e23a8020SPhilipp Rudo 					     VERIFYING_MODULE_SIGNATURE,
79e23a8020SPhilipp Rudo 					     NULL, NULL);
800828c4a3SMichal Suchanek 	return ret;
81e23a8020SPhilipp Rudo }
8299d5cadfSJiri Bohac #endif /* CONFIG_KEXEC_SIG */
83e23a8020SPhilipp Rudo 
kexec_file_update_purgatory(struct kimage * image,struct s390_load_data * data)84653beba2SPhilipp Rudo static int kexec_file_update_purgatory(struct kimage *image,
85653beba2SPhilipp Rudo 				       struct s390_load_data *data)
86e49bb0a2SPhilipp Rudo {
87e49bb0a2SPhilipp Rudo 	u64 entry, type;
88e49bb0a2SPhilipp Rudo 	int ret;
89e49bb0a2SPhilipp Rudo 
90ee337f54SPhilipp Rudo 	if (image->type == KEXEC_TYPE_CRASH) {
91ee337f54SPhilipp Rudo 		entry = STARTUP_KDUMP_OFFSET;
92ee337f54SPhilipp Rudo 		type = KEXEC_TYPE_CRASH;
93ee337f54SPhilipp Rudo 	} else {
94e49bb0a2SPhilipp Rudo 		entry = STARTUP_NORMAL_OFFSET;
95ee337f54SPhilipp Rudo 		type = KEXEC_TYPE_DEFAULT;
96ee337f54SPhilipp Rudo 	}
97ee337f54SPhilipp Rudo 
98e49bb0a2SPhilipp Rudo 	ret = kexec_purgatory_get_set_symbol(image, "kernel_entry", &entry,
99e49bb0a2SPhilipp Rudo 					     sizeof(entry), false);
100ee337f54SPhilipp Rudo 	if (ret)
101ee337f54SPhilipp Rudo 		return ret;
102ee337f54SPhilipp Rudo 
103ee337f54SPhilipp Rudo 	ret = kexec_purgatory_get_set_symbol(image, "kernel_type", &type,
104ee337f54SPhilipp Rudo 					     sizeof(type), false);
105ee337f54SPhilipp Rudo 	if (ret)
106ee337f54SPhilipp Rudo 		return ret;
107ee337f54SPhilipp Rudo 
108*865e2acdSBaoquan He #ifdef CONFIG_CRASH_DUMP
109ee337f54SPhilipp Rudo 	if (image->type == KEXEC_TYPE_CRASH) {
110ee337f54SPhilipp Rudo 		u64 crash_size;
111ee337f54SPhilipp Rudo 
112ee337f54SPhilipp Rudo 		ret = kexec_purgatory_get_set_symbol(image, "crash_start",
113ee337f54SPhilipp Rudo 						     &crashk_res.start,
114ee337f54SPhilipp Rudo 						     sizeof(crashk_res.start),
115ee337f54SPhilipp Rudo 						     false);
116ee337f54SPhilipp Rudo 		if (ret)
117ee337f54SPhilipp Rudo 			return ret;
118ee337f54SPhilipp Rudo 
119ee337f54SPhilipp Rudo 		crash_size = crashk_res.end - crashk_res.start + 1;
120ee337f54SPhilipp Rudo 		ret = kexec_purgatory_get_set_symbol(image, "crash_size",
121ee337f54SPhilipp Rudo 						     &crash_size,
122ee337f54SPhilipp Rudo 						     sizeof(crash_size),
123ee337f54SPhilipp Rudo 						     false);
124ee337f54SPhilipp Rudo 	}
125*865e2acdSBaoquan He #endif
126e49bb0a2SPhilipp Rudo 	return ret;
127e49bb0a2SPhilipp Rudo }
128e49bb0a2SPhilipp Rudo 
kexec_file_add_purgatory(struct kimage * image,struct s390_load_data * data)1298e496426SPhilipp Rudo static int kexec_file_add_purgatory(struct kimage *image,
1308e496426SPhilipp Rudo 				    struct s390_load_data *data)
131e49bb0a2SPhilipp Rudo {
132e49bb0a2SPhilipp Rudo 	struct kexec_buf buf;
133e49bb0a2SPhilipp Rudo 	int ret;
134e49bb0a2SPhilipp Rudo 
135e49bb0a2SPhilipp Rudo 	buf.image = image;
136e49bb0a2SPhilipp Rudo 
137e49bb0a2SPhilipp Rudo 	data->memsz = ALIGN(data->memsz, PAGE_SIZE);
138e49bb0a2SPhilipp Rudo 	buf.mem = data->memsz;
139*865e2acdSBaoquan He #ifdef CONFIG_CRASH_DUMP
140ee337f54SPhilipp Rudo 	if (image->type == KEXEC_TYPE_CRASH)
141ee337f54SPhilipp Rudo 		buf.mem += crashk_res.start;
142*865e2acdSBaoquan He #endif
143e49bb0a2SPhilipp Rudo 
144e49bb0a2SPhilipp Rudo 	ret = kexec_load_purgatory(image, &buf);
145e49bb0a2SPhilipp Rudo 	if (ret)
146e49bb0a2SPhilipp Rudo 		return ret;
14799feaa71SPhilipp Rudo 	data->memsz += buf.memsz;
148e49bb0a2SPhilipp Rudo 
14999feaa71SPhilipp Rudo 	return kexec_file_update_purgatory(image, data);
150e49bb0a2SPhilipp Rudo }
151e49bb0a2SPhilipp Rudo 
kexec_file_add_initrd(struct kimage * image,struct s390_load_data * data)1528e496426SPhilipp Rudo static int kexec_file_add_initrd(struct kimage *image,
1538e496426SPhilipp Rudo 				 struct s390_load_data *data)
154e49bb0a2SPhilipp Rudo {
155e49bb0a2SPhilipp Rudo 	struct kexec_buf buf;
156e49bb0a2SPhilipp Rudo 	int ret;
157e49bb0a2SPhilipp Rudo 
158e49bb0a2SPhilipp Rudo 	buf.image = image;
159e49bb0a2SPhilipp Rudo 
1608e496426SPhilipp Rudo 	buf.buffer = image->initrd_buf;
1618e496426SPhilipp Rudo 	buf.bufsz = image->initrd_buf_len;
162e49bb0a2SPhilipp Rudo 
163e49bb0a2SPhilipp Rudo 	data->memsz = ALIGN(data->memsz, PAGE_SIZE);
164e49bb0a2SPhilipp Rudo 	buf.mem = data->memsz;
165*865e2acdSBaoquan He #ifdef CONFIG_CRASH_DUMP
166ee337f54SPhilipp Rudo 	if (image->type == KEXEC_TYPE_CRASH)
167ee337f54SPhilipp Rudo 		buf.mem += crashk_res.start;
168*865e2acdSBaoquan He #endif
169e49bb0a2SPhilipp Rudo 	buf.memsz = buf.bufsz;
170e49bb0a2SPhilipp Rudo 
17170b69054SPhilipp Rudo 	data->parm->initrd_start = data->memsz;
172d0d249d7SPhilipp Rudo 	data->parm->initrd_size = buf.memsz;
173e49bb0a2SPhilipp Rudo 	data->memsz += buf.memsz;
174e49bb0a2SPhilipp Rudo 
175e49bb0a2SPhilipp Rudo 	ret = kexec_add_buffer(&buf);
17699feaa71SPhilipp Rudo 	if (ret)
177e49bb0a2SPhilipp Rudo 		return ret;
17899feaa71SPhilipp Rudo 
17999feaa71SPhilipp Rudo 	return ipl_report_add_component(data->report, &buf, 0, 0);
18099feaa71SPhilipp Rudo }
18199feaa71SPhilipp Rudo 
kexec_file_add_ipl_report(struct kimage * image,struct s390_load_data * data)18299feaa71SPhilipp Rudo static int kexec_file_add_ipl_report(struct kimage *image,
18399feaa71SPhilipp Rudo 				     struct s390_load_data *data)
18499feaa71SPhilipp Rudo {
18599feaa71SPhilipp Rudo 	__u32 *lc_ipl_parmblock_ptr;
18699feaa71SPhilipp Rudo 	unsigned int len, ncerts;
18799feaa71SPhilipp Rudo 	struct kexec_buf buf;
18899feaa71SPhilipp Rudo 	unsigned long addr;
18999feaa71SPhilipp Rudo 	void *ptr, *end;
19020c76e24SHeiko Carstens 	int ret;
19199feaa71SPhilipp Rudo 
19299feaa71SPhilipp Rudo 	buf.image = image;
19399feaa71SPhilipp Rudo 
19499feaa71SPhilipp Rudo 	data->memsz = ALIGN(data->memsz, PAGE_SIZE);
19599feaa71SPhilipp Rudo 	buf.mem = data->memsz;
19699feaa71SPhilipp Rudo 
197979fe44aSAlexander Gordeev 	ptr = __va(ipl_cert_list_addr);
19899feaa71SPhilipp Rudo 	end = ptr + ipl_cert_list_size;
19999feaa71SPhilipp Rudo 	ncerts = 0;
20099feaa71SPhilipp Rudo 	while (ptr < end) {
20199feaa71SPhilipp Rudo 		ncerts++;
20299feaa71SPhilipp Rudo 		len = *(unsigned int *)ptr;
20399feaa71SPhilipp Rudo 		ptr += sizeof(len);
20499feaa71SPhilipp Rudo 		ptr += len;
20599feaa71SPhilipp Rudo 	}
20699feaa71SPhilipp Rudo 
20799feaa71SPhilipp Rudo 	addr = data->memsz + data->report->size;
20899feaa71SPhilipp Rudo 	addr += ncerts * sizeof(struct ipl_rb_certificate_entry);
209979fe44aSAlexander Gordeev 	ptr = __va(ipl_cert_list_addr);
21099feaa71SPhilipp Rudo 	while (ptr < end) {
21199feaa71SPhilipp Rudo 		len = *(unsigned int *)ptr;
21299feaa71SPhilipp Rudo 		ptr += sizeof(len);
21399feaa71SPhilipp Rudo 		ipl_report_add_certificate(data->report, ptr, addr, len);
21499feaa71SPhilipp Rudo 		addr += len;
21599feaa71SPhilipp Rudo 		ptr += len;
21699feaa71SPhilipp Rudo 	}
21799feaa71SPhilipp Rudo 
21820c76e24SHeiko Carstens 	ret = -ENOMEM;
21999feaa71SPhilipp Rudo 	buf.buffer = ipl_report_finish(data->report);
22020c76e24SHeiko Carstens 	if (!buf.buffer)
22120c76e24SHeiko Carstens 		goto out;
22299feaa71SPhilipp Rudo 	buf.bufsz = data->report->size;
22399feaa71SPhilipp Rudo 	buf.memsz = buf.bufsz;
2244aa93405SBaoquan He 	image->arch.ipl_buf = buf.buffer;
22599feaa71SPhilipp Rudo 
22699feaa71SPhilipp Rudo 	data->memsz += buf.memsz;
22799feaa71SPhilipp Rudo 
22899feaa71SPhilipp Rudo 	lc_ipl_parmblock_ptr =
22999feaa71SPhilipp Rudo 		data->kernel_buf + offsetof(struct lowcore, ipl_parmblock_ptr);
23099feaa71SPhilipp Rudo 	*lc_ipl_parmblock_ptr = (__u32)buf.mem;
23199feaa71SPhilipp Rudo 
232*865e2acdSBaoquan He #ifdef CONFIG_CRASH_DUMP
233c2337a40SAlexander Egorenkov 	if (image->type == KEXEC_TYPE_CRASH)
234c2337a40SAlexander Egorenkov 		buf.mem += crashk_res.start;
235*865e2acdSBaoquan He #endif
236c2337a40SAlexander Egorenkov 
23720c76e24SHeiko Carstens 	ret = kexec_add_buffer(&buf);
23820c76e24SHeiko Carstens out:
23920c76e24SHeiko Carstens 	return ret;
240e49bb0a2SPhilipp Rudo }
241e49bb0a2SPhilipp Rudo 
kexec_file_add_components(struct kimage * image,int (* add_kernel)(struct kimage * image,struct s390_load_data * data))2428e496426SPhilipp Rudo void *kexec_file_add_components(struct kimage *image,
2438e496426SPhilipp Rudo 				int (*add_kernel)(struct kimage *image,
2448e496426SPhilipp Rudo 						  struct s390_load_data *data))
2458e496426SPhilipp Rudo {
2465ecb2da6SSven Schnelle 	unsigned long max_command_line_size = LEGACY_COMMAND_LINE_SIZE;
2478e496426SPhilipp Rudo 	struct s390_load_data data = {0};
2485ecb2da6SSven Schnelle 	unsigned long minsize;
2498e496426SPhilipp Rudo 	int ret;
2508e496426SPhilipp Rudo 
25199feaa71SPhilipp Rudo 	data.report = ipl_report_init(&ipl_block);
25299feaa71SPhilipp Rudo 	if (IS_ERR(data.report))
25399feaa71SPhilipp Rudo 		return data.report;
25499feaa71SPhilipp Rudo 
2558e496426SPhilipp Rudo 	ret = add_kernel(image, &data);
2568e496426SPhilipp Rudo 	if (ret)
25799feaa71SPhilipp Rudo 		goto out;
2588e496426SPhilipp Rudo 
25999feaa71SPhilipp Rudo 	ret = -EINVAL;
2605ecb2da6SSven Schnelle 	minsize = PARMAREA + offsetof(struct parmarea, command_line);
2615ecb2da6SSven Schnelle 	if (image->kernel_buf_len < minsize)
26299feaa71SPhilipp Rudo 		goto out;
2635ecb2da6SSven Schnelle 
2645ecb2da6SSven Schnelle 	if (data.parm->max_command_line_size)
2655ecb2da6SSven Schnelle 		max_command_line_size = data.parm->max_command_line_size;
2665ecb2da6SSven Schnelle 
2675ecb2da6SSven Schnelle 	if (minsize + max_command_line_size < minsize)
2685ecb2da6SSven Schnelle 		goto out;
2695ecb2da6SSven Schnelle 
2705ecb2da6SSven Schnelle 	if (image->kernel_buf_len < minsize + max_command_line_size)
2715ecb2da6SSven Schnelle 		goto out;
2725ecb2da6SSven Schnelle 
2735ecb2da6SSven Schnelle 	if (image->cmdline_buf_len >= max_command_line_size)
2745ecb2da6SSven Schnelle 		goto out;
2755ecb2da6SSven Schnelle 
2768e496426SPhilipp Rudo 	memcpy(data.parm->command_line, image->cmdline_buf,
2778e496426SPhilipp Rudo 	       image->cmdline_buf_len);
2788e496426SPhilipp Rudo 
279*865e2acdSBaoquan He #ifdef CONFIG_CRASH_DUMP
2808e496426SPhilipp Rudo 	if (image->type == KEXEC_TYPE_CRASH) {
2818e496426SPhilipp Rudo 		data.parm->oldmem_base = crashk_res.start;
2828e496426SPhilipp Rudo 		data.parm->oldmem_size = crashk_res.end - crashk_res.start + 1;
2838e496426SPhilipp Rudo 	}
284*865e2acdSBaoquan He #endif
2858e496426SPhilipp Rudo 
2868e496426SPhilipp Rudo 	if (image->initrd_buf) {
2878e496426SPhilipp Rudo 		ret = kexec_file_add_initrd(image, &data);
2888e496426SPhilipp Rudo 		if (ret)
28999feaa71SPhilipp Rudo 			goto out;
2908e496426SPhilipp Rudo 	}
2918e496426SPhilipp Rudo 
2928e496426SPhilipp Rudo 	ret = kexec_file_add_purgatory(image, &data);
2938e496426SPhilipp Rudo 	if (ret)
29499feaa71SPhilipp Rudo 		goto out;
2958e496426SPhilipp Rudo 
296653beba2SPhilipp Rudo 	if (data.kernel_mem == 0) {
297653beba2SPhilipp Rudo 		unsigned long restart_psw =  0x0008000080000000UL;
298653beba2SPhilipp Rudo 		restart_psw += image->start;
299653beba2SPhilipp Rudo 		memcpy(data.kernel_buf, &restart_psw, sizeof(restart_psw));
300653beba2SPhilipp Rudo 		image->start = 0;
301653beba2SPhilipp Rudo 	}
302653beba2SPhilipp Rudo 
30399feaa71SPhilipp Rudo 	ret = kexec_file_add_ipl_report(image, &data);
30499feaa71SPhilipp Rudo out:
30599feaa71SPhilipp Rudo 	ipl_report_free(data.report);
30699feaa71SPhilipp Rudo 	return ERR_PTR(ret);
3078e496426SPhilipp Rudo }
3088e496426SPhilipp Rudo 
arch_kexec_apply_relocations_add(struct purgatory_info * pi,Elf_Shdr * section,const Elf_Shdr * relsec,const Elf_Shdr * symtab)30971406883SPhilipp Rudo int arch_kexec_apply_relocations_add(struct purgatory_info *pi,
31071406883SPhilipp Rudo 				     Elf_Shdr *section,
31171406883SPhilipp Rudo 				     const Elf_Shdr *relsec,
31271406883SPhilipp Rudo 				     const Elf_Shdr *symtab)
31371406883SPhilipp Rudo {
314edce10eeSPhilipp Rudo 	const char *strtab, *name, *shstrtab;
315edce10eeSPhilipp Rudo 	const Elf_Shdr *sechdrs;
31671406883SPhilipp Rudo 	Elf_Rela *relas;
317805bc0bcSGerald Schaefer 	int i, r_type;
31841967a37SPhilipp Rudo 	int ret;
31971406883SPhilipp Rudo 
320edce10eeSPhilipp Rudo 	/* String & section header string table */
321edce10eeSPhilipp Rudo 	sechdrs = (void *)pi->ehdr + pi->ehdr->e_shoff;
322edce10eeSPhilipp Rudo 	strtab = (char *)pi->ehdr + sechdrs[symtab->sh_link].sh_offset;
323edce10eeSPhilipp Rudo 	shstrtab = (char *)pi->ehdr + sechdrs[pi->ehdr->e_shstrndx].sh_offset;
324edce10eeSPhilipp Rudo 
32571406883SPhilipp Rudo 	relas = (void *)pi->ehdr + relsec->sh_offset;
32671406883SPhilipp Rudo 
32771406883SPhilipp Rudo 	for (i = 0; i < relsec->sh_size / sizeof(*relas); i++) {
32871406883SPhilipp Rudo 		const Elf_Sym *sym;	/* symbol to relocate */
32971406883SPhilipp Rudo 		unsigned long addr;	/* final location after relocation */
33071406883SPhilipp Rudo 		unsigned long val;	/* relocated symbol value */
33171406883SPhilipp Rudo 		void *loc;		/* tmp location to modify */
33271406883SPhilipp Rudo 
33371406883SPhilipp Rudo 		sym = (void *)pi->ehdr + symtab->sh_offset;
33471406883SPhilipp Rudo 		sym += ELF64_R_SYM(relas[i].r_info);
33571406883SPhilipp Rudo 
336edce10eeSPhilipp Rudo 		if (sym->st_name)
337edce10eeSPhilipp Rudo 			name = strtab + sym->st_name;
338edce10eeSPhilipp Rudo 		else
339edce10eeSPhilipp Rudo 			name = shstrtab + sechdrs[sym->st_shndx].sh_name;
34071406883SPhilipp Rudo 
341edce10eeSPhilipp Rudo 		if (sym->st_shndx == SHN_UNDEF) {
342edce10eeSPhilipp Rudo 			pr_err("Undefined symbol: %s\n", name);
34371406883SPhilipp Rudo 			return -ENOEXEC;
344edce10eeSPhilipp Rudo 		}
345edce10eeSPhilipp Rudo 
346edce10eeSPhilipp Rudo 		if (sym->st_shndx == SHN_COMMON) {
347edce10eeSPhilipp Rudo 			pr_err("symbol '%s' in common section\n", name);
348edce10eeSPhilipp Rudo 			return -ENOEXEC;
349edce10eeSPhilipp Rudo 		}
35071406883SPhilipp Rudo 
35171406883SPhilipp Rudo 		if (sym->st_shndx >= pi->ehdr->e_shnum &&
352edce10eeSPhilipp Rudo 		    sym->st_shndx != SHN_ABS) {
353edce10eeSPhilipp Rudo 			pr_err("Invalid section %d for symbol %s\n",
354edce10eeSPhilipp Rudo 			       sym->st_shndx, name);
35571406883SPhilipp Rudo 			return -ENOEXEC;
356edce10eeSPhilipp Rudo 		}
35771406883SPhilipp Rudo 
35871406883SPhilipp Rudo 		loc = pi->purgatory_buf;
35971406883SPhilipp Rudo 		loc += section->sh_offset;
36071406883SPhilipp Rudo 		loc += relas[i].r_offset;
36171406883SPhilipp Rudo 
36271406883SPhilipp Rudo 		val = sym->st_value;
36371406883SPhilipp Rudo 		if (sym->st_shndx != SHN_ABS)
36471406883SPhilipp Rudo 			val += pi->sechdrs[sym->st_shndx].sh_addr;
36571406883SPhilipp Rudo 		val += relas[i].r_addend;
36671406883SPhilipp Rudo 
36771406883SPhilipp Rudo 		addr = section->sh_addr + relas[i].r_offset;
36871406883SPhilipp Rudo 
369805bc0bcSGerald Schaefer 		r_type = ELF64_R_TYPE(relas[i].r_info);
370abf0e8e4SAlexander Egorenkov 
371abf0e8e4SAlexander Egorenkov 		if (r_type == R_390_PLT32DBL)
372abf0e8e4SAlexander Egorenkov 			r_type = R_390_PC32DBL;
373abf0e8e4SAlexander Egorenkov 
37441967a37SPhilipp Rudo 		ret = arch_kexec_do_relocs(r_type, loc, val, addr);
37541967a37SPhilipp Rudo 		if (ret) {
37641967a37SPhilipp Rudo 			pr_err("Unknown rela relocation: %d\n", r_type);
37741967a37SPhilipp Rudo 			return -ENOEXEC;
37841967a37SPhilipp Rudo 		}
37971406883SPhilipp Rudo 	}
38071406883SPhilipp Rudo 	return 0;
38171406883SPhilipp Rudo }
3824aa93405SBaoquan He 
arch_kimage_file_post_load_cleanup(struct kimage * image)3834aa93405SBaoquan He int arch_kimage_file_post_load_cleanup(struct kimage *image)
3844aa93405SBaoquan He {
3854aa93405SBaoquan He 	vfree(image->arch.ipl_buf);
3864aa93405SBaoquan He 	image->arch.ipl_buf = NULL;
3874aa93405SBaoquan He 
3884aa93405SBaoquan He 	return kexec_image_post_load_cleanup_default(image);
3894aa93405SBaoquan He }
390