Skip to content

Commit

Permalink
gossmap: fix OpenBSD crash.
Browse files Browse the repository at this point in the history
Thanks to amazing debugging assistance from grubles, we figured out
that indeed, my memory was correct: write and mmap are not consistent
on all platforms.  The easiest fix is to disable mmap on OpenBSD for now:
the better fix is to do in-place updates using the mmap, and only rely
on write() for append (which always causes a remap anyway before it's accessed).

Fixes: ElementsProject#7109
Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell authored and cdecker committed Feb 27, 2024
1 parent a708690 commit 87f6ceb
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions common/gossmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -690,9 +690,13 @@ static bool load_gossip_store(struct gossmap *map)
{
map->map_size = lseek(map->fd, 0, SEEK_END);
map->local = NULL;

/* gossipd uses pwritev(), which is not consistent with mmap on OpenBSD! */
#ifndef __OpenBSD__
/* If this fails, we fall back to read */
map->mmap = mmap(NULL, map->map_size, PROT_READ, MAP_SHARED, map->fd, 0);
if (map->mmap == MAP_FAILED)
#endif /* __OpenBSD__ */
map->mmap = NULL;

/* We only support major version 0 */
Expand Down Expand Up @@ -994,8 +998,11 @@ bool gossmap_refresh_mayfail(struct gossmap *map, bool *updated)
if (map->mmap)
munmap(map->mmap, map->map_size);
map->map_size = len;
/* gossipd uses pwritev(), which is not consistent with mmap on OpenBSD! */
#ifndef __OpenBSD__
map->mmap = mmap(NULL, map->map_size, PROT_READ, MAP_SHARED, map->fd, 0);
if (map->mmap == MAP_FAILED)
#endif /* __OpenBSD__ */
map->mmap = NULL;

return map_catchup(map, updated);
Expand Down

0 comments on commit 87f6ceb

Please sign in to comment.