Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@hpoussin
Copy link
Contributor

Purpose

Implement kernel sanitizers (-fsanitize=...)

This is a resurrection of PR #2527

JIRA issue: CORE-15771

Proposed changes

  • add a cmake option SANITIZE_UB to enable kernel undefined sanitizer
  • add a static library sdk/lib/ksanitize having required functions
  • link kernel modules (ntoskrnl, hal, drivers...) to ksanitize library

TODO

  • UndefinedBehaviorSanitizer (UBSan, -fsanitize=undefined)
  • fsanitize=nullability* group of checks
  • KernelAddressSanitizer (KASan, -fsanitize=address)
  • Test on 64bit builds

Testbot runs (Filled in by Devs)

  • KVM x86:
  • KVM x64:

@github-actions github-actions bot added kernel&hal Code changes to the ntoskrnl and HAL drivers Kernel mode drivers and frameworks Win32SS For Win32 subsystem (Win32k, GDI/USER DLLs, etc.) related components PRs. labels Oct 24, 2025
Copy link
Contributor

@HBelusca HBelusca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Some questions;
  • space fixes for e1000 changes

@binarymaster binarymaster added the enhancement For PRs with an enhancement/new feature. label Oct 24, 2025
@hpoussin hpoussin force-pushed the hpoussin/CORE-15771 branch from dea19c4 to bb280a7 Compare October 26, 2025 18:09
Comment on lines +827 to +847

ASSERT(pData);

HandleOverflow(false, pData, ulLHS, ulRHS, PLUS_STRING);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason for these being wrappers?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

__ubsan_handle_add_overflow/__ubsan_handle_add_overflow_abort/ __ubsan_handle_divrem_overflow/ __ubsan_handle_divrem_overflow_abort/... functions are called by the code generated by the compiler. They all call the same function HandleOverflow.

Comment on lines 102 to 140
/*
#include <sys/cdefs.h>
#if defined(_KERNEL)
__KERNEL_RCSID(0, "$NetBSD: ubsan.c,v 1.10 2020/03/08 21:35:03 kamil Exp $");
#else
__RCSID("$NetBSD: ubsan.c,v 1.10 2020/03/08 21:35:03 kamil Exp $");
#endif
#if defined(_KERNEL)
#include <sys/param.h>
#include <sys/types.h>
#include <sys/stdarg.h>
#define ASSERT(x) KASSERT(x)
#else
#if defined(_LIBC)
#include "namespace.h"
#endif
#include <sys/param.h>
#include <assert.h>
#include <inttypes.h>
#include <math.h>
#include <signal.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
#include <unistd.h>
#if defined(_LIBC)
#include "extern.h"
#define ubsan_vsyslog vsyslog_ss
#define ASSERT(x) _DIAGASSERT(x)
#else
#define ubsan_vsyslog vsyslog_r
#define ASSERT(x) assert(x)
#endif
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to keep this? I get that this file is "synced", but how much of it is really still original? Wouldn't it make sense to simply fork it?

Copy link
Contributor Author

@hpoussin hpoussin Oct 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything is original, except this #ifdef __REACTOS__

@hpoussin hpoussin force-pushed the hpoussin/CORE-15771 branch 6 times, most recently from 58537b7 to defea0a Compare November 9, 2025 16:19
@hpoussin hpoussin force-pushed the hpoussin/CORE-15771 branch from defea0a to 7dbc0ed Compare November 9, 2025 22:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

drivers Kernel mode drivers and frameworks enhancement For PRs with an enhancement/new feature. kernel&hal Code changes to the ntoskrnl and HAL Win32SS For Win32 subsystem (Win32k, GDI/USER DLLs, etc.) related components PRs.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants