!lheuhImcToQZYTQTuI:nixos.org

Nix on macOS

1175 Members
“There are still many issues with the Darwin platform but most of it is quite usable.” — http://yves.gnu-darwin.org190 Servers

Load older messages


SenderMessageTime
29 Dec 2025
@reckenrode:matrix.orgRandy Eckenrode I wonder if the change should be localized to just the g_poll implementation. 00:56:08
@ihar.hrachyshka:matrix.orgIhar Hrachyshkathe glib_conf meson declaration affects config.h used to build glib00:56:26
@emilazy:matrix.orgemily ok, going by glib_conf.set('_GNU_SOURCE', 1) I suppose it ought to be local :) 00:56:43
@reckenrode:matrix.orgRandy Eckenrode I pondered whether to use a heuristic to malloc enough, but doesn’t the set size have to cover all fds in the process? 00:56:53
@emilazy:matrix.orgemilywon't work, since it has to be set early enough for headers00:56:56
@emilazy:matrix.orgemilyyou'd at least need to make it scoped to the file00:57:03
@ihar.hrachyshka:matrix.orgIhar Hrachyshka

I wonder if the change should be localized to just the g_poll implementation.

it is already. The BROKEN_POLL macro is only used in g_poll.

00:57:36
@emilazy:matrix.orgemily btw, doesn't the check against FD_SETSIZE prevent potential heap overflow? 00:58:01
@emilazy:matrix.orgemily you can miscompute a too-high nfds, but then your fd_sets are still the standard size, so select trashes the heap 00:58:45
@emilazy:matrix.orgemily so it seems like part of the reason _DARWIN_UNLIMITED_SELECT isn't default is probably security 00:59:00
@ihar.hrachyshka:matrix.orgIhar Hrachyshkayes but the problem is that while they allow FD_SETSIZE to be redefined, libSystem enforces the value as was used during libSystem compilation.00:59:09
@emilazy:matrix.orgemilysure00:59:22
@emilazy:matrix.orgemilyI just mean it's a disadvantage of setting it00:59:29
@emilazy:matrix.orgemily with your patch, what happens if glib wants to select over more than 4096 fds? does it do the check itself and bail out, or would it trash the heap? 01:00:21
@ihar.hrachyshka:matrix.orgIhar Hrachyshkaprobably it will trash the heap. like it will do on *BSD or Windows.01:01:59
@emilazy:matrix.orgemily on Windows it has a custom implementation with the native API and on BSD it'll use poll 01:02:52
@reckenrode:matrix.orgRandy EckenrodeWindows doesn’t use the same implementation. See the Old New Thing article.01:03:00
@emilazy:matrix.orgemilyit's only Darwin using this code path, and indeed it doesn't have checks https://gitlab.gnome.org/GNOME/glib/-/blob/ecef4b16cfe1a67f18c82f7b12f58241922c7b89/glib/gpoll.c#L54401:03:00
@ihar.hrachyshka:matrix.orgIhar Hrachyshkadocs don't promise / mention fd limits: https://docs.gtk.org/glib/func.poll.html01:03:07
@emilazy:matrix.orgemily well it is only select that has this footgun in the first place 01:03:32
@ihar.hrachyshka:matrix.orgIhar Hrachyshkaindeed windows uses a different implementation. It uses same macro but ends up with a different code path.. :(01:04:41
@emilazy:matrix.orgemily https://gitlab.gnome.org/GNOME/glib/-/blob/ecef4b16cfe1a67f18c82f7b12f58241922c7b89/glib/gpoll.c#L544 doesn't bother doing any checks, but Darwin's FD_SET will do overflow checks by default (see sys/_types/_fd_def.h), but _DARWIN_UNLIMITED_SELECT adjusts the behaviour 01:04:43
@emilazy:matrix.orgemilyso I think this turns something likely caught at runtime into a potential vulnerability, on Darwin01:05:06
@emilazy:matrix.orgemily I think what would be ideal is #define _DARWIN_UNLIMITED_SELECT just in this file and doing it as a heap allocation 01:05:38
@ihar.hrachyshka:matrix.orgIhar Hrachyshkaok. should I add an explicit nfds check against SET_FDSIZE in that g_poll implementation? would it save runtime?01:06:07
@emilazy:matrix.orgemily of a struct { int32_t fds_bits[]; } 01:06:13
@emilazy:matrix.orgemilyyeah that would also work as a cheaper fix01:06:40
@emilazy:matrix.orgemilybut it should only be a few lines to do the heap allocation thing01:06:45
@emilazy:matrix.orgemilysomething like…01:08:49
@emilazy:matrix.orgemily
  fd_set rset_stack, wset_stack, xset_stack;
  fd_set *rset = &rset_stack, *wset = &wset_stack, *xset = &xset_stack;

  if (nfds > FD_SETSIZE)
    {
      size_t nelems = __DARWIN_howmany(nfds, __DARWIN_NFDBITS);
      size_t size = sizeof (struct { int32_t fds_bits[nelems] });
      rset = g_malloc0 (size);
      wset = g_malloc0 (size);
      xset = g_malloc0 (size);
    }

  …

  if (nfds > FD_SETSIZE)
    {
      g_free (rset);
      g_free (wset);
      g_free (xset);
    }
01:12:50

Show newer messages


Back to Room ListRoom Version: 6