Skip to content

Commit

Permalink
fix segmentation fault caused by uninitialized mutex
Browse files Browse the repository at this point in the history
Segmentation fault was raised while trying to restore a process with
tty. Coredump file says this is caused by uninitialized tty_mutex:
        (gdb) where
        #0  0x00000000004d7270 in atomic_add_return (i=1, v=0x0) at
        include/common/asm/atomic.h:34
        #1  0x00000000004d7398 in mutex_lock (m=0x0) at
        include/common/lock.h:151
        #2  0x00000000004d840c in __pty_open_ptmx_index (index=3, flags=2,
        cb=0x4dce50 <open_pty>, arg=0x11, path=0x5562e0 "ptmx") at
        criu/tty.c:603
        #3  0x00000000004dced8 in pty_create_ptmx_index (dfd=17, index=3,
        flags=2) at criu/tty.c:2384

since init_tty_mutex() is reentrantable, just calling it before
mutex_lock()

Signed-off-by: Deng Guangxing <dengguangxing@huawei.com>
Reviewed-by: Cyrill Gorcunov <gorcunov@gmail.com>
Signed-off-by: Andrei Vagin <avagin@gmail.com>
  • Loading branch information
Dengguangxing authored and avagin committed Sep 7, 2019
1 parent 8c65b8a commit d1b1253
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions criu/tty.c
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,9 @@ static int __pty_open_ptmx_index(int index, int flags,

memset(fds, 0xff, sizeof(fds));

if (init_tty_mutex())
return -1;

mutex_lock(tty_mutex);

for (i = 0; i < ARRAY_SIZE(fds); i++) {
Expand Down

0 comments on commit d1b1253

Please sign in to comment.