[Bug 4064] New: mkstemp() macro breaks glibc's _FILE_OFFSET_BITS=64 redirect on 32-bit platforms (binaries import mkstemp at GLIBC_2.0)

bugzilla-daemon at mindrot.org bugzilla-daemon at mindrot.org
Mon Nov 23 22:03:05 AEDT 2026


https://bugzilla.mindrot.org/show_bug.cgi?id=4064

            Bug ID: 4064
           Summary: mkstemp() macro breaks glibc's _FILE_OFFSET_BITS=64
                    redirect on 32-bit platforms (binaries import
                    mkstemp at GLIBC_2.0)
           Product: Portable OpenSSH
           Version: -current
          Hardware: PPC
                OS: Linux
            Status: NEW
          Severity: minor
          Priority: P5
         Component: Build system
          Assignee: unassigned-bugs at mindrot.org
          Reporter: keragez at gmail.com

Created attachment 4035
  --> https://bugzilla.mindrot.org/attachment.cgi?id=4035&action=edit
One-liner patch

On 32-bit glibc systems built with -D_FILE_OFFSET_BITS=64, OpenSSH
binaries end up importing the 32-bit off_t mkstemp() instead of
mkstemp64().

glibc's <stdlib.h> declares mkstemp() as an asm redirect when
_FILE_OFFSET_BITS=64:

    extern int mkstemp(char *) __asm__("mkstemp64");

openbsd-compat/openbsd-compat.h defines

    #define mkstemp(x) _ssh_mkstemp(x)

without having included <stdlib.h>. Most sources include
openbsd-compat.h (via includes.h) before <stdlib.h>, so when <stdlib.h>
is processed the macro rewrites glibc's declaration into

    extern int _ssh_mkstemp(char *) __asm__("mkstemp64");

As a result:
  - callers of mkstemp() bind directly to libc's "mkstemp64" symbol,
    bypassing the _ssh_mkstemp() wrapper, and
  - the wrapper in openbsd-compat/mktemp.c (which #undefs the macro and
    declares a plain "int mkstemp(char *)") calls the 32-bit off_t
    mkstemp().

So binaries import mkstemp at GLIBC_2.0 despite the large-file build.

Fix: include <stdlib.h> in openbsd-compat.h before the macro is
defined, so glibc declares mkstemp() with its redirect first. Callers
then use _ssh_mkstemp and the wrapper calls mkstemp64. Patch attached
(one line); also available as
https://github.com/openssh/openssh-portable/pull/739

How it was found / tested:
Cross build for 32-bit PowerPC (e500v2), glibc 2.44, with
-D_TIME_BITS=64 -D_FILE_OFFSET_BITS=64, while auditing for leftover
32-bit time_t/off_t symbol imports. Checked with readelf --dyn-syms:
  before: mkstemp at GLIBC_2.0 imported
  after:  mkstemp64 imported; wrapper emitted as _ssh_mkstemp

Analysis and patch done with the help of an AI assistant; reviewed and
verified by me.

-- 
You are receiving this mail because:
You are watching the assignee of the bug.


More information about the openssh-bugs mailing list