BLOG

Cache Miss Attack

blog5 1

Before understanding about Cache Miss Attack, letโ€™s talk a little aboutย Cache.

What exactly is Cache?

  • A cache (pronounced โ€œcashโ€) is a hardware or software component used in computer systems toย store frequently accessed data or instructions, making it quickly accessible to the CPU or other processing units.
  • The primary purpose of a cache is toย reduce the time it takes to retrieve data from the main memory (RAM) or storage devices, as accessing data from these slower sources can be relatively time-consuming compared to accessing data from a cache.

Locality of Reference

  • Caches work on the principle of exploiting theย locality of referenceย exhibited by most programs and applications.
  • Locality of referenceย refers to the tendency of programs to access a relatively small portion of their memory space frequently and repeatedly for a short period of time.

There are two common types of caches:

  1. CPU Cache:
     โ†’ The CPU cache is aย small, high-speed memoryย integrated into the CPU itself or located very close to it.
     โ†’ It stores copies ofย frequently accessed data and instructionsย from the main memory.
     โ†’ When the CPU needs to read or write data, it first checks the cache. If the data is present in the cache (cache hit), it can be retrieved or modified much faster than fetching it from the main memory (cache miss).
     โ†’ CPU caches typically have multiple levels, such asย L1, L2, and L3ย caches, each with increasing size and farther from the CPU cores.

  2. Disk Cache:
     โ†’ It is a software-based cache used to accelerate data access from slower storage devices likeย hard disk drivesย (HDDs) orย solid-state drivesย (SSDs).
     โ†’ It temporarily stores frequently read data from the disk in a faster memory, such as RAM or SSD, to reduce the time required to access that data again.
     โ†’ It helps improve the overall system performance by reducing the bottleneck caused by slower storage devices.

What is a Cache Hit?

  • A cache hit occursย when the data or instruction requested by a processor is found in the cache memoryย during a memory access operation.
  • In other words, it means thatย the processor has successfully located the required information in the cacheย without the need to access the slower main memory or external storage devices.

What is a Cache Miss?

  • A cache miss occursย when the data or instruction requested by a processor is not found in the cacheย during a memory access operation.
  • In other words, it means that the processor attempted to access data that was not already stored in the cache,ย requiring the CPU to fetch the data from the slower main memory or external storage devices.

What is a โ€œCache Miss Attackโ€?

Letโ€™s consider a scenario where a user is trying to access some data from an application and theย data to be fetched doesnโ€™t exist in the database and the data isnโ€™t present in the cache either.

blog5 2

So, whatโ€™s going to happen in this case?

  • All the user requests will hit the database eventually, defeating the purpose of using a cache.
  • A malicious user submits some queries, is able to understand the pattern when the cache is being missed and then fires a lot of such queries, thus overloading the database.

How can it be avoided?

  • We can design the APIs such that the users wonโ€™t be able to figure out of their requests are a Cache-Hit or a Cache-Miss.
  • If we have cache keys with null values, we should set aย Short Time-To-Live (TTL)ย for such keys.
  • Use aย Web Application Firewall (WAF)ย to detect and block malicious requests.
  • Cache the non-existent keys, so that the next time database wonโ€™t be hit because key can be found in the cache. However, this should be done with caution asย attacker can inject a malicious payloadย in the GET request, and the response is cached.
  • Use Bloom Filter:
    โ†’ It is aย space-efficient probabilistic data structureย used to test whether an element is a member of a set.
    โ†’ It can be used to checkย if a key exists in a set, such as a cache, without actually retrieving the key.
    โ†’ This canย prevent cache miss attacks by making it difficult for an attacker to determine whether a specific key is in the cache.
    โ†’ Bloom filters work by hashing the key and setting the corresponding bits in a bit array.
    โ†’ When checking if a key exists, the same hash function is applied to the key, and the corresponding bits in the bit array are checked. If all the bits are set, the key is probably in the set, but there is a small chance of a false positive.
    โ†’ If the key exists,ย the request first goes to the cacheย and then queries the database if needed.
    โ†’ If the key does not exist in the data set, it means the key is not present in the cache or the database.

Conclusion

Itโ€™s essential for software developers and system architects to be aware of the risks associated with cache miss attacks andย design their systems with security in mind, especially when dealing with sensitive data. Additionally, operating system and hardware manufacturers continually work on mitigating these vulnerabilities and releasing patches to ensure the security of their systems.

Written by Tuyen Nguyen

Tuyen has worked in various projects in e-commerce domain software developing companies. She enjoy to think like a hacker, much to the delight of the QC team.
}
July 15, 2023

1 Comment

  1. Bryan Foect

    Is this the same like the so called ‘caching penetration’ or ‘cache poisoning’ ?

    Reply

Submit a Comment

Your email address will not be published. Required fields are marked *

What to read next

Ready for the leverage?

Choose the Qilin.Cloud technology platform for your business now.