Skip to content

Commit 87f6ceb

Browse files
rustyrussellcdecker
authored andcommitted
gossmap: fix OpenBSD crash.
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: #7109 Signed-off-by: Rusty Russell <[email protected]>
1 parent a708690 commit 87f6ceb

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

common/gossmap.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,9 +690,13 @@ static bool load_gossip_store(struct gossmap *map)
690690
{
691691
map->map_size = lseek(map->fd, 0, SEEK_END);
692692
map->local = NULL;
693+
694+
/* gossipd uses pwritev(), which is not consistent with mmap on OpenBSD! */
695+
#ifndef __OpenBSD__
693696
/* If this fails, we fall back to read */
694697
map->mmap = mmap(NULL, map->map_size, PROT_READ, MAP_SHARED, map->fd, 0);
695698
if (map->mmap == MAP_FAILED)
699+
#endif /* __OpenBSD__ */
696700
map->mmap = NULL;
697701

698702
/* We only support major version 0 */
@@ -994,8 +998,11 @@ bool gossmap_refresh_mayfail(struct gossmap *map, bool *updated)
994998
if (map->mmap)
995999
munmap(map->mmap, map->map_size);
9961000
map->map_size = len;
1001+
/* gossipd uses pwritev(), which is not consistent with mmap on OpenBSD! */
1002+
#ifndef __OpenBSD__
9971003
map->mmap = mmap(NULL, map->map_size, PROT_READ, MAP_SHARED, map->fd, 0);
9981004
if (map->mmap == MAP_FAILED)
1005+
#endif /* __OpenBSD__ */
9991006
map->mmap = NULL;
10001007

10011008
return map_catchup(map, updated);

0 commit comments

Comments
 (0)