google / kernel-sanitizers

Linux Kernel Sanitizers, fast bug-detectors for the Linux kernel
https://google.github.io/kernel-sanitizers/
436 stars 87 forks source link

error_report_notify implementation #171

Closed ramosian-glider closed 3 years ago

ramosian-glider commented 3 years ago

This patch series adds error report tracing for debugging tools like KFENCE and KASAN, so that it is possible to extend their error reporting mechanisms. It also implements CONFIG_ERROR_REPORT_NOTIFY that captures the last error report and exposes it, together with the report count, to the userspace via sysfs. This shall make it possible to perform userspace handling of memory errors (e.g. uploading them to the cloud) in restrictive environments that disallow access to dmesg or /dev/kmsg.

ramosian-glider commented 3 years ago

Ok, sounds reasonable.

On Mon, Dec 21, 2020 at 2:12 PM Marco Elver notifications@github.com wrote:

@melver commented on this pull request.

In lib/Kconfig.debug https://github.com/google/kasan/pull/171#discussion_r546697443:

@@ -195,6 +195,21 @@ config DEBUG_BUGVERBOSE of the BUG call as well as the EIP and oops trace. This aids debugging but costs about 70-100K of memory.

+config ERROR_REPORT_NOTIFY

  • bool "Expose memory error reports to the userspace"
  • depends on TRACING
  • default n
  • help
  • When enabled, captures error reports from debugging tools like KFENCE
  • or KASAN using console tracing, and provides two files:
    • /sys/kernel/error_report/last_report

Maybe it's worth mentioning, but I think I just didn't like the calling out of "trimmed at PAGE_SIZE" of something that happens extremely rarely. The way it was put sounds like it's a common occurrence, and might be cause for criticism.

Maybe just: " (with maximum report length of PAGE_SIZE)".

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/google/kasan/pull/171#discussion_r546697443, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAG6Z47LO5HGITRD3MXHOO3SV5CSNANCNFSM4U7WIWPA .

ramosian-glider commented 3 years ago

@melver I think we're all set now - please let me know if you have any other comments before I send this for upstream review.

melver commented 3 years ago

LGTM

Assuming you've already run tests and subjected it to syzkaller torture testing.

Ah, to torture test the code here we need lots of bugs.

CONFIG_KFENCE_STRESS_TEST_FAULTS=<non-zero>

would probably do the job.

ramosian-glider commented 3 years ago

I've also noticed that a buffer captured by console tracing may contain \n's, in which case we need to handle every line separately. Fixed that as well.