From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 6713C388A001; Thu, 2 Apr 2020 12:08:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6713C388A001 From: "martin.lubich at gmx dot at" To: glibc-bugs@sourceware.org Subject: [Bug nptl/25765] New: Incorrect futex syscall in __pthread_disable_asynccancel for linux x86_64 leads to livelock Date: Thu, 02 Apr 2020 12:08:54 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: glibc X-Bugzilla-Component: nptl X-Bugzilla-Version: unspecified X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: martin.lubich at gmx dot at X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at sourceware dot org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter cc target_milestone attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://sourceware.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: glibc-bugs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Glibc-bugs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 02 Apr 2020 12:08:54 -0000 https://sourceware.org/bugzilla/show_bug.cgi?id=3D25765 Bug ID: 25765 Summary: Incorrect futex syscall in __pthread_disable_asynccancel for linux x86_64 leads to livelock Product: glibc Version: unspecified Status: UNCONFIRMED Severity: normal Priority: P2 Component: nptl Assignee: unassigned at sourceware dot org Reporter: martin.lubich at gmx dot at CC: drepper.fsp at gmail dot com Target Milestone: --- Created attachment 12422 --> https://sourceware.org/bugzilla/attachment.cgi?id=3D12422&action=3Ded= it Example code to reproduce and trigger the bug There is a bug in the x86_64 specific implementation of __pthread_disable_asynccancel. When detecting an ongoing thread cancellation (CANCELLING_BITMASK) the code tries to block on a futex based on the cancellation member of the thread structure. The generic c-code in nptl/cancellation.c does this in a correct way. The specific implemention in sysdeps/unix/sysv/linux/x86_64/cancellation.S = has an error in setting up the futex syscall. The 3rd parameter ( the value aga= inst which the kernel futex code checks ) is not set (edx register) i.e. edx is = not in a defined state and thus typically the futex call will return immediately with EAGAIN. This leads to an endless loop. If the looping thread has a higher RT priority than the cancelling thread, = the loop will go on forever, consuming all CPU cycles there are. In case of RT threads, this will also cause complete system freezes. If have attached a simple test which will show the problem after some time.= =20 This is a patch which fixes the problem. The patch is based on a glibc 2.27, but the bug is still present in the act= ual version 2.31. as well as the actual developmemt version. --------------- snip ---------------------------- diff -Naur glibc-2.27/sysdeps/unix/sysv/linux/x86_64/cancellation.S glibc-2.27_patched/sysdeps/unix/sysv/linux/x86_64/cancellation.S --- glibc-2.27/sysdeps/unix/sysv/linux/x86_64/cancellation.S 2018-02-01 17:17:18.000000000 +0100 +++ glibc-2.27_patched/sysdeps/unix/sysv/linux/x86_64/cancellation.S=20=20= =20 2020-04-02 12:08:02.712851151 +0200 @@ -95,8 +95,8 @@ cmpxchgl %r11d, %fs:CANCELHANDLING jnz 2b - movl %r11d, %eax -3: andl $(TCB_CANCELING_BITMASK|TCB_CANCELED_BITMASK), %eax +3: movl %r11d, %eax + andl $(TCB_CANCELING_BITMASK|TCB_CANCELED_BITMASK), %eax cmpl $TCB_CANCELING_BITMASK, %eax je 4f 1: ret @@ -104,12 +104,13 @@ /* Performance doesn't matter in this loop. We will delay until the thread is canceled. And we will unlikely enter the loop twice. */ -4: mov %fs:0, %RDI_LP +4: movl %r11d, %edx + mov %fs:0, %RDI_LP movl $__NR_futex, %eax xorq %r10, %r10 addq $CANCELHANDLING, %rdi LOAD_PRIVATE_FUTEX_WAIT (%esi) syscall - movl %fs:CANCELHANDLING, %eax + movl %fs:CANCELHANDLING, %edx jmp 3b END(__pthread_disable_asynccancel) ------------------- snip --------------------------- This is a linux x86_64 specific bug. --=20 You are receiving this mail because: You are on the CC list for the bug.=