Reference counting is a memory-management technique that tracks how many parts of a program or system still rely on a resource. When the count reaches zero, the resource can be released. In kernel code, counters may track references to objects such as shared memory or other data structures.
Incorrect reference counts can cause security bugs. If a count becomes too low, the kernel may free an object that is still in use, creating a use-after-free that attackers may exploit to corrupt memory or gain privileges. If it stays too high, resources may linger and waste memory. Defenses include careful counter updates, safe handling of overflow and underflow, code review, testing, and promptly applying kernel patches.


