This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libc/20596] sprintf segmentation fault due to misaligned movaps on x86_64


https://sourceware.org/bugzilla/show_bug.cgi?id=20596

Florian Weimer <fweimer at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |fweimer at redhat dot com
              Flags|                            |security-

--- Comment #1 from Florian Weimer <fweimer at redhat dot com> ---
(In reply to Andrew Thomas from comment #0)
> sprintf and snprintf fail with a segmentation fault due to a movaps
> instruction that is not 16-byte aligned.  I run into this with a call like:
>    double value = 2.5;
>    sprintf (buf, "%.20g", value);
> 
> The problem is that sprintf enters with the stack aligned to an arbitrary
> boundary and then executes movaps on 16-byte offsets from %rsp.  On my
> 64-bit system the stack alignment is 8 bytes.  Depending on the calling
> sequence leading up to the sprintf call, sprintf may or may not crash.

What kind of system is this?

> The problem gets worse in that sprintf subtracts 0xd8 bytes from %rsp on
> entry, so even if the stack is aligned to 16 bytes on function entry, it
> will be misaligned by the time it calls movaps.  It's not helpful to compile
> application code with -mstackrealign.

The official x86_64 ABI specification says that the stack is 16-byte-aligned
when the function is called (so with the return address pushed, the alignment
is congruent 8 modulo 16).  The __sprintf disassembly you showed respects that.

To be honest, this looks more like a bug in the code calling sprintf.  Can you
provide a call stack?

-- 
You are receiving this mail because:
You are on the CC list for the bug.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]