Skip to content

Instantly share code, notes, and snippets.

@wataash
Last active May 6, 2020 04:14
Show Gist options
  • Save wataash/0a55bdaedf723b8145f8f3478d6d3f0f to your computer and use it in GitHub Desktop.
Save wataash/0a55bdaedf723b8145f8f3478d6d3f0f to your computer and use it in GitHub Desktop.
wsl glibc-2.31のワークアラウンド https://qiita.com/mmns/items/eaf42dd3345a2285ff9e
# MIT License
#
# Copyright (c) 2020 Wataru Ashihara
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# https://qiita.com/mmns/items/eaf42dd3345a2285ff9e
# https://twitter.com/wata_ash/status/1255130650723487746
# 筆者はWindowsを持っていなくてUbuntuでしか試していない。
# 高確率で環境破壊するので自己責任でお願いします。
# ------------------------------------------------------------------------------
# 環境の確認
cat /etc/lsb-release # DISTRIB_DESCRIPTION="Ubuntu 20.04"
# md5sum が異なったら終了して下さい。(そしてできれば教えて下さい)
md5sum /usr/lib/x86_64-linux-gnu/libc-2.31.so # 10fdeb77eea525914332769e9cd912ae
# ------------------------------------------------------------------------------
# バグの確認
echo > a.c '
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(int argc, char *argv[]) {
const struct timespec ts = {.tv_sec = 1};
printf("sleep 1\n");
if (nanosleep(&ts, NULL) == -1) {
perror("nanosleep");
exit(EXIT_FAILURE);
}
printf("done\n");
}'
cc a.c
./a.out
# 通常のUbuntuなら1秒スリープするが、
# WSLだと nanosleep: Invalid argument と出力してすぐ終了すると思われる
# ------------------------------------------------------------------------------
# HACK
cp -v /usr/lib/x86_64-linux-gnu/libc-2.31.so ./libc-2.31.so.work.0.realtime.orig
cp -v /usr/lib/x86_64-linux-gnu/libc-2.31.so ./libc-2.31.so.work.1.monotonic
cp -v /usr/lib/x86_64-linux-gnu/libc-2.31.so ./libc-2.31.so.work.7.boottime
echo -en '\xbf\x01\x00\x00\x00' | dd seek=918244 bs=1 count=5 of=./libc-2.31.so.work.1.monotonic
dd skip=918249 seek=918249 bs=1 if=./libc-2.31.so.work.0.realtime.orig of=./libc-2.31.so.work.1.monotonic
echo -en '\xbf\x07\x00\x00\x00' | dd seek=918244 bs=1 count=5 of=./libc-2.31.so.work.7.boottime
dd skip=918249 seek=918249 bs=1 if=./libc-2.31.so.work.0.realtime.orig of=./libc-2.31.so.work.7.boottime
# ------------------------------------------------------------------------------
# 確認
ls -l ./libc* # 全て 2029224 バイト
md5sum ./libc-2.31.so.work.0.realtime.orig # 10fdeb77eea525914332769e9cd912ae
md5sum ./libc-2.31.so.work.1.monotonic # a3de8ddf981b31db75c2e14fb9a330c8
md5sum ./libc-2.31.so.work.7.boottime # cc62215f49f8f229f8294c005ef5ec51
# objdump --disassemble=clock_nanosleep ./libc-2.31.so.work.0.original
# objdump --disassemble=clock_nanosleep ./libc-2.31.so.work.1.monotonic
# objdump --disassemble=clock_nanosleep ./libc-2.31.so.work.7.boottime
# ------------------------------------------------------------------------------
# Install・ためす (キケン)
# 直接cpしないこと!!死にます(コメント参照)
cp -v ./libc-2.31.so.work.1.monotonic tmp && sudo mv -v tmp /usr/lib/x86_64-linux-gnu/libc-2.31.so
./a.out # 1秒sleepすればOK
cp -v ./libc-2.31.so.work.7.boottime tmp && sudo mv -v tmp /usr/lib/x86_64-linux-gnu/libc-2.31.so
./a.out # 1秒sleepすればOK
# ------------------------------------------------------------------------------
# もどす場合
cp -v ./libc-2.31.so.work.0.orig tmp && sudo mv -v tmp /usr/lib/x86_64-linux-gnu/libc-2.31.so
./a.out # EINVAL
@wataash
Copy link
Author

wataash commented Apr 28, 2020

直接cp: sudo cp -v ./libc-2.31.so.work.1.monotonic /usr/lib/x86_64-linux-gnu/libc-2.31.so した瞬間panicした…
PID: 1 なのでinitが死んだ?

image

fs syncせずに死んだおかげでオリジナルのlibcのまま起動した。

@wataash
Copy link
Author

wataash commented Apr 28, 2020

memo
l exit from #0  __GI___clock_nanosleep (clock_id=clock_id@entry=0, flags=flags@entry=0, req=0x0, rem=0x0) at ../sysdeps/unix/sysv/linux/clock_nanosleep.c:48
__GI___nanosleep (requested_time=<optimized out>, remaining=<optimized out>) at nanosleep.c:28
28	  if (ret != 0)
Value returned is $1 = 14
(gdb) l
23	int
24	__nanosleep (const struct timespec *requested_time,
25		     struct timespec *remaining)
26	{
27	  int ret = __clock_nanosleep (CLOCK_REALTIME, 0, requested_time, remaining);
28	  if (ret != 0)
29	    {
30	      __set_errno (ret);
31	      return -1;
32	    }
(gdb) disas
Dump of assembler code for function __GI___nanosleep:
   0x00007ffff7eb5ea0 <+0>:	endbr64 
   0x00007ffff7eb5ea4 <+4>:	sub    $0x8,%rsp
   0x00007ffff7eb5ea8 <+8>:	mov    %rdi,%rdx
   0x00007ffff7eb5eab <+11>:	mov    %rsi,%rcx
   0x00007ffff7eb5eae <+14>:	xor    %edi,%edi
   0x00007ffff7eb5eb0 <+16>:	xor    %esi,%esi
   0x00007ffff7eb5eb2 <+18>:	callq  0x7ffff7eb02e0 <__GI___clock_nanosleep>
=> 0x00007ffff7eb5eb7 <+23>:	test   %eax,%eax
   0x00007ffff7eb5eb9 <+25>:	jne    0x7ffff7eb5ec0 <__GI___nanosleep+32>
   0x00007ffff7eb5ebb <+27>:	add    $0x8,%rsp
   0x00007ffff7eb5ebf <+31>:	retq   
   0x00007ffff7eb5ec0 <+32>:	mov    0x104fa9(%rip),%rdx        # 0x7ffff7fbae70
   0x00007ffff7eb5ec7 <+39>:	mov    %eax,%fs:(%rdx)
   0x00007ffff7eb5eca <+42>:	mov    $0xffffffff,%eax
   0x00007ffff7eb5ecf <+47>:	jmp    0x7ffff7eb5ebb <__GI___nanosleep+27>
End of assembler dump.













(gdb) s
27   int ret = __clock_nanosleep (CLOCK_REALTIME, 0, requested_time, remaining);
(gdb) disas
Dump of assembler code for function __GI___nanosleep:
   0x00007ffff7eb5ea0 <+0>:   endbr64 
=> 0x00007ffff7eb5ea4 <+4>:   sub    $0x8,%rsp
   0x00007ffff7eb5ea8 <+8>:   mov    %rdi,%rdx
   0x00007ffff7eb5eab <+11>:  mov    %rsi,%rcx
   0x00007ffff7eb5eae <+14>:  xor    %edi,%edi
   0x00007ffff7eb5eb0 <+16>:  xor    %esi,%esi
   0x00007ffff7eb5eb2 <+18>:  callq  0x7ffff7eb02e0 <__GI___clock_nanosleep>


CLOCK_REALTIME






1>:   mov    %rsi,%rcx
   0x00007ffff7eb5eae <+14>:  xor    %edi,%edi
   0x00007ffff7eb5eb0 <+16>:  xor    %esi,%esi
=> 0x00007ffff7eb5eb2 <+18>:  callq  0x7ffff7eb02e0 <__GI___clock_nanosleep>
   0x00007ffff7eb5eb7 <+23>:  test   %eax,%eax
   0x00007ffff7eb5eb9 <+25>:  jne    0x7ffff7eb5ec0 <__GI___nanosleep+32>
   0x00007ffff7eb5ebb <+27>:  add    $0x8,%rsp
   0x00007ffff7eb5ebf <+31>:  retq   
   0x00007ffff7eb5ec0 <+32>:  mov    0x104fa9(%rip),%rdx        # 0x7ffff7fbae70
   0x00007ffff7eb5ec7 <+39>:  mov    %eax,%fs:(%rdx)
   0x00007ffff7eb5eca <+42>:  mov    $0xffffffff,%eax
   0x00007ffff7eb5ecf <+47>:  jmp    0x7ffff7eb5ebb <__GI___nanosleep+27>
End of assembler dump.
(gdb) si
__GI___clock_nanosleep (clock_id=clock_id@entry=0, flags=flags@entry=0, req=0x0, rem=0x0) at ../sysdeps/unix/sysv/linux/clock_nanosleep.c:32
32 {
(gdb) disas
Dump of assembler code for function __GI___clock_nanosleep:
=> 0x00007ffff7eb02e0 <+0>:   endbr64 
   0x00007ffff7eb02e4 <+4>:   cmp    $0x3,%edi
   0x00007ffff7eb02e7 <+7>:   je     0x7ffff7eb0328 <__GI___clock_nanosleep+72>
   0x00007ffff7eb02e9 <+9>:   sub    $0x28,%rsp
   0x00007ffff7eb02ed <+13>:  mov    $0xfffffffa,%eax
   0x00007ffff7eb02f2 <+18>:  cmp    $0x2,%edi
   0x00007ffff7eb02f5 <+21>:  mov    %rcx,%r10
   0x00007ffff7eb02f8 <+24>:  cmove  %eax,%edi
   0x00007ffff7eb02fb <+27>:  mov    %fs:0x18,%eax
   0x00007ffff7eb0303 <+35>:  test   %eax,%eax
   0x00007ffff7eb0305 <+37>:  jne    0x7ffff7eb0330 <__GI___clock_nanosleep+80>
   0x00007ffff7eb0307 <+39>:  mov    $0xe6,%eax
   0x00007ffff7eb030c <+44>:  syscall 
   0x00007ffff7eb030e <+46>:  mov    %eax,%edx
   0x00007ffff7eb0310 <+48>:  neg    %edx
   0x00007ffff7eb0312 <+50>:  cmp    $0xfffff000,%eax
   0x00007ffff7eb0317 <+55>:  mov    $0x0,%eax
   0x00007ffff7eb031c <+60>:  cmova  %edx,%eax
   0x00007ffff7eb031f <+63>:  add    $0x28,%rsp
   0x00007ffff7eb0323 <+67>:  retq   
   0x00007ffff7eb0324 <+68>:  nopl   0x0(%rax)
   0x00007ffff7eb0328 <+72>:  mov    $0x16,%eax
   0x00007ffff7eb032d <+77>:  retq   
   0x00007ffff7eb032e <+78>:  xchg   %ax,%ax
   0x00007ffff7eb0330 <+80>:  mov    %rdx,0x10(%rsp)
   0x00007ffff7eb0335 <+85>:  mov    %esi,0xc(%rsp)
   0x00007ffff7eb0339 <+89>:  mov    %edi,(%rsp)
   0x00007ffff7eb033c <+92>:  mov    %rcx,0x18(%rsp)
   0x00007ffff7eb0341 <+97>:  callq  0x7ffff7e67760 <__libc_enable_asynccancel>
   0x00007ffff7eb0346 <+102>: mov    0x18(%rsp),%r10
   0x00007ffff7eb034b <+107>: mov    0x10(%rsp),%rdx
   0x00007ffff7eb0350 <+112>: mov    %eax,%r8d
   0x00007ffff7eb0353 <+115>: mov    0xc(%rsp),%esi
   0x00007ffff7eb0357 <+119>: mov    (%rsp),%edi
   0x00007ffff7eb035a <+122>: mov    $0xe6,%eax
   0x00007ffff7eb035f <+127>: syscall 
   0x00007ffff7eb0361 <+129>: mov    %r8d,%edi
   0x00007ffff7eb0364 <+132>: mov    %rax,(%rsp)
   0x00007ffff7eb0368 <+136>: callq  0x7ffff7e677c0 <__libc_disable_asynccancel>
   0x00007ffff7eb036d <+141>: mov    (%rsp),%rax
   0x00007ffff7eb0371 <+145>: jmp    0x7ffff7eb030e <__GI___clock_nanosleep+46>
End of assembler dump.
(gdb) p clock_id
$1 = 0
(gdb) p clock_id
$2 = 0
(gdb) info registers 
rax            0x555555555149      93824992235849
rbx            0x555555555180      93824992235904
rcx            0x0                 0
rdx            0x0                 0
rsi            0x0                 0
rdi            0x0                 0
rbp            0x7fffffffe3a0      0x7fffffffe3a0
rsp            0x7fffffffe378      0x7fffffffe378
r8             0x0                 0
r9             0x7ffff7fe0d50      140737354009936
r10            0x0                 0
r11            0x7ffff7f828c8      140737353623752
r12            0x555555555060      93824992235616
r13            0x7fffffffe490      140737488348304
r14            0x0                 0
r15            0x0                 0
rip            0x7ffff7eb02e0      0x7ffff7eb02e0 <__GI___clock_nanosleep>
eflags         0x246               [ PF ZF IF ]
cs             0x33                51
ss             0x2b                43
ds             0x0                 0
es             0x0                 0
fs             0x0                 0
gs             0x0                 0
(gdb) print %edi
A syntax error in expression, near `%edi'.
(gdb) info registers %edi
Invalid register `%edi'
(gdb) info registers edi
edi            0x0                 0
(gdb) p edi
No symbol "edi" in current context.
(gdb) set %edi=1
A syntax error in expression, near `%edi=1'.
(gdb) set $edi = 1
(gdb) p edi
No symbol "edi" in current context.
(gdb) info registers edi
edi            0x1                 1
(gdb) p clock_id
$3 = 1
(gdb) si
35   if (clock_id == CLOCK_THREAD_CPUTIME_ID)
(gdb) disas
Dump of assembler code for function __GI___clock_nanosleep:
   0x00007ffff7eb02e0 <+0>:   endbr64 
=> 0x00007ffff7eb02e4 <+4>:   cmp    $0x3,%edi
   0x00007ffff7eb02e7 <+7>:   je     0x7ffff7eb0328 <__GI___clock_nanosleep+72>
   0x00007ffff7eb02e9 <+9>:   sub    $0x28,%rsp












35	  if (clock_id == CLOCK_THREAD_CPUTIME_ID)
(gdb) disas
Dump of assembler code for function __GI___clock_nanosleep:
   0x00007ffff7eb02e0 <+0>:	endbr64 
   0x00007ffff7eb02e4 <+4>:	cmp    $0x3,%edi
   0x00007ffff7eb02e7 <+7>:	je     0x7ffff7eb0328 <__GI___clock_nanosleep+72>
=> 0x00007ffff7eb02e9 <+9>:	sub    $0x28,%rsp
   0x00007ffff7eb02ed <+13>:	mov    $0xfffffffa,%eax
   0x00007ffff7eb02f2 <+18>:	cmp    $0x2,%edi
   0x00007ffff7eb02f5 <+21>:	mov    %rcx,%r10
   0x00007ffff7eb02f8 <+24>:	cmove  %eax,%edi
   0x00007ffff7eb02fb <+27>:	mov    %fs:0x18,%eax
   0x00007ffff7eb0303 <+35>:	test   %eax,%eax
   0x00007ffff7eb0305 <+37>:	jne    0x7ffff7eb0330 <__GI___clock_nanosleep+80>
   0x00007ffff7eb0307 <+39>:	mov    $0xe6,%eax
   0x00007ffff7eb030c <+44>:	syscall 
   0x00007ffff7eb030e <+46>:	mov    %eax,%edx
   0x00007ffff7eb0310 <+48>:	neg    %edx
   0x00007ffff7eb0312 <+50>:	cmp    $0xfffff000,%eax
   0x00007ffff7eb0317 <+55>:	mov    $0x0,%eax
   0x00007ffff7eb031c <+60>:	cmova  %edx,%eax
   0x00007ffff7eb031f <+63>:	add    $0x28,%rsp
   0x00007ffff7eb0323 <+67>:	retq   
   0x00007ffff7eb0324 <+68>:	nopl   0x0(%rax)
   0x00007ffff7eb0328 <+72>:	mov    $0x16,%eax
   0x00007ffff7eb032d <+77>:	retq   
   0x00007ffff7eb032e <+78>:	xchg   %ax,%ax
   0x00007ffff7eb0330 <+80>:	mov    %rdx,0x10(%rsp)
   0x00007ffff7eb0335 <+85>:	mov    %esi,0xc(%rsp)
   0x00007ffff7eb0339 <+89>:	mov    %edi,(%rsp)
   0x00007ffff7eb033c <+92>:	mov    %rcx,0x18(%rsp)
   0x00007ffff7eb0341 <+97>:	callq  0x7ffff7e67760 <__libc_enable_asynccancel>
   0x00007ffff7eb0346 <+102>:	mov    0x18(%rsp),%r10
   0x00007ffff7eb034b <+107>:	mov    0x10(%rsp),%rdx
   0x00007ffff7eb0350 <+112>:	mov    %eax,%r8d
   0x00007ffff7eb0353 <+115>:	mov    0xc(%rsp),%esi
   0x00007ffff7eb0357 <+119>:	mov    (%rsp),%edi
   0x00007ffff7eb035a <+122>:	mov    $0xe6,%eax
   0x00007ffff7eb035f <+127>:	syscall 
   0x00007ffff7eb0361 <+129>:	mov    %r8d,%edi
   0x00007ffff7eb0364 <+132>:	mov    %rax,(%rsp)
   0x00007ffff7eb0368 <+136>:	callq  0x7ffff7e677c0 <__libc_disable_asynccancel>
   0x00007ffff7eb036d <+141>:	mov    (%rsp),%rax
   0x00007ffff7eb0371 <+145>:	jmp    0x7ffff7eb030e <__GI___clock_nanosleep+46>
End of assembler dump.












End of assembler dump.
(gdb) l
30	__clock_nanosleep_time64 (clockid_t clock_id, int flags, const struct __timespec64 *req,
31	                          struct __timespec64 *rem)
32	{
33	  int r;
34	
35	  if (clock_id == CLOCK_THREAD_CPUTIME_ID)
36	    return EINVAL;
37	  if (clock_id == CLOCK_PROCESS_CPUTIME_ID)
38	    clock_id = MAKE_PROCESS_CPUCLOCK (0, CPUCLOCK_SCHED);
39	
(gdb) l
40	  /* If the call is interrupted by a signal handler or encounters an error,
41	     it returns a positive value similar to errno.  */
42	  INTERNAL_SYSCALL_DECL (err);
43	
44	#ifdef __ASSUME_TIME64_SYSCALLS
45	# ifndef __NR_clock_nanosleep_time64
46	#  define __NR_clock_nanosleep_time64 __NR_clock_nanosleep
47	# endif
48	  r = INTERNAL_SYSCALL_CANCEL (clock_nanosleep_time64, err, clock_id,
49	                               flags, req, rem);
(gdb) l
50	#else
51	# ifdef __NR_clock_nanosleep_time64
52	  r = INTERNAL_SYSCALL_CANCEL (clock_nanosleep_time64, err, clock_id,
53	                               flags, req, rem);
54	
55	  if (! INTERNAL_SYSCALL_ERROR_P (r, err))
56	    return 0;
57	  if (INTERNAL_SYSCALL_ERRNO (r, err) != ENOSYS)
58	    return INTERNAL_SYSCALL_ERRNO (r, err);
59	# endif /* __NR_clock_nanosleep_time64 */
(gdb) l
60	
61	  if (! in_time_t_range (req->tv_sec))
62	    {
63	      __set_errno (EOVERFLOW);
64	      return -1;
65	    }
66	
67	  struct timespec tr32;
68	  struct timespec ts32 = valid_timespec64_to_timespec (*req);
69	  r = INTERNAL_SYSCALL_CANCEL (clock_nanosleep, err, clock_id, flags,
(gdb) 
70	                               &ts32, &tr32);
71	  if (INTERNAL_SYSCALL_ERROR_P (r, err))
72	    {
73	      if (INTERNAL_SYSCALL_ERRNO (r, err) == EINTR && rem != NULL
74		  && (flags & TIMER_ABSTIME) == 0)
75		*rem = valid_timespec_to_timespec64 (tr32);
76	    }
77	#endif /* __ASSUME_TIME64_SYSCALLS */
78	
79	  return (INTERNAL_SYSCALL_ERROR_P (r, err)
(gdb) 
80		  ? INTERNAL_SYSCALL_ERRNO (r, err) : 0);
81	}
82	
83	#if __TIMESIZE != 64
84	int
85	__clock_nanosleep (clockid_t clock_id, int flags, const struct timespec *req,
86	                   struct timespec *rem)
87	{
88	  int r;
89	  struct __timespec64 treq64, trem64;
(gdb) 
90	
91	  treq64 = valid_timespec_to_timespec64 (*req);
92	  r = __clock_nanosleep_time64 (clock_id, flags, &treq64, &trem64);
93	
94	  if (r == EINTR && rem != NULL && (flags & TIMER_ABSTIME) == 0)
95	    *rem = valid_timespec64_to_timespec (trem64);
96	
97	  return r;
98	}
99	#endif
(gdb) 
100	libc_hidden_def (__clock_nanosleep)
101	versioned_symbol (libc, __clock_nanosleep, clock_nanosleep, GLIBC_2_17);
102	/* clock_nanosleep moved to libc in version 2.17;
103	   old binaries may expect the symbol version it had in librt.  */
104	#if SHLIB_COMPAT (libc, GLIBC_2_2, GLIBC_2_17)
105	strong_alias (__clock_nanosleep, __clock_nanosleep_2);
106	compat_symbol (libc, __clock_nanosleep_2, clock_nanosleep, GLIBC_2_2);
107	#endif
(gdb) 
Line number 108 out of range; ../sysdeps/u






(gdb) disas
Dump of assembler code for function __GI___clock_nanosleep:
   0x00007ffff7eb02e0 <+0>:	endbr64 
   0x00007ffff7eb02e4 <+4>:	cmp    $0x3,%edi
   0x00007ffff7eb02e7 <+7>:	je     0x7ffff7eb0328 <__GI___clock_nanosleep+72>
=> 0x00007ffff7eb02e9 <+9>:	sub    $0x28,%rsp
   0x00007ffff7eb02ed <+13>:	mov    $0xfffffffa,%eax
   0x00007ffff7eb02f2 <+18>:	cmp    $0x2,%edi
   0x00007ffff7eb02f5 <+21>:	mov    %rcx,%r10
   0x00007ffff7eb02f8 <+24>:	cmove  %eax,%edi
   0x00007ffff7eb02fb <+27>:	mov    %fs:0x18,%eax
   0x00007ffff7eb0303 <+35>:	test   %eax,%eax


(gdb) disas
Dump of assembler code for function __GI___clock_nanosleep:
   0x00007ffff7eb02e0 <+0>:	endbr64 

   0x00007ffff7eb02e4 <+4>:	cmp    $0x3,%edi
   0x00007ffff7eb02e7 <+7>:	je     0x7ffff7eb0328 <__GI___clock_nanosleep+72>

=> 0x00007ffff7eb02e9 <+9>:	sub    $0x28,%rsp
   0x00007ffff7eb02ed <+13>:	mov    $0xfffffffa,%eax
   0x00007ffff7eb02f2 <+18>:	cmp    $0x2,%edi
   0x00007ffff7eb02f5 <+21>:	mov    %rcx,%r10
   0x00007ffff7eb02f8 <+24>:	cmove  %eax,%edi
   0x00007ffff7eb02fb <+27>:	mov    %fs:0x18,%eax
   0x00007ffff7eb0303 <+35>:	test   %eax,%eax


gdb /usr/lib/x86_64-linux-gnu/libc-2.31.so -ex 'disas 0x00007ffff7eb02e0'
だめ
objdump --disassemble=clock_nanosleep /usr/lib/x86_64-linux-gnu/libc-2.31.so

sudo cp /usr/lib/x86_64-linux-gnu/libc-2.31.so  /usr/lib/x86_64-linux-gnu/libc-2.31.so.orig


(gdb) bt
#0  __GI___clock_nanosleep (clock_id=clock_id@entry=0, flags=flags@entry=0, req=0x0, rem=0x0)
    at ../sysdeps/unix/sysv/linux/clock_nanosleep.c:35
#1  0x00007ffff7eb5eb7 in __GI___nanosleep (requested_time=<optimized out>, remaining=<optimized out>) at nanosleep.c:27
#2  0x000055555555516b in main (argc=1, argv=0x7fffffffe498) at a.c:55



wsh@wsh9bubu ~> lsof -p 7343
COMMAND  PID USER   FD   TYPE DEVICE SIZE/OFF    NODE NAME
a.out   7343  wsh  mem    REG    8,2  2029224 5904316 /usr/lib/x86_64-linux-gnu/libc-2.31.so


wsh@wsh9bubu ~/src> objdump --disassemble=clock_nanosleep /usr/lib/x86_64-linux-gnu/libc-2.31.so

あった

00000000000e02e0 <clock_nanosleep@@GLIBC_2.17>:
   e02e0:	f3 0f 1e fa          	endbr64 
   e02e4:	83 ff 03             	cmp    $0x3,%edi
   e02e7:	74 3f                	je     e0328 <clock_nanosleep@@GLIBC_2.17+0x48>
   e02e9:	48 83 ec 28          	sub    $0x28,%rsp
   e02ed:	b8 fa ff ff ff       	mov    $0xfffffffa,%eax
   e02f2:	83 ff 02             	cmp    $0x2,%edi
   e02f5:	49 89 ca             	mov    %rcx,%r10
   e02f8:	0f 44 f8             	cmove  %eax,%edi
   e02fb:	64 8b 04 25 18 00 00 	mov    %fs:0x18,%eax


sudo cp -nv /usr/lib/x86_64-linux-gnu/libc-2.31.so /usr/lib/x86_64-linux-gnu/libc-2.31.so.work

wsh@wsh9bubu ~/src> objdump --disassemble=clock_nanosleep /usr/lib/x86_64-linux-gnu/libc-2.31.so


xxd -seek 0xe02e0 /usr/lib/x86_64-linux-gnu/libc-2.31.so.work | head

0xe02e0 = 918240
dd skip=918240 bs=1 count=4 if=/usr/lib/x86_64-linux-gnu/libc-2.31.so.work | xxd
dd skip=918244 bs=1 count=5 if=/usr/lib/x86_64-linux-gnu/libc-2.31.so.work | xxd

echo -en '\xbf\x01\x00\x00\x00' | xxd #  mov    $0x1,%edi
echo -en '\xbf\x07\x00\x00\x00' | xxd #  mov    $0x7,%edi


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment