Bug 61539

Summary: The race condition in linuxthreads
Product: [Retired] Red Hat Linux Reporter: hjl
Component: glibcAssignee: Jakub Jelinek <jakub>
Status: CLOSED WONTFIX QA Contact: Brian Brock <bbrock>
Severity: medium Docs Contact:
Priority: medium    
Version: 7.3CC: fweimer
Target Milestone: ---   
Target Release: ---   
Hardware: i386   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2003-04-23 22:40:31 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 61901, 67218, 79579    
Attachments:
Description Flags
A simple patch
none
A patch with spinlock none

Description hjl 2002-03-21 07:28:06 UTC
There is a race condition between __pthread_manager_adjust_prio
called from pthread_setschedparam and pthread_start_thread on
manager_thread->p_priority. When a thread is calling
pthread_setschedparam, the new thread may inherit SCHED_FIFO from
the manager thread. That is

Thread A calls pthread_setschedparam
  calls __pthread_manager_adjust_prio
    calls __sched_setscheduler (SCHED_FIFO) on the manager thread.
The main thread calls pthread_create
  The manager threads calls pthread_start_thread. It does

        if (manager_thread->p_priority > 0)
          __sched_setscheduler (SCHED_OTHER)

Since manager_thread->p_priority may not be changed by
__pthread_manager_adjust_prio yet, the new thread may inherit
SCHED_FIFO. Here is a patch. the worst case is pthread_start_thread
may call __sched_setscheduler (SCHED_OTHER) before 
__sched_setscheduler (SCHED_FIFO) is called on the manager thread.

Comment 1 hjl 2002-03-21 07:29:50 UTC
Created attachment 49328 [details]
A simple patch

Comment 2 hjl 2002-03-21 07:32:02 UTC
I don't know if a spinlock for manager_thread->p_priority
is a better fix. Also we need to check if there are any other
race conditions like that for other manager_thread fields.

Comment 3 hjl 2002-03-21 08:16:31 UTC
Created attachment 49329 [details]
A patch with spinlock

Comment 4 hjl 2002-03-21 08:17:22 UTC
I uploaded another patch with spinlock.

Comment 5 Ulrich Drepper 2003-04-23 22:40:31 UTC
I've explained a few times on the libc lists that the patches aren't adequate. 
And probably no userlevel solution can be adequate.  But this is all pointless
now.  LinuxThreads stays as it is, correct or not.  I'm closing the bug therefore.