* x86: Fixup some nits in longjmp asm implementation
@ 2024-01-04 22:16 Noah Goldstein
2024-01-04 22:22 ` H.J. Lu
` (3 more replies)
0 siblings, 4 replies; 14+ messages in thread
From: Noah Goldstein @ 2024-01-04 22:16 UTC (permalink / raw)
To: libc-alpha; +Cc: goldstein.w.n, hjl.tools, carlos
1) Replace `jne` with `jb`. This is generally safer incase either
r10/rcx are misaligned.
2) Replace a stray `nop` with a `.p2align` directive.
---
sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S | 2 +-
sysdeps/x86_64/__longjmp.S | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S b/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S
index 9aa24620b9..083ffb33f2 100644
--- a/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S
+++ b/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S
@@ -57,7 +57,7 @@ longjmp_msg:
cfi_def_cfa_offset(16); \
LOAD_MSG; \
call HIDDEN_JUMPTARGET(__fortify_fail); \
- nop; \
+ .p2align 3, 5; \
cfi_restore_state; \
.Lok2: \
movq %r10, %rdi; \
diff --git a/sysdeps/x86_64/__longjmp.S b/sysdeps/x86_64/__longjmp.S
index 22fedc4997..d38ace7512 100644
--- a/sysdeps/x86_64/__longjmp.S
+++ b/sysdeps/x86_64/__longjmp.S
@@ -89,7 +89,7 @@ L(find_restore_token_loop):
subq $8, %rcx
/* Stop if the current ssp is found. */
cmpq %rcx, %r10
- jne L(find_restore_token_loop)
+ jb L(find_restore_token_loop)
jmp L(no_shadow_stack_token)
L(restore_shadow_stack):
--
2.34.1
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: x86: Fixup some nits in longjmp asm implementation
2024-01-04 22:16 x86: Fixup some nits in longjmp asm implementation Noah Goldstein
@ 2024-01-04 22:22 ` H.J. Lu
2024-01-04 22:40 ` Andreas Schwab
2024-01-04 23:25 ` Noah Goldstein
` (2 subsequent siblings)
3 siblings, 1 reply; 14+ messages in thread
From: H.J. Lu @ 2024-01-04 22:22 UTC (permalink / raw)
To: Noah Goldstein; +Cc: libc-alpha, carlos, Andreas Schwab
On Thu, Jan 4, 2024 at 2:16 PM Noah Goldstein <goldstein.w.n@gmail.com> wrote:
>
> 1) Replace `jne` with `jb`. This is generally safer incase either
> r10/rcx are misaligned.
>
> 2) Replace a stray `nop` with a `.p2align` directive.
> ---
> sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S | 2 +-
> sysdeps/x86_64/__longjmp.S | 2 +-
> 2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S b/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S
> index 9aa24620b9..083ffb33f2 100644
> --- a/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S
> +++ b/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S
> @@ -57,7 +57,7 @@ longjmp_msg:
> cfi_def_cfa_offset(16); \
> LOAD_MSG; \
> call HIDDEN_JUMPTARGET(__fortify_fail); \
> - nop; \
> + .p2align 3, 5; \
This looks good to me.
commit e451d22b22c959a4dbf86dbc9f125985601473ab
Author: Andreas Schwab <schwab@redhat.com>
Date: Thu Apr 7 16:23:52 2011 -0400
Maintain stack alignment in ____longjmp_chk on x86_64
had
#ifdef PIC
-# define CALL_FAIL leaq longjmp_msg(%rip), %rdi; \
- call __GI___fortify_fail
+# define CALL_FAIL subq $8, %rsp; \
+ cfi_remember_state; \
+ cfi_def_cfa_offset(16); \
+ leaq longjmp_msg(%rip), %rdi; \
+ call __GI___fortify_fail; \
+ nop; \
+ cfi_restore_state
I don't think NOP is required.
> cfi_restore_state; \
> .Lok2: \
> movq %r10, %rdi; \
> diff --git a/sysdeps/x86_64/__longjmp.S b/sysdeps/x86_64/__longjmp.S
> index 22fedc4997..d38ace7512 100644
> --- a/sysdeps/x86_64/__longjmp.S
> +++ b/sysdeps/x86_64/__longjmp.S
> @@ -89,7 +89,7 @@ L(find_restore_token_loop):
> subq $8, %rcx
> /* Stop if the current ssp is found. */
> cmpq %rcx, %r10
> - jne L(find_restore_token_loop)
> + jb L(find_restore_token_loop)
We should stop searching only if we find a match for
the current SSP. We shouldn't stop searching for JA.
> jmp L(no_shadow_stack_token)
>
> L(restore_shadow_stack):
> --
> 2.34.1
>
--
H.J.
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: x86: Fixup some nits in longjmp asm implementation
2024-01-04 22:22 ` H.J. Lu
@ 2024-01-04 22:40 ` Andreas Schwab
2024-01-04 23:07 ` Noah Goldstein
2024-01-04 23:42 ` H.J. Lu
0 siblings, 2 replies; 14+ messages in thread
From: Andreas Schwab @ 2024-01-04 22:40 UTC (permalink / raw)
To: H.J. Lu; +Cc: Noah Goldstein, libc-alpha, carlos
On Jan 04 2024, H.J. Lu wrote:
> #ifdef PIC
> -# define CALL_FAIL leaq longjmp_msg(%rip), %rdi; \
> - call __GI___fortify_fail
> +# define CALL_FAIL subq $8, %rsp; \
> + cfi_remember_state; \
> + cfi_def_cfa_offset(16); \
> + leaq longjmp_msg(%rip), %rdi; \
> + call __GI___fortify_fail; \
> + nop; \
> + cfi_restore_state
>
> I don't think NOP is required.
Is the unwind information correct without the nop? Without it, the
return address points to the following label. It is customary that a
noreturn call is followed by a nop to avoid that.
--
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1
"And now for something completely different."
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: x86: Fixup some nits in longjmp asm implementation
2024-01-04 22:40 ` Andreas Schwab
@ 2024-01-04 23:07 ` Noah Goldstein
2024-01-04 23:42 ` H.J. Lu
1 sibling, 0 replies; 14+ messages in thread
From: Noah Goldstein @ 2024-01-04 23:07 UTC (permalink / raw)
To: Andreas Schwab; +Cc: H.J. Lu, libc-alpha, carlos
On Thu, Jan 4, 2024 at 2:40 PM Andreas Schwab <schwab@linux-m68k.org> wrote:
>
> On Jan 04 2024, H.J. Lu wrote:
>
> > #ifdef PIC
> > -# define CALL_FAIL leaq longjmp_msg(%rip), %rdi; \
> > - call __GI___fortify_fail
> > +# define CALL_FAIL subq $8, %rsp; \
> > + cfi_remember_state; \
> > + cfi_def_cfa_offset(16); \
> > + leaq longjmp_msg(%rip), %rdi; \
> > + call __GI___fortify_fail; \
> > + nop; \
> > + cfi_restore_state
> >
> > I don't think NOP is required.
>
> Is the unwind information correct without the nop? Without it, the
> return address points to the following label. It is customary that a
> noreturn call is followed by a nop to avoid that.
Any link about why it wouldn't be. The only related mention I could find
was:
https://stackoverflow.com/questions/44854497/why-does-64-bit-vc-compiler-add-nop-instruction-after-function-calls
which seems to argue its potentially an unwind optimization, but not
for correctness.
>
> --
> Andreas Schwab, schwab@linux-m68k.org
> GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1
> "And now for something completely different."
^ permalink raw reply [flat|nested] 14+ messages in thread
* x86: Fixup some nits in longjmp asm implementation
2024-01-04 22:16 x86: Fixup some nits in longjmp asm implementation Noah Goldstein
2024-01-04 22:22 ` H.J. Lu
@ 2024-01-04 23:25 ` Noah Goldstein
2024-01-05 16:33 ` H.J. Lu
2024-01-05 19:12 ` Noah Goldstein
2024-01-05 22:00 ` Noah Goldstein
3 siblings, 1 reply; 14+ messages in thread
From: Noah Goldstein @ 2024-01-04 23:25 UTC (permalink / raw)
To: libc-alpha; +Cc: goldstein.w.n, hjl.tools, carlos
Replace a stray `nop` with a `.p2align` directive.
---
sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S b/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S
index 9aa24620b9..083ffb33f2 100644
--- a/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S
+++ b/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S
@@ -57,7 +57,7 @@ longjmp_msg:
cfi_def_cfa_offset(16); \
LOAD_MSG; \
call HIDDEN_JUMPTARGET(__fortify_fail); \
- nop; \
+ .p2align 3, 5; \
cfi_restore_state; \
.Lok2: \
movq %r10, %rdi; \
--
2.34.1
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: x86: Fixup some nits in longjmp asm implementation
2024-01-04 22:40 ` Andreas Schwab
2024-01-04 23:07 ` Noah Goldstein
@ 2024-01-04 23:42 ` H.J. Lu
2024-01-05 11:18 ` Andreas Schwab
1 sibling, 1 reply; 14+ messages in thread
From: H.J. Lu @ 2024-01-04 23:42 UTC (permalink / raw)
To: Andreas Schwab; +Cc: Noah Goldstein, libc-alpha, carlos
On Thu, Jan 4, 2024 at 2:40 PM Andreas Schwab <schwab@linux-m68k.org> wrote:
>
> On Jan 04 2024, H.J. Lu wrote:
>
> > #ifdef PIC
> > -# define CALL_FAIL leaq longjmp_msg(%rip), %rdi; \
> > - call __GI___fortify_fail
> > +# define CALL_FAIL subq $8, %rsp; \
> > + cfi_remember_state; \
> > + cfi_def_cfa_offset(16); \
> > + leaq longjmp_msg(%rip), %rdi; \
> > + call __GI___fortify_fail; \
> > + nop; \
> > + cfi_restore_state
> >
> > I don't think NOP is required.
>
> Is the unwind information correct without the nop? Without it, the
> return address points to the following label. It is customary that a
> noreturn call is followed by a nop to avoid that.
>
Without the return address is the next instruction,
movq %r10, %rdi
What difference does NOP here make? Are there any visible
impacts without NOP?
--
H.J.
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: x86: Fixup some nits in longjmp asm implementation
2024-01-04 23:42 ` H.J. Lu
@ 2024-01-05 11:18 ` Andreas Schwab
2024-01-05 15:22 ` H.J. Lu
0 siblings, 1 reply; 14+ messages in thread
From: Andreas Schwab @ 2024-01-05 11:18 UTC (permalink / raw)
To: H.J. Lu; +Cc: Noah Goldstein, libc-alpha, carlos
On Jan 04 2024, H.J. Lu wrote:
> On Thu, Jan 4, 2024 at 2:40 PM Andreas Schwab <schwab@linux-m68k.org> wrote:
>>
>> On Jan 04 2024, H.J. Lu wrote:
>>
>> > #ifdef PIC
>> > -# define CALL_FAIL leaq longjmp_msg(%rip), %rdi; \
>> > - call __GI___fortify_fail
>> > +# define CALL_FAIL subq $8, %rsp; \
>> > + cfi_remember_state; \
>> > + cfi_def_cfa_offset(16); \
>> > + leaq longjmp_msg(%rip), %rdi; \
>> > + call __GI___fortify_fail; \
>> > + nop; \
>> > + cfi_restore_state
>> >
>> > I don't think NOP is required.
>>
>> Is the unwind information correct without the nop? Without it, the
>> return address points to the following label. It is customary that a
>> noreturn call is followed by a nop to avoid that.
>>
>
> Without the return address is the next instruction,
>
> movq %r10, %rdi
>
> What difference does NOP here make? Are there any visible
> impacts without NOP?
Does backtrace work correctly in gdb at each and every point?
--
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1
"And now for something completely different."
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: x86: Fixup some nits in longjmp asm implementation
2024-01-05 11:18 ` Andreas Schwab
@ 2024-01-05 15:22 ` H.J. Lu
2024-01-05 16:42 ` Andreas Schwab
0 siblings, 1 reply; 14+ messages in thread
From: H.J. Lu @ 2024-01-05 15:22 UTC (permalink / raw)
To: Andreas Schwab; +Cc: Noah Goldstein, libc-alpha, carlos
On Fri, Jan 5, 2024 at 3:18 AM Andreas Schwab <schwab@linux-m68k.org> wrote:
>
> On Jan 04 2024, H.J. Lu wrote:
>
> > On Thu, Jan 4, 2024 at 2:40 PM Andreas Schwab <schwab@linux-m68k.org> wrote:
> >>
> >> On Jan 04 2024, H.J. Lu wrote:
> >>
> >> > #ifdef PIC
> >> > -# define CALL_FAIL leaq longjmp_msg(%rip), %rdi; \
> >> > - call __GI___fortify_fail
> >> > +# define CALL_FAIL subq $8, %rsp; \
> >> > + cfi_remember_state; \
> >> > + cfi_def_cfa_offset(16); \
> >> > + leaq longjmp_msg(%rip), %rdi; \
> >> > + call __GI___fortify_fail; \
> >> > + nop; \
> >> > + cfi_restore_state
> >> >
> >> > I don't think NOP is required.
> >>
> >> Is the unwind information correct without the nop? Without it, the
> >> return address points to the following label. It is customary that a
> >> noreturn call is followed by a nop to avoid that.
> >>
> >
> > Without the return address is the next instruction,
> >
> > movq %r10, %rdi
> >
> > What difference does NOP here make? Are there any visible
> > impacts without NOP?
>
> Does backtrace work correctly in gdb at each and every point?
>
With this change:
diff --git a/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S
b/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S
index 9aa24620b9..0da7c0133e 100644
--- a/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S
+++ b/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S
@@ -57,7 +57,6 @@ longjmp_msg:
cfi_def_cfa_offset(16); \
LOAD_MSG; \
call HIDDEN_JUMPTARGET(__fortify_fail); \
- nop; \
cfi_restore_state; \
.Lok2: \
movq %r10, %rdi;
on debug/tst-longjmp_chk, I got
0x000055555532334c <+124>: call 0x555555324420 <__GI___fortify_fail>
(gdb) c
Continuing.
Breakpoint 3, 0x000055555532334c in ____longjmp_chk ()
at ../sysdeps/x86_64/__longjmp.S:57
57 CHECK_INVALID_LONGJMP
(gdb) bt
#0 0x000055555532334c in ____longjmp_chk ()
at ../sysdeps/x86_64/__longjmp.S:57
#1 0x0000555555324c9f in __GI___longjmp_chk (
env=env@entry=0x55555555a200 <b>, val=val@entry=1)
at ../setjmp/longjmp.c:41
#2 0x0000555555556a00 in do_test () at tst-longjmp_chk.c:70
#3 0x0000555555557312 in support_test_main (argc=1, argv=0x7fffffffdcd0,
config=config@entry=0x7fffffffdb50) at support_test_main.c:413
#4 0x000055555555673f in main (argc=<optimized out>, argv=<optimized out>)
at ../support/test-driver.c:170
(gdb) si
__GI___fortify_fail (
msg=0x5555553b712b <longjmp_msg> "longjmp causes uninitialized
stack frame") at fortify_fail.c:23
23 {
(gdb) bt
#0 __GI___fortify_fail (
msg=0x5555553b712b <longjmp_msg> "longjmp causes uninitialized
stack frame") at fortify_fail.c:23
#1 0x0000555555323351 in ____longjmp_chk ()
at ../sysdeps/x86_64/__longjmp.S:57
#2 0x0000555555324c9f in __GI___longjmp_chk (
env=env@entry=0x55555555a200 <b>, val=val@entry=1)
at ../setjmp/longjmp.c:41
#3 0x0000555555556a00 in do_test () at tst-longjmp_chk.c:70
#4 0x0000555555557312 in support_test_main (argc=1, argv=0x7fffffffdcd0,
config=config@entry=0x7fffffffdb50) at support_test_main.c:413
#5 0x000055555555673f in main (argc=<optimized out>, argv=<optimized out>)
at ../support/test-driver.c:170
(gdb)
Does it look OK?
--
H.J.
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: x86: Fixup some nits in longjmp asm implementation
2024-01-04 23:25 ` Noah Goldstein
@ 2024-01-05 16:33 ` H.J. Lu
0 siblings, 0 replies; 14+ messages in thread
From: H.J. Lu @ 2024-01-05 16:33 UTC (permalink / raw)
To: Noah Goldstein; +Cc: libc-alpha, carlos
On Thu, Jan 4, 2024 at 3:25 PM Noah Goldstein <goldstein.w.n@gmail.com> wrote:
>
> Replace a stray `nop` with a `.p2align` directive.
> ---
> sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S b/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S
> index 9aa24620b9..083ffb33f2 100644
> --- a/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S
> +++ b/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S
> @@ -57,7 +57,7 @@ longjmp_msg:
> cfi_def_cfa_offset(16); \
> LOAD_MSG; \
> call HIDDEN_JUMPTARGET(__fortify_fail); \
> - nop; \
> + .p2align 3, 5; \
p2align should be placed after cfi_restore_state.
> cfi_restore_state; \
> .Lok2: \
> movq %r10, %rdi; \
> --
> 2.34.1
>
--
H.J.
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: x86: Fixup some nits in longjmp asm implementation
2024-01-05 15:22 ` H.J. Lu
@ 2024-01-05 16:42 ` Andreas Schwab
0 siblings, 0 replies; 14+ messages in thread
From: Andreas Schwab @ 2024-01-05 16:42 UTC (permalink / raw)
To: H.J. Lu; +Cc: Noah Goldstein, libc-alpha, carlos
Seems to be ok.
--
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1
"And now for something completely different."
^ permalink raw reply [flat|nested] 14+ messages in thread
* x86: Fixup some nits in longjmp asm implementation
2024-01-04 22:16 x86: Fixup some nits in longjmp asm implementation Noah Goldstein
2024-01-04 22:22 ` H.J. Lu
2024-01-04 23:25 ` Noah Goldstein
@ 2024-01-05 19:12 ` Noah Goldstein
2024-01-05 20:09 ` H.J. Lu
2024-01-05 22:00 ` Noah Goldstein
3 siblings, 1 reply; 14+ messages in thread
From: Noah Goldstein @ 2024-01-05 19:12 UTC (permalink / raw)
To: libc-alpha; +Cc: goldstein.w.n, hjl.tools, carlos
Replace a stray `nop` with a `.p2align` directive.
---
.../unix/sysv/linux/x86_64/____longjmp_chk.S | 2 +-
sysdeps/x86_64/dl-machine.h | 31 +++++++++----------
2 files changed, 16 insertions(+), 17 deletions(-)
diff --git a/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S b/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S
index 9aa24620b9..9d9732afdc 100644
--- a/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S
+++ b/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S
@@ -57,8 +57,8 @@ longjmp_msg:
cfi_def_cfa_offset(16); \
LOAD_MSG; \
call HIDDEN_JUMPTARGET(__fortify_fail); \
- nop; \
cfi_restore_state; \
+ .p2align 3, 5; \
.Lok2: \
movq %r10, %rdi; \
cfi_restore (%rdi); \
diff --git a/sysdeps/x86_64/dl-machine.h b/sysdeps/x86_64/dl-machine.h
index adcc0f7113..7ef6e24eb5 100644
--- a/sysdeps/x86_64/dl-machine.h
+++ b/sysdeps/x86_64/dl-machine.h
@@ -618,25 +618,24 @@ x86_64_rewrite_plt (struct link_map *map, ElfW(Addr) plt_rewrite)
if (((uint64_t) disp + (uint64_t) ((uint32_t) INT32_MIN))
<= (uint64_t) UINT32_MAX)
{
- pad = branch_start + JMP32_INSN_SIZE;
+ pad = branch_start + JMP32_INSN_SIZE;
- if (__glibc_unlikely (pad > plt_end))
- continue;
+ if (__glibc_unlikely (pad > plt_end))
+ continue;
- /* If the target branch can be reached with a direct branch,
- rewrite the PLT entry with a direct branch. */
- if (__glibc_unlikely (GLRO(dl_debug_mask) & DL_DEBUG_BINDINGS))
- {
- const char *sym_name = x86_64_reloc_symbol_name (map,
- reloc);
- _dl_debug_printf ("changing '%s' PLT entry in '%s' to "
- "direct branch\n", sym_name,
- DSO_FILENAME (map->l_name));
- }
+ /* If the target branch can be reached with a direct branch,
+ rewrite the PLT entry with a direct branch. */
+ if (__glibc_unlikely (GLRO (dl_debug_mask) & DL_DEBUG_BINDINGS))
+ {
+ const char *sym_name = x86_64_reloc_symbol_name (map, reloc);
+ _dl_debug_printf ("changing '%s' PLT entry in '%s' to "
+ "direct branch\n",
+ sym_name, DSO_FILENAME (map->l_name));
+ }
- /* Write out direct branch. */
- *(uint8_t *) branch_start = JMP32_INSN_OPCODE;
- *((uint32_t *) (branch_start + 1)) = disp;
+ /* Write out direct branch. */
+ *(uint8_t *) branch_start = JMP32_INSN_OPCODE;
+ *((uint32_t *) (branch_start + 1)) = disp;
}
else
{
--
2.34.1
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: x86: Fixup some nits in longjmp asm implementation
2024-01-05 19:12 ` Noah Goldstein
@ 2024-01-05 20:09 ` H.J. Lu
0 siblings, 0 replies; 14+ messages in thread
From: H.J. Lu @ 2024-01-05 20:09 UTC (permalink / raw)
To: Noah Goldstein; +Cc: libc-alpha, carlos
On Fri, Jan 5, 2024 at 11:12 AM Noah Goldstein <goldstein.w.n@gmail.com> wrote:
>
> Replace a stray `nop` with a `.p2align` directive.
> ---
> .../unix/sysv/linux/x86_64/____longjmp_chk.S | 2 +-
> sysdeps/x86_64/dl-machine.h | 31 +++++++++----------
> 2 files changed, 16 insertions(+), 17 deletions(-)
>
> diff --git a/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S b/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S
> index 9aa24620b9..9d9732afdc 100644
> --- a/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S
> +++ b/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S
> @@ -57,8 +57,8 @@ longjmp_msg:
> cfi_def_cfa_offset(16); \
> LOAD_MSG; \
> call HIDDEN_JUMPTARGET(__fortify_fail); \
> - nop; \
> cfi_restore_state; \
> + .p2align 3, 5; \
> .Lok2: \
> movq %r10, %rdi; \
> cfi_restore (%rdi); \
> diff --git a/sysdeps/x86_64/dl-machine.h b/sysdeps/x86_64/dl-machine.h
> index adcc0f7113..7ef6e24eb5 100644
> --- a/sysdeps/x86_64/dl-machine.h
> +++ b/sysdeps/x86_64/dl-machine.h
> @@ -618,25 +618,24 @@ x86_64_rewrite_plt (struct link_map *map, ElfW(Addr) plt_rewrite)
> if (((uint64_t) disp + (uint64_t) ((uint32_t) INT32_MIN))
> <= (uint64_t) UINT32_MAX)
> {
> - pad = branch_start + JMP32_INSN_SIZE;
> + pad = branch_start + JMP32_INSN_SIZE;
These changes are unrelated.
> - if (__glibc_unlikely (pad > plt_end))
> - continue;
> + if (__glibc_unlikely (pad > plt_end))
> + continue;
>
> - /* If the target branch can be reached with a direct branch,
> - rewrite the PLT entry with a direct branch. */
> - if (__glibc_unlikely (GLRO(dl_debug_mask) & DL_DEBUG_BINDINGS))
> - {
> - const char *sym_name = x86_64_reloc_symbol_name (map,
> - reloc);
> - _dl_debug_printf ("changing '%s' PLT entry in '%s' to "
> - "direct branch\n", sym_name,
> - DSO_FILENAME (map->l_name));
> - }
> + /* If the target branch can be reached with a direct branch,
> + rewrite the PLT entry with a direct branch. */
> + if (__glibc_unlikely (GLRO (dl_debug_mask) & DL_DEBUG_BINDINGS))
> + {
> + const char *sym_name = x86_64_reloc_symbol_name (map, reloc);
> + _dl_debug_printf ("changing '%s' PLT entry in '%s' to "
> + "direct branch\n",
> + sym_name, DSO_FILENAME (map->l_name));
> + }
>
> - /* Write out direct branch. */
> - *(uint8_t *) branch_start = JMP32_INSN_OPCODE;
> - *((uint32_t *) (branch_start + 1)) = disp;
> + /* Write out direct branch. */
> + *(uint8_t *) branch_start = JMP32_INSN_OPCODE;
> + *((uint32_t *) (branch_start + 1)) = disp;
> }
> else
> {
> --
> 2.34.1
>
--
H.J.
^ permalink raw reply [flat|nested] 14+ messages in thread
* x86: Fixup some nits in longjmp asm implementation
2024-01-04 22:16 x86: Fixup some nits in longjmp asm implementation Noah Goldstein
` (2 preceding siblings ...)
2024-01-05 19:12 ` Noah Goldstein
@ 2024-01-05 22:00 ` Noah Goldstein
2024-01-05 22:29 ` H.J. Lu
3 siblings, 1 reply; 14+ messages in thread
From: Noah Goldstein @ 2024-01-05 22:00 UTC (permalink / raw)
To: libc-alpha; +Cc: goldstein.w.n, hjl.tools, carlos
Replace a stray `nop` with a `.p2align` directive.
---
sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S b/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S
index 9aa24620b9..9d9732afdc 100644
--- a/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S
+++ b/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S
@@ -57,8 +57,8 @@ longjmp_msg:
cfi_def_cfa_offset(16); \
LOAD_MSG; \
call HIDDEN_JUMPTARGET(__fortify_fail); \
- nop; \
cfi_restore_state; \
+ .p2align 3, 5; \
.Lok2: \
movq %r10, %rdi; \
cfi_restore (%rdi); \
--
2.34.1
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: x86: Fixup some nits in longjmp asm implementation
2024-01-05 22:00 ` Noah Goldstein
@ 2024-01-05 22:29 ` H.J. Lu
0 siblings, 0 replies; 14+ messages in thread
From: H.J. Lu @ 2024-01-05 22:29 UTC (permalink / raw)
To: Noah Goldstein; +Cc: libc-alpha, carlos
On Fri, Jan 5, 2024 at 2:00 PM Noah Goldstein <goldstein.w.n@gmail.com> wrote:
>
> Replace a stray `nop` with a `.p2align` directive.
> ---
> sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S b/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S
> index 9aa24620b9..9d9732afdc 100644
> --- a/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S
> +++ b/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S
> @@ -57,8 +57,8 @@ longjmp_msg:
> cfi_def_cfa_offset(16); \
> LOAD_MSG; \
> call HIDDEN_JUMPTARGET(__fortify_fail); \
> - nop; \
> cfi_restore_state; \
> + .p2align 3, 5; \
> .Lok2: \
> movq %r10, %rdi; \
> cfi_restore (%rdi); \
> --
> 2.34.1
>
LGTM.
Thanks.
--
H.J.
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2024-01-05 22:30 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-04 22:16 x86: Fixup some nits in longjmp asm implementation Noah Goldstein
2024-01-04 22:22 ` H.J. Lu
2024-01-04 22:40 ` Andreas Schwab
2024-01-04 23:07 ` Noah Goldstein
2024-01-04 23:42 ` H.J. Lu
2024-01-05 11:18 ` Andreas Schwab
2024-01-05 15:22 ` H.J. Lu
2024-01-05 16:42 ` Andreas Schwab
2024-01-04 23:25 ` Noah Goldstein
2024-01-05 16:33 ` H.J. Lu
2024-01-05 19:12 ` Noah Goldstein
2024-01-05 20:09 ` H.J. Lu
2024-01-05 22:00 ` Noah Goldstein
2024-01-05 22:29 ` H.J. Lu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).