Skip to contentSkip to conversation

kexec: Update vmcoreinfo after crash happened

PATCH In review Xunlei Pang 5 participants 10 messages Mar 16, 2017 – Mar 21, 2017

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kexec: Update vmcoreinfo after crash happened

Currently vmcoreinfo data is updated at boot time subsys_initcall(), it has the risk of being modified by some wrong code during system is running.

As a result, vmcore dumped will contain the wrong vmcoreinfo. Later on, when using "crash" utility to parse this vmcore, we probably will get "Segmentation fault".

Based on the fact that the value of each vmcoreinfo stays invariable once kernel boots up, we safely move all the vmcoreinfo operations into crash_save_vmcoreinfo() which is called after crash happened. In this way, vmcoreinfo data correctness is always guaranteed.

---
 kernel/kexec_core.c | 14 +++-----------
 1 file changed, 3 insertions(+), 11 deletions(-)
kernel/kexec_core.c +3 -11
index bfe62d5..1bfdd96 100644
@@ -1367,12 +1367,6 @@ static void update_vmcoreinfo_note(void)
 	final_note(buf);
 }
 
-void crash_save_vmcoreinfo(void)
-{
-	vmcoreinfo_append_str("CRASHTIME=%ld\n", get_seconds());
-	update_vmcoreinfo_note();
-}
-
 void vmcoreinfo_append_str(const char *fmt, ...)
 {
 	va_list args;
@@ -1402,7 +1396,7 @@ phys_addr_t __weak paddr_vmcoreinfo_note(void)
 	return __pa_symbol((unsigned long)(char *)&vmcoreinfo_note);
 }
 
-static int __init crash_save_vmcoreinfo_init(void)
+void crash_save_vmcoreinfo(void)
 {
 	VMCOREINFO_OSRELEASE(init_uts_ns.name.release);
 	VMCOREINFO_PAGESIZE(PAGE_SIZE);
@@ -1474,13 +1468,11 @@ static int __init crash_save_vmcoreinfo_init(void)
 #endif
 
 	arch_crash_save_vmcoreinfo();
-	update_vmcoreinfo_note();
+	vmcoreinfo_append_str("CRASHTIME=%ld\n", get_seconds());
 
-	return 0;
+	update_vmcoreinfo_note();
 }
 
-subsys_initcall(crash_save_vmcoreinfo_init);
-
 /*
  * Move into place and start executing a preloaded standalone
  * executable.  If nothing was preloaded return an error.
Signature · 1 line
1.8.3.1
#1 lore raw

Hi Xunlei,

Did you really see this ever happened? Because the vmcore size estimate feature, namely --mem-usage option of makedumpfile, depends on the vmcoreinfo in 1st kernel, your change will break it.

If not, it could be not good to change that.

Baoquan

Quoted 63 lines · Xunlei Pang

Currently vmcoreinfo data is updated at boot time subsys_initcall(), it has the risk of being modified by some wrong code during system is running.

As a result, vmcore dumped will contain the wrong vmcoreinfo. Later on, when using "crash" utility to parse this vmcore, we probably will get "Segmentation fault".

Based on the fact that the value of each vmcoreinfo stays invariable once kernel boots up, we safely move all the vmcoreinfo operations into crash_save_vmcoreinfo() which is called after crash happened. In this way, vmcoreinfo data correctness is always guaranteed.

---
 kernel/kexec_core.c | 14 +++-----------
 1 file changed, 3 insertions(+), 11 deletions(-)
kernel/kexec_core.c +3 -11
index bfe62d5..1bfdd96 100644
@@ -1367,12 +1367,6 @@ static void update_vmcoreinfo_note(void)
 	final_note(buf);
 }
 
-void crash_save_vmcoreinfo(void)
-{
-	vmcoreinfo_append_str("CRASHTIME=%ld\n", get_seconds());
-	update_vmcoreinfo_note();
-}
-
 void vmcoreinfo_append_str(const char *fmt, ...)
 {
 	va_list args;
@@ -1402,7 +1396,7 @@ phys_addr_t __weak paddr_vmcoreinfo_note(void)
 	return __pa_symbol((unsigned long)(char *)&vmcoreinfo_note);
 }
 
-static int __init crash_save_vmcoreinfo_init(void)
+void crash_save_vmcoreinfo(void)
 {
 	VMCOREINFO_OSRELEASE(init_uts_ns.name.release);
 	VMCOREINFO_PAGESIZE(PAGE_SIZE);
@@ -1474,13 +1468,11 @@ static int __init crash_save_vmcoreinfo_init(void)
 #endif
 
 	arch_crash_save_vmcoreinfo();
-	update_vmcoreinfo_note();
+	vmcoreinfo_append_str("CRASHTIME=%ld\n", get_seconds());
 
-	return 0;
+	update_vmcoreinfo_note();
 }
 
-subsys_initcall(crash_save_vmcoreinfo_init);
-
 /*
  * Move into place and start executing a preloaded standalone
  * executable.  If nothing was preloaded return an error.
Signature · 1 line
1.8.3.1
#2 lore raw
Quoted 5 lines · Baoquan He

Hi Xunlei,

Did you really see this ever happened? Because the vmcore size estimate feature, namely --mem-usage option of makedumpfile, depends on the vmcoreinfo in 1st kernel, your change will break it.

Hi Baoquan,

I can reproduce it using a kernel module which modifies the vmcoreinfo, so it's a problem can actually happen.

Quoted 1 line

If not, it could be not good to change that.

That's a good point, then I guess we can keep the crash_save_vmcoreinfo_init(), and store again all the vmcoreinfo after crash. What do you think?

Regards,
Xunlei

Quoted 67 lines

Baoquan

Quoted 63 lines · Xunlei Pang

Currently vmcoreinfo data is updated at boot time subsys_initcall(), it has the risk of being modified by some wrong code during system is running.

As a result, vmcore dumped will contain the wrong vmcoreinfo. Later on, when using "crash" utility to parse this vmcore, we probably will get "Segmentation fault".

Based on the fact that the value of each vmcoreinfo stays invariable once kernel boots up, we safely move all the vmcoreinfo operations into crash_save_vmcoreinfo() which is called after crash happened. In this way, vmcoreinfo data correctness is always guaranteed.

---
 kernel/kexec_core.c | 14 +++-----------
 1 file changed, 3 insertions(+), 11 deletions(-)
kernel/kexec_core.c +3 -11
index bfe62d5..1bfdd96 100644
@@ -1367,12 +1367,6 @@ static void update_vmcoreinfo_note(void)
 	final_note(buf);
 }
 
-void crash_save_vmcoreinfo(void)
-{
-	vmcoreinfo_append_str("CRASHTIME=%ld\n", get_seconds());
-	update_vmcoreinfo_note();
-}
-
 void vmcoreinfo_append_str(const char *fmt, ...)
 {
 	va_list args;
@@ -1402,7 +1396,7 @@ phys_addr_t __weak paddr_vmcoreinfo_note(void)
 	return __pa_symbol((unsigned long)(char *)&vmcoreinfo_note);
 }
 
-static int __init crash_save_vmcoreinfo_init(void)
+void crash_save_vmcoreinfo(void)
 {
 	VMCOREINFO_OSRELEASE(init_uts_ns.name.release);
 	VMCOREINFO_PAGESIZE(PAGE_SIZE);
@@ -1474,13 +1468,11 @@ static int __init crash_save_vmcoreinfo_init(void)
 #endif
 
 	arch_crash_save_vmcoreinfo();
-	update_vmcoreinfo_note();
+	vmcoreinfo_append_str("CRASHTIME=%ld\n", get_seconds());
 
-	return 0;
+	update_vmcoreinfo_note();
 }
 
-subsys_initcall(crash_save_vmcoreinfo_init);
-
 /*
  * Move into place and start executing a preloaded standalone
  * executable.  If nothing was preloaded return an error.
Signature · 1 line
1.8.3.1
#3 lore raw
Quoted 9 lines · Xunlei Pang
Quoted 5 lines · Baoquan He

Hi Xunlei,

Did you really see this ever happened? Because the vmcore size estimate feature, namely --mem-usage option of makedumpfile, depends on the vmcoreinfo in 1st kernel, your change will break it.

Hi Baoquan,

Quoted 7 lines

I can reproduce it using a kernel module which modifies the vmcoreinfo, so it's a problem can actually happen.

Quoted 1 line

If not, it could be not good to change that.

That's a good point, then I guess we can keep the crash_save_vmcoreinfo_init(), and store again all the vmcoreinfo after crash. What do you think?

Well, then it will make makedumpfile segfault happen too when execute below command in 1st kernel if it existed:

	makedumpfile --mem-usage /proc/kcore

So we still need to face that problem and need fix it. vmcoreinfo_note is in kernel data area, how does module intrude into this area? And can we fix the module code?

Quoted 69 lines
Quoted 68 lines

Baoquan

Quoted 63 lines · Xunlei Pang

Currently vmcoreinfo data is updated at boot time subsys_initcall(), it has the risk of being modified by some wrong code during system is running.

As a result, vmcore dumped will contain the wrong vmcoreinfo. Later on, when using "crash" utility to parse this vmcore, we probably will get "Segmentation fault".

Based on the fact that the value of each vmcoreinfo stays invariable once kernel boots up, we safely move all the vmcoreinfo operations into crash_save_vmcoreinfo() which is called after crash happened. In this way, vmcoreinfo data correctness is always guaranteed.

---
 kernel/kexec_core.c | 14 +++-----------
 1 file changed, 3 insertions(+), 11 deletions(-)
kernel/kexec_core.c +3 -11
index bfe62d5..1bfdd96 100644
@@ -1367,12 +1367,6 @@ static void update_vmcoreinfo_note(void)
 	final_note(buf);
 }
 
-void crash_save_vmcoreinfo(void)
-{
-	vmcoreinfo_append_str("CRASHTIME=%ld\n", get_seconds());
-	update_vmcoreinfo_note();
-}
-
 void vmcoreinfo_append_str(const char *fmt, ...)
 {
 	va_list args;
@@ -1402,7 +1396,7 @@ phys_addr_t __weak paddr_vmcoreinfo_note(void)
 	return __pa_symbol((unsigned long)(char *)&vmcoreinfo_note);
 }
 
-static int __init crash_save_vmcoreinfo_init(void)
+void crash_save_vmcoreinfo(void)
 {
 	VMCOREINFO_OSRELEASE(init_uts_ns.name.release);
 	VMCOREINFO_PAGESIZE(PAGE_SIZE);
@@ -1474,13 +1468,11 @@ static int __init crash_save_vmcoreinfo_init(void)
 #endif
 
 	arch_crash_save_vmcoreinfo();
-	update_vmcoreinfo_note();
+	vmcoreinfo_append_str("CRASHTIME=%ld\n", get_seconds());
 
-	return 0;
+	update_vmcoreinfo_note();
 }
 
-subsys_initcall(crash_save_vmcoreinfo_init);
-
 /*
  * Move into place and start executing a preloaded standalone
  * executable.  If nothing was preloaded return an error.
Signature · 1 line
1.8.3.1
#4 lore raw
Quoted 12 lines · Baoquan He
Quoted 11 lines · Xunlei Pang
Quoted 5 lines · Baoquan He

Hi Xunlei,

Did you really see this ever happened? Because the vmcore size estimate feature, namely --mem-usage option of makedumpfile, depends on the vmcoreinfo in 1st kernel, your change will break it.

Hi Baoquan,

I can reproduce it using a kernel module which modifies the vmcoreinfo, so it's a problem can actually happen.

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

If not, it could be not good to change that.

That's a good point, then I guess we can keep the crash_save_vmcoreinfo_init(), and store again all the vmcoreinfo after crash. What do you think?

Well, then it will make makedumpfile segfault happen too when execute below command in 1st kernel if it existed:

	makedumpfile --mem-usage /proc/kcore

Yes, if the initial vmcoreinfo data was modified before "makedumpfile --mem-usage", it might happen, after all the system is going something wrong. And that's why we deploy kdump service at the very beginning when the system has a low possibility of going wrong.

But we have to guarantee kdump vmcore can be generated correctly as possible as it can.

Quoted 5 lines

So we still need to face that problem and need fix it. vmcoreinfo_note is in kernel data area, how does module intrude into this area? And can we fix the module code?

Bugs always exist in products, we can't know what will happen and fix all the errors, that's why we need kdump.

I think the following update should guarantee the correct vmcoreinfo for kdump.

---
 kernel/kexec_core.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)
kernel/kexec_core.c +15 -7
index bfe62d5..0f7b328 100644
@@ -1367,12 +1367,6 @@ static void update_vmcoreinfo_note(void)
     final_note(buf);
 }
 
-void crash_save_vmcoreinfo(void)
-{
-    vmcoreinfo_append_str("CRASHTIME=%ld\n", get_seconds());
-    update_vmcoreinfo_note();
-}
-
 void vmcoreinfo_append_str(const char *fmt, ...)
 {
     va_list args;
@@ -1402,7 +1396,7 @@ phys_addr_t __weak paddr_vmcoreinfo_note(void)
     return __pa_symbol((unsigned long)(char *)&vmcoreinfo_note);
 }
 
-static int __init crash_save_vmcoreinfo_init(void)
+static void do_crash_save_vmcoreinfo_init(void)
 {
     VMCOREINFO_OSRELEASE(init_uts_ns.name.release);
     VMCOREINFO_PAGESIZE(PAGE_SIZE);
@@ -1474,6 +1468,20 @@ static int __init crash_save_vmcoreinfo_init(void)
 #endif
 
     arch_crash_save_vmcoreinfo();
+}
+
+void crash_save_vmcoreinfo(void)
+{
+    /* Save again to protect vmcoreinfo from being modified */
+    vmcoreinfo_size = 0;
+    do_crash_save_vmcoreinfo_init();
+    vmcoreinfo_append_str("CRASHTIME=%ld\n", get_seconds());
+    update_vmcoreinfo_note();
+}
+
+static int __init crash_save_vmcoreinfo_init(void)
+{
+    do_crash_save_vmcoreinfo_init();
     update_vmcoreinfo_note();
 
     return 0;
Signature · 1 line
1.8.3.1
#5 lore raw
Quoted 32 lines · On Thu, 16 Mar 2017 21:40:58 +0800 Xunlei Pang <[email protected]> wrote:
Quoted 12 lines · Baoquan He
Quoted 11 lines · Xunlei Pang
Quoted 5 lines · Baoquan He

Hi Xunlei,

Did you really see this ever happened? Because the vmcore size estimate feature, namely --mem-usage option of makedumpfile, depends on the vmcoreinfo in 1st kernel, your change will break it.

Hi Baoquan,

I can reproduce it using a kernel module which modifies the vmcoreinfo, so it's a problem can actually happen.

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

If not, it could be not good to change that.

That's a good point, then I guess we can keep the crash_save_vmcoreinfo_init(), and store again all the vmcoreinfo after crash. What do you think?

Well, then it will make makedumpfile segfault happen too when execute below command in 1st kernel if it existed:

	makedumpfile --mem-usage /proc/kcore

Yes, if the initial vmcoreinfo data was modified before "makedumpfile --mem-usage", it might happen, after all the system is going something wrong. And that's why we deploy kdump service at the very beginning when the system has a low possibility of going wrong.

But we have to guarantee kdump vmcore can be generated correctly as possible as it can.

Quoted 5 lines

So we still need to face that problem and need fix it. vmcoreinfo_note is in kernel data area, how does module intrude into this area? And can we fix the module code?

Quoted 4 lines

Bugs always exist in products, we can't know what will happen and fix all the errors, that's why we need kdump.

I think the following update should guarantee the correct vmcoreinfo for kdump.

I'm still not convinced. I would probably have more trust in a clean kernel (after boot) than a kernel that has already crashed (presumably because of a serious bug). How can be reliability improved by running more code in unsafe environment?

If some code overwrites reserved areas (such as vmcoreinfo), then it's seriously buggy. And in my opinion, it is more difficult to identify such bugs if they are masked by re-initializing vmcoreinfo after crash. In fact, if makedumpfile in the kexec'ed kernel complains that it didn't find valid VMCOREINFO content, that's already a hint.

As a side note, if you're debugging a vmcoreinfo corruption, it's possible to use a standalone VMCOREINFO file with makedumpfile, so you can pre-generate it and save it in the kdump initrd.

In short, I don't see a compelling case for this change.

Just my two cents,
Petr T

#6 lore raw
Quoted 32 lines · Petr Tesarik
Quoted 29 lines · On Thu, 16 Mar 2017 21:40:58 +0800 Xunlei Pang <[email protected]> wrote:
Quoted 12 lines · Baoquan He
Quoted 11 lines · Xunlei Pang
Quoted 5 lines · Baoquan He

Hi Xunlei,

Did you really see this ever happened? Because the vmcore size estimate feature, namely --mem-usage option of makedumpfile, depends on the vmcoreinfo in 1st kernel, your change will break it.

Hi Baoquan,

I can reproduce it using a kernel module which modifies the vmcoreinfo, so it's a problem can actually happen.

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

If not, it could be not good to change that.

That's a good point, then I guess we can keep the crash_save_vmcoreinfo_init(), and store again all the vmcoreinfo after crash. What do you think?

Well, then it will make makedumpfile segfault happen too when execute below command in 1st kernel if it existed:

	makedumpfile --mem-usage /proc/kcore

Yes, if the initial vmcoreinfo data was modified before "makedumpfile --mem-usage", it might happen, after all the system is going something wrong. And that's why we deploy kdump service at the very beginning when the system has a low possibility of going wrong.

But we have to guarantee kdump vmcore can be generated correctly as possible as it can.

Quoted 4 lines

So we still need to face that problem and need fix it. vmcoreinfo_note is in kernel data area, how does module intrude into this area? And can we fix the module code?

Quoted 8 lines
Quoted 4 lines

Bugs always exist in products, we can't know what will happen and fix all the errors, that's why we need kdump.

I think the following update should guarantee the correct vmcoreinfo for kdump.

I'm still not convinced. I would probably have more trust in a clean kernel (after boot) than a kernel that has already crashed (presumably because of a serious bug). How can be reliability improved by running more code in unsafe environment?

Correct, I realized that, so used crc32 to protect the original data, but since Eric left a more reasonable idea, I will try that later.

Quoted 7 lines

If some code overwrites reserved areas (such as vmcoreinfo), then it's seriously buggy. And in my opinion, it is more difficult to identify such bugs if they are masked by re-initializing vmcoreinfo after crash. In fact, if makedumpfile in the kexec'ed kernel complains that it didn't find valid VMCOREINFO content, that's already a hint.

Quoted 5 lines

As a side note, if you're debugging a vmcoreinfo corruption, it's possible to use a standalone VMCOREINFO file with makedumpfile, so you can pre-generate it and save it in the kdump initrd.

In short, I don't see a compelling case for this change.

E.g. 1) wrong code overwrites vmcoreinfo_data; 2) further crashes the system; 3) trigger kdump, then we obviously will fail to recognize the crash context correctly due to the corrupted vmcoreinfo. Everyone will get confused if met such unfortunate customer-side issue.

Although it's corner case, if it's easy to fix, then I think we better do it.

Now except for vmcoreinfo, all the crash data is well protected (including cpu note which is fully updated in the crash path, thus its correctness is guaranteed).

Regards,
Xunlei

#7 lore raw
Quoted 63 lines · On Mon, 20 Mar 2017 10:17:42 +0800 Xunlei Pang <[email protected]> wrote:
Quoted 32 lines · Petr Tesarik
Quoted 29 lines · On Thu, 16 Mar 2017 21:40:58 +0800 Xunlei Pang <[email protected]> wrote:
Quoted 12 lines · Baoquan He
Quoted 11 lines · Xunlei Pang
Quoted 5 lines · Baoquan He

Hi Xunlei,

Did you really see this ever happened? Because the vmcore size estimate feature, namely --mem-usage option of makedumpfile, depends on the vmcoreinfo in 1st kernel, your change will break it.

Hi Baoquan,

I can reproduce it using a kernel module which modifies the vmcoreinfo, so it's a problem can actually happen.

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

If not, it could be not good to change that.

That's a good point, then I guess we can keep the crash_save_vmcoreinfo_init(), and store again all the vmcoreinfo after crash. What do you think?

Well, then it will make makedumpfile segfault happen too when execute below command in 1st kernel if it existed:

	makedumpfile --mem-usage /proc/kcore

Yes, if the initial vmcoreinfo data was modified before "makedumpfile --mem-usage", it might happen, after all the system is going something wrong. And that's why we deploy kdump service at the very beginning when the system has a low possibility of going wrong.

But we have to guarantee kdump vmcore can be generated correctly as possible as it can.

Quoted 4 lines

So we still need to face that problem and need fix it. vmcoreinfo_note is in kernel data area, how does module intrude into this area? And can we fix the module code?

Quoted 8 lines
Quoted 4 lines

Bugs always exist in products, we can't know what will happen and fix all the errors, that's why we need kdump.

I think the following update should guarantee the correct vmcoreinfo for kdump.

I'm still not convinced. I would probably have more trust in a clean kernel (after boot) than a kernel that has already crashed (presumably because of a serious bug). How can be reliability improved by running more code in unsafe environment?

Correct, I realized that, so used crc32 to protect the original data, but since Eric left a more reasonable idea, I will try that later.

Quoted 7 lines

If some code overwrites reserved areas (such as vmcoreinfo), then it's seriously buggy. And in my opinion, it is more difficult to identify such bugs if they are masked by re-initializing vmcoreinfo after crash. In fact, if makedumpfile in the kexec'ed kernel complains that it didn't find valid VMCOREINFO content, that's already a hint.

Quoted 5 lines

As a side note, if you're debugging a vmcoreinfo corruption, it's possible to use a standalone VMCOREINFO file with makedumpfile, so you can pre-generate it and save it in the kdump initrd.

In short, I don't see a compelling case for this change.

E.g. 1) wrong code overwrites vmcoreinfo_data; 2) further crashes the system; 3) trigger kdump, then we obviously will fail to recognize the crash context correctly due to the corrupted vmcoreinfo. Everyone will get confused if met such unfortunate customer-side issue.

Quoted 5 lines

Although it's corner case, if it's easy to fix, then I think we better do it.

Now except for vmcoreinfo, all the crash data is well protected (including cpu note which is fully updated in the crash path, thus its correctness is guaranteed).

Hm, I think we shouldn't combine the two things.

Protecting VMCOREINFO with SHA (just as the other information passed to the secondary kernel) sounds right to me. Re-creating the info while the kernel is already crashing does not sound particularly good.

Yes, your patch may help in some scenarios, but in general it also increases the amount of code that must reliably work in a crashed environment. I can still recall why the LKCD approach (save the dump directly from the crashed kernel) was abandoned...

Apart, there's a lot of other information that might be corrupted (e.g. the purgatory code, elfcorehdr, secondary kernel, or the initrd).

Why is this VMCOREINFO so special?

Regards,
Petr Tesarik

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#8 lore raw
Quoted 83 lines · Petr Tesarik
Quoted 63 lines · On Mon, 20 Mar 2017 10:17:42 +0800 Xunlei Pang <[email protected]> wrote:
Quoted 32 lines · Petr Tesarik
Quoted 29 lines · On Thu, 16 Mar 2017 21:40:58 +0800 Xunlei Pang <[email protected]> wrote:
Quoted 12 lines · Baoquan He
Quoted 11 lines · Xunlei Pang
Quoted 5 lines · Baoquan He

Hi Xunlei,

Did you really see this ever happened? Because the vmcore size estimate feature, namely --mem-usage option of makedumpfile, depends on the vmcoreinfo in 1st kernel, your change will break it.

Hi Baoquan,

I can reproduce it using a kernel module which modifies the vmcoreinfo, so it's a problem can actually happen.

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

If not, it could be not good to change that.

That's a good point, then I guess we can keep the crash_save_vmcoreinfo_init(), and store again all the vmcoreinfo after crash. What do you think?

Well, then it will make makedumpfile segfault happen too when execute below command in 1st kernel if it existed:

	makedumpfile --mem-usage /proc/kcore

Yes, if the initial vmcoreinfo data was modified before "makedumpfile --mem-usage", it might happen, after all the system is going something wrong. And that's why we deploy kdump service at the very beginning when the system has a low possibility of going wrong.

But we have to guarantee kdump vmcore can be generated correctly as possible as it can.

Quoted 4 lines

So we still need to face that problem and need fix it. vmcoreinfo_note is in kernel data area, how does module intrude into this area? And can we fix the module code?

Quoted 8 lines
Quoted 4 lines

Bugs always exist in products, we can't know what will happen and fix all the errors, that's why we need kdump.

I think the following update should guarantee the correct vmcoreinfo for kdump.

I'm still not convinced. I would probably have more trust in a clean kernel (after boot) than a kernel that has already crashed (presumably because of a serious bug). How can be reliability improved by running more code in unsafe environment?

Correct, I realized that, so used crc32 to protect the original data, but since Eric left a more reasonable idea, I will try that later.

Quoted 7 lines

If some code overwrites reserved areas (such as vmcoreinfo), then it's seriously buggy. And in my opinion, it is more difficult to identify such bugs if they are masked by re-initializing vmcoreinfo after crash. In fact, if makedumpfile in the kexec'ed kernel complains that it didn't find valid VMCOREINFO content, that's already a hint.

Quoted 5 lines

As a side note, if you're debugging a vmcoreinfo corruption, it's possible to use a standalone VMCOREINFO file with makedumpfile, so you can pre-generate it and save it in the kdump initrd.

In short, I don't see a compelling case for this change.

E.g. 1) wrong code overwrites vmcoreinfo_data; 2) further crashes the system; 3) trigger kdump, then we obviously will fail to recognize the crash context correctly due to the corrupted vmcoreinfo. Everyone will get confused if met such unfortunate customer-side issue.

Quoted 5 lines

Although it's corner case, if it's easy to fix, then I think we better do it.

Now except for vmcoreinfo, all the crash data is well protected (including cpu note which is fully updated in the crash path, thus its correctness is guaranteed).

Hm, I think we shouldn't combine the two things.

Protecting VMCOREINFO with SHA (just as the other information passed to the secondary kernel) sounds right to me. Re-creating the info while the kernel is already crashing does not sound particularly good.

Yes, your patch may help in some scenarios, but in general it also increases the amount of code that must reliably work in a crashed environment. I can still recall why the LKCD approach (save the dump directly from the crashed kernel) was abandoned...

Quoted 4 lines

Apart, there's a lot of other information that might be corrupted (e.g. the purgatory code, elfcorehdr, secondary kernel, or the initrd).

Why is this VMCOREINFO so special?

Petr I generally agree with you. We need to minimise what happens after a panic.

I don't know if you saw my comment on the v2 of this patchset, but the core issue I saw with VMCOREINFO is that the data appears to be stored in the .bss (of the kernel that will crash) instead of in the pages managed by kexec. Which means they are not protected like other pages.

That is the issue I have asked to be addressed first.

I also agree that we very much want to minimise what happens during crash. Which I suspect means that we will want to remove the CRASH_TIME variable from VMCOREINFO. I may be wrong but I think that is probably enough to make the strings a constant.

Eric

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#9 lore raw
In reply to Petr Tesarik
Quoted 70 lines · Petr Tesarik
Quoted 60 lines · On Mon, 20 Mar 2017 10:17:42 +0800 Xunlei Pang <[email protected]> wrote:
Quoted 32 lines · Petr Tesarik
Quoted 29 lines · On Thu, 16 Mar 2017 21:40:58 +0800 Xunlei Pang <[email protected]> wrote:
Quoted 12 lines · Baoquan He
Quoted 11 lines · Xunlei Pang
Quoted 5 lines · Baoquan He

Hi Xunlei,

Did you really see this ever happened? Because the vmcore size estimate feature, namely --mem-usage option of makedumpfile, depends on the vmcoreinfo in 1st kernel, your change will break it.

Hi Baoquan,

I can reproduce it using a kernel module which modifies the vmcoreinfo, so it's a problem can actually happen.

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

If not, it could be not good to change that.

That's a good point, then I guess we can keep the crash_save_vmcoreinfo_init(), and store again all the vmcoreinfo after crash. What do you think?

Well, then it will make makedumpfile segfault happen too when execute below command in 1st kernel if it existed:

	makedumpfile --mem-usage /proc/kcore

Yes, if the initial vmcoreinfo data was modified before "makedumpfile --mem-usage", it might happen, after all the system is going something wrong. And that's why we deploy kdump service at the very beginning when the system has a low possibility of going wrong.

But we have to guarantee kdump vmcore can be generated correctly as possible as it can.

Quoted 4 lines

So we still need to face that problem and need fix it. vmcoreinfo_note is in kernel data area, how does module intrude into this area? And can we fix the module code?

Quoted 8 lines
Quoted 4 lines

Bugs always exist in products, we can't know what will happen and fix all the errors, that's why we need kdump.

I think the following update should guarantee the correct vmcoreinfo for kdump.

I'm still not convinced. I would probably have more trust in a clean kernel (after boot) than a kernel that has already crashed (presumably because of a serious bug). How can be reliability improved by running more code in unsafe environment?

Correct, I realized that, so used crc32 to protect the original data, but since Eric left a more reasonable idea, I will try that later.

Quoted 11 lines

If some code overwrites reserved areas (such as vmcoreinfo), then it's seriously buggy. And in my opinion, it is more difficult to identify such bugs if they are masked by re-initializing vmcoreinfo after crash. In fact, if makedumpfile in the kexec'ed kernel complains that it didn't find valid VMCOREINFO content, that's already a hint.

As a side note, if you're debugging a vmcoreinfo corruption, it's possible to use a standalone VMCOREINFO file with makedumpfile, so you can pre-generate it and save it in the kdump initrd.

In short, I don't see a compelling case for this change.

E.g. 1) wrong code overwrites vmcoreinfo_data; 2) further crashes the system; 3) trigger kdump, then we obviously will fail to recognize the crash context correctly due to the corrupted vmcoreinfo. Everyone will get confused if met such unfortunate customer-side issue.

Quoted 5 lines

Although it's corner case, if it's easy to fix, then I think we better do it.

Now except for vmcoreinfo, all the crash data is well protected (including cpu note which is fully updated in the crash path, thus its correctness is guaranteed).

Hm, I think we shouldn't combine the two things.

Quoted 8 lines

Protecting VMCOREINFO with SHA (just as the other information passed to the secondary kernel) sounds right to me. Re-creating the info while the kernel is already crashing does not sound particularly good.

Yes, your patch may help in some scenarios, but in general it also increases the amount of code that must reliably work in a crashed environment. I can still recall why the LKCD approach (save the dump directly from the crashed kernel) was abandoned...

Agree on this point, there is nearly no extra code added to the crash path in v3, maybe you can have a quick look.

Quoted 3 lines

Apart, there's a lot of other information that might be corrupted (e.g. the purgatory code, elfcorehdr, secondary kernel, or the initrd).

Those are located at the crash memory, they can be protected by either SHA or the arch_kexec_protect_crashkres() mechanism(if implemented).

Quoted 2 lines

Why is this VMCOREINFO so special?

It is also a chunk passed to 2nd kernel like the above-mentioned information, we better treat it like them as well.

Regards,
Xunlei