summaryrefslogtreecommitdiffstats
path: root/kernel/kexec_file.c
diff options
context:
space:
mode:
authorXunlei Pang <xlpang@redhat.com>2016-05-23 19:24:10 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2016-05-23 20:04:14 -0400
commit9b492cf58077a0254eb4b9574029ac6e79add9f9 (patch)
tree7f723acccb7706d1c38aa4573f469d5b633cf20c /kernel/kexec_file.c
parent9eb8a659dea694b0dcbd6287f6b1fbdc523b80bc (diff)
kexec: introduce a protection mechanism for the crashkernel reserved memory
For the cases that some kernel (module) path stamps the crash reserved memory(already mapped by the kernel) where has been loaded the second kernel data, the kdump kernel will probably fail to boot when panic happens (or even not happens) leaving the culprit at large, this is unacceptable. The patch introduces a mechanism for detecting such cases: 1) After each crash kexec loading, it simply marks the reserved memory regions readonly since we no longer access it after that. When someone stamps the region, the first kernel will panic and trigger the kdump. The weak arch_kexec_protect_crashkres() is introduced to do the actual protection. 2) To allow multiple loading, once 1) was done we also need to remark the reserved memory to readwrite each time a system call related to kdump is made. The weak arch_kexec_unprotect_crashkres() is introduced to do the actual protection. The architecture can make its specific implementation by overriding arch_kexec_protect_crashkres() and arch_kexec_unprotect_crashkres(). Signed-off-by: Xunlei Pang <xlpang@redhat.com> Cc: Eric Biederman <ebiederm@xmission.com> Cc: Dave Young <dyoung@redhat.com> Cc: Minfei Huang <mhuang@redhat.com> Cc: Vivek Goyal <vgoyal@redhat.com> Cc: Baoquan He <bhe@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'kernel/kexec_file.c')
-rw-r--r--kernel/kexec_file.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c
index c72d2ff5896e..503bc2d348e5 100644
--- a/kernel/kexec_file.c
+++ b/kernel/kexec_file.c
@@ -274,8 +274,11 @@ SYSCALL_DEFINE5(kexec_file_load, int, kernel_fd, int, initrd_fd,
274 return -EBUSY; 274 return -EBUSY;
275 275
276 dest_image = &kexec_image; 276 dest_image = &kexec_image;
277 if (flags & KEXEC_FILE_ON_CRASH) 277 if (flags & KEXEC_FILE_ON_CRASH) {
278 dest_image = &kexec_crash_image; 278 dest_image = &kexec_crash_image;
279 if (kexec_crash_image)
280 arch_kexec_unprotect_crashkres();
281 }
279 282
280 if (flags & KEXEC_FILE_UNLOAD) 283 if (flags & KEXEC_FILE_UNLOAD)
281 goto exchange; 284 goto exchange;
@@ -324,6 +327,9 @@ SYSCALL_DEFINE5(kexec_file_load, int, kernel_fd, int, initrd_fd,
324exchange: 327exchange:
325 image = xchg(dest_image, image); 328 image = xchg(dest_image, image);
326out: 329out:
330 if ((flags & KEXEC_FILE_ON_CRASH) && kexec_crash_image)
331 arch_kexec_protect_crashkres();
332
327 mutex_unlock(&kexec_mutex); 333 mutex_unlock(&kexec_mutex);
328 kimage_free(image); 334 kimage_free(image);
329 return ret; 335 return ret;