Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CACC_My9fj50WAKpOSr_1mn2VeXvBYDA0Xt5U+8tW-YCfw9XKgw@mail.gmail.com>
Date: Sun, 22 Mar 2026 16:41:41 +0100
From: Lukas Tribus <lukas@...i.eu>
To: musl@...ts.openwall.com
Subject: Type confusion in include/sched.h (was: Discrepancy in include/sched.h – breaks haproxy's CPU topology discovery)

Dear list,


On Fri, 5 Sept 2025 at 21:23, rafamiga <rafamiga@...il.com> wrote:
>
> While working on a fix for haproxy load balancer running in a container built with musl a discrepancy was found in include/sched.h. Long story short, on a 48 CPU system haproxy was reporting just 32 CPUs. I'm forwarding findings to this list to let you know that a change might be considered.
>
> Original bug report: https://github.com/haproxy/haproxy/issues/3103
>
> Citing the author (wtarreau):
>
> Oh I think I found it! The issue is here in sched.h:
>
> #define __CPU_op_S(i, size, set, op) ( (i)/8U >= (size) ? 0 : \
> (((unsigned long *)(set))[(i)/8/sizeof(long)] op (1UL<<((i)%(8*sizeof(long))))) )
>
> but CPU_ISSET() is defined as:
>
> #define CPU_ISSET(i, set) CPU_ISSET_S(i,sizeof(cpu_set_t),set)
>
> See ? It returns an unsigned long which is returned as-is by the macro. However the man says that CPU_ISSET() must return an int. So in our case it's returned as-is and truncated to the lowest 32 bits.
>
> The fix for the lib would be simple:
>
> -#define CPU_ISSET(i, set) CPU_ISSET_S(i,sizeof(cpu_set_t),set)
> +#define CPU_ISSET(i, set) (CPU_ISSET_S(i,sizeof(cpu_set_t),set) != 0)
>
> It should be reported to the project.


Any feedback on the above report regarding a unsigned long vs int type
mismatch and the change suggested by Willy Tarreau?



Thanks,
Lukas

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.