Logo

dev-resources.site

for different kinds of informations.

Code Smell 260 - Crowdstrike NULL

Published at
7/20/2024
Categories
security
cleancode
hacking
null
Author
mcsee
Categories
4 categories in total
security
open
cleancode
open
hacking
open
null
open
Author
5 person written this
mcsee
open
Code Smell 260 - Crowdstrike NULL

Avoiding the Null Trap in Privilege Mode Drivers

TL;DR: Using null pointers in critical code can crash your system

Problems

  • Memory access violation

  • Unpredictable behavior

  • Null Pointer Dereference

  • Unexpected program termination

  • System instability

  • No healing/recovery strategy

  • Security Risk

Solutions

  1. Avoid using NULLs

  2. Use address sanitizers

  3. Make controlled releases to mission-critical software

  4. Create better rollback strategies instead of BSOD

  5. Use Smart Pointers: Manage memory automatically and avoid null pointers with smart pointers

  6. Create self-healing software.

  7. Apply defensive programming

  8. Improve your QA tests before deploying to production.

BSOD

Context

When you use nulls in a privileged driver, you risk causing serious issues.

Privilege mode drivers run with high permissions, and if you use a null pointer, the system might try to access an invalid memory address.

For example, trying to read from address 0x9c (156) or using 0x0 as a special value can lead to critical errors.

You can't just abort the program in privileged mode, so you must handle these cases carefully.

In privileged drivers, null pointer usage poses significant risks. You can mitigate these risks using modern C++ features like std::optional.

This problem caused one of the worst software blackouts in 2024.

Sample Code

Wrong



// This case is not exactly what happened with Crowdstrike
// It is here for illustration purposes
void* get_data() {
  if (data_available) {
    return data_ptr;  // This could be null!
  } else {
    // Uh oh, what if data_ptr is null here?
    return NULL;  
    // Using Null to indicate no data
    // knowing Null is schizophrenic
  }
}

int process_data(void* data) {
  if (data != NULL) { 
    // Maybe a null check, but not guaranteed!
    // Accessing data... (crash if data is Null)
    return *data;
  }
  // No check? Silent failure or unexpected behavior.
  return -1;
}


Enter fullscreen mode Exit fullscreen mode

Right



// You should ideally replace the null with a polymorphic call
// You can see the technique in related articles

std::unique_ptr<int> get_data() { 
  if (data_available) {
    return std::make_unique<int>(data_value);
  } else {
    return nullptr;  // Explicitly return nullptr
  }
}

int process_data(const std::unique_ptr<int>& data) {
  if (data) { // Check for valid pointer
    return *data;
  } else {
    // Handle no data case (e.g., return default value)
    return 0;
  }
}


Enter fullscreen mode Exit fullscreen mode

Detection

[X] Semi-Automatic

You can detect this smell by checking for null pointer usage in critical parts of your code. Look for functions that process pointers and see if they handle null pointers safely.

Human code reviews are good for checking this kind of problem.

Tags

  • Null

Level

[x] Advanced

AI Generation

AI generators can sometimes produce this smell, especially if they generate code without context about the environment where the code will run.

AI generators are fed with code with NULL usage even though his creator told us to avoid it altogether.

AI Detection

AI tools can detect this smell with specific instructions.

AI can be trained to identify code patterns.

Teaching it the nuances of privileged driver development and null safety best practices might require more advanced techniques.

Use static analysis tools to flag null pointer dereferences.

Conclusion

Voyager 1's software has been running for more than 50 years.

It was designed to be robust, reliable, and redundant which is sadly uncommon in some immature systems in 2024.

Avoid using null pointers in privileged mode drivers.

I have written a book on clean code and a whole chapter #15 on how to avoid NULL and all the consequences it carries.

Hopefully, Crowdstrike engineers will read it!

Relations

More Info


This article is part of the CodeSmell Series.

null Article's
30 articles in total
Favicon
How Imburse Payments Ships High-Quality APIs Faster
Favicon
Need to Verify Your JSON Schema? Here's a Few Ways to Do It!
Favicon
Code Smell 260 - Crowdstrike NULL
Favicon
Be careful when using NULL in PostgreSQL
Favicon
The most painful reason NULLs are evil
Favicon
Null or Nothing? Unmasking the Mystery of Parameters in Dart
Favicon
La Solución del Billón de Dólares
Favicon
11 Lessons to learn when using NULLs in PostgreSQL®
Favicon
NULLs Are Not The Same – A Guide
Favicon
the (not so big) Bang!
Favicon
Rust's Option type... in Python
Favicon
Understanding Nullable Reference Types in C#
Favicon
Working with NULL in Databases. Turn Your Frustration Into Delight
Favicon
TypeScript: The many types of nothing
Favicon
ERROR: null" or "null pointer exception while invoking FlowService - Storage get operation
Favicon
ServiceNow: 1 thing for safer GlideRecord scripts
Favicon
How NullPointerException can be avoided in Java
Favicon
Consider these facts when dealing with NULL in RDBMS
Favicon
Unhandled Exception: type 'Null' is not a subtype of type 'int' in type cast error when trying to call function with no int
Favicon
When <nil> is not <nil>
Favicon
Absence of null in Solidity
Favicon
How to Check for Null in Javascript
Favicon
Javascript Tagalog - Null
Favicon
Kotlin 基礎 Part 1 -- !! や ?: と ?.let で Nullable な値を処理する
Favicon
Remove null check, use the Optional
Favicon
Handling null: optional and nullable types
Favicon
More JS Concepts
Favicon
Valores null e undefined no JavaScript
Favicon
Javascript default parameter for null and undefined
Favicon
How I Learned to Stop Worrying and Love NULL in SQL

Featured ones: