Linux EDAC development
 help / color / mirror / Atom feed
* [bug report] x86/mce: Mark fatal MCE's page as poison to avoid panic in the kdump kernel
@ 2023-10-25  5:44 Dan Carpenter
  2023-10-25  6:19 ` Zhiquan Li
  0 siblings, 1 reply; 3+ messages in thread
From: Dan Carpenter @ 2023-10-25  5:44 UTC (permalink / raw)
  To: zhiquan1.li; +Cc: linux-edac

Hello Zhiquan Li,

The patch 1d11b153d23b: "x86/mce: Mark fatal MCE's page as poison to
avoid panic in the kdump kernel" from Oct 23, 2023 (linux-next),
leads to the following Smatch static checker warning:

	arch/x86/kernel/cpu/mce/core.c:299 mce_panic()
	error: we previously assumed 'final' could be null (see line 281)

arch/x86/kernel/cpu/mce/core.c
    270         /* Now print uncorrected but with the final one last */
    271         llist_for_each_entry(l, pending, llnode) {
    272                 struct mce *m = &l->mce;
    273                 if (!(m->status & MCI_STATUS_UC))
    274                         continue;
    275                 if (!final || mce_cmp(m, final)) {
    276                         print_mce(m);
    277                         if (!apei_err)
    278                                 apei_err = apei_write_mce(m);
    279                 }
    280         }
    281         if (final) {
                    ^^^^^
This assumes final can be NULL

    282                 print_mce(final);
    283                 if (!apei_err)
    284                         apei_err = apei_write_mce(final);
    285         }
    286         if (exp)
    287                 pr_emerg(HW_ERR "Machine check: %s\n", exp);
    288         if (!fake_panic) {
    289                 if (panic_timeout == 0)
    290                         panic_timeout = mca_cfg.panic_timeout;
    291 
    292                 /*
    293                  * Kdump skips the poisoned page in order to avoid
    294                  * touching the error bits again. Poison the page even
    295                  * if the error is fatal and the machine is about to
    296                  * panic.
    297                  */
    298                 if (kexec_crash_loaded()) {
--> 299                         p = pfn_to_online_page(final->addr >> PAGE_SHIFT);
                                                       ^^^^^^^^^^^
Unchecked dereference

    300                         if (final && (final->status & MCI_STATUS_ADDRV) && p)
                                    ^^^^^
Checked too late

    301                                 SetPageHWPoison(p);
    302                 }
    303                 panic(msg);
    304         } else
    305                 pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);
    306 
    307 out:
    308         instrumentation_end();
    309 }

regards,
dan carpenter

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-10-25  7:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-25  5:44 [bug report] x86/mce: Mark fatal MCE's page as poison to avoid panic in the kdump kernel Dan Carpenter
2023-10-25  6:19 ` Zhiquan Li
2023-10-25  7:48   ` Borislav Petkov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox