cache_seg_id_valid(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… cache_seg_id_valid(9)

okay so this is a page from the Kernel API Manual (section 9, kernel API, iykyk) and honestly? it's a little baddie of a function whose whole job is a vibe check on a cache segment id. πŸŽ€


✨ NAME ✨

cache_seg_id_valid β€” bestie, this validates a cache segment id that was read from the cache device. that's it. that's the whole job. πŸ‘‘


πŸ¦‹ SYNOPSIS πŸ¦‹

bool cache_seg_id_valid (struct pcache_cache *cache , u32 cache_seg_id
);

🌸 ARGUMENTS 🌸

  • cache β€” Pointer to the pcache_cache structure. literally the whole cache, handing itself over so we can peek at its segment table. 🫢
  • cache_seg_id β€” the segment id, decoded from on-media metadata. yeah. it came from the disk. we do not trust it. πŸ™ˆ

πŸ”₯ DESCRIPTION πŸ”₯

okay so here's the tea: on-media segment ids are only protected by a CRC. that's it. one lil CRC. and the way that an attacker who can format the cache device can just… compute that CRC over whatever value they feel like picking. 😭 so it's giving "not a real security boundary," fr fr.

so the move is: reject any id that would index cache->segments[] out of bounds before it gets dereferenced. do the bounds check first, dereference later. no cap. that's the entire assignment and it ate. πŸ’…

like, do NOT skip the check. out-of-bounds index becoming a dereference is a whole situation and nobody wants that on their conscience. πŸ’€

πŸ‘‘ SEE ALSO πŸ‘‘

Kernel file ./drivers/md/dm-pcache/cache.h β€” plus the whole friend group:


⭐ that's the whole page, bestie β€” brought to you by ./drivers/md/dm-pcache, dated October 2026, and yes the section 9 is exactly as iconic as it sounds. go validate some ids responsibly πŸ’œπŸŒˆ

πŸ“¦ where this page comes from