gossmap: refresh map even if size hasn't changed.
What changed, and why it matters
This change fixes a bug in how Core Lightning refreshes its network map (gossmap). Previously, if the gossip store file stayed the same size, the code would skip re-reading it entirely, even though the last entry might have been partially written or updated in place. Now it always re-parses the map contents, which can prevent stale or incomplete routing data from being used.
Treat as a bug fix with possible security side effects. Review whether stale or partially-read gossip entries could be exploited to influence routing decisions, then include in routine release notes. No emergency action indicated from the diff alone.
Security signals we found
Logic error: early return on unchanged file size could miss final-entry updates
Potential stale routing state in gossip map
No explicit security framing in commit message
Evidence from the diff
In common/gossmap.c, gossmap_refresh() used to return false immediately if lseek() reported the same file size as the existing mmap. The patch removes that early return and always calls map_catchup(map, false, &changed). The mmap is only remapped when the size actually changes. This addresses a race where the final gossip store entry could be appended/updated without changing the total file size, leaving the in-memory map out of sync.
Changed components
common/gossmap.cgossmap_refresh()lightningd gossip store handlingInspect captured patch +10 / −11
diff --git a/common/gossmap.c b/common/gossmap.c
index aed9852d..685bdd4a 100644
--- a/common/gossmap.c
+++ b/common/gossmap.c
@@ -1212,19 +1212,18 @@ bool gossmap_refresh(struct gossmap *map)
/* You must remove local modifications before this. */
assert(!map->local_announces);
- /* If file has gotten larger, try rereading */
+ /* If file has gotten larger, remap */
len = lseek(map->fd, 0, SEEK_END);
- if (len == map->map_size)
- return false;
-
- if (map->mmap)
- munmap(map->mmap, map->map_size);
- map->map_size = len;
+ if (len != map->map_size) {
+ if (map->mmap)
+ munmap(map->mmap, map->map_size);
+ map->map_size = len;
- if (map->mmap) {
- map->mmap = mmap(NULL, map->map_size, PROT_READ, MAP_SHARED, map->fd, 0);
- if (map->mmap == MAP_FAILED)
- map->mmap = NULL;
+ if (map->mmap) {
+ map->mmap = mmap(NULL, map->map_size, PROT_READ, MAP_SHARED, map->fd, 0);
+ if (map->mmap == MAP_FAILED)
+ map->mmap = NULL;
+ }
}
map_catchup(map, false, &changed);
Why this scored 34/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.