Bug 28194 - stack size not consistently checked by _pthread_attr_setstacksize
stack size not consistently checked by _pthread_attr_setstacksize
Status: CLOSED RAWHIDE
Product: Red Hat Linux
Classification: Retired
Component: glibc (Show other bugs)
7.1
i386 Linux
medium Severity low
: ---
: ---
Assigned To: Jakub Jelinek
Aaron Brown
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2001-02-17 17:33 EST by dtc-rhbug
Modified: 2016-11-24 09:54 EST (History)
1 user (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2001-02-17 17:33:20 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description dtc-rhbug 2001-02-17 17:33:16 EST
From Bugzilla Helper:
User-Agent: Mozilla/4.75 [en] (X11; U; Linux 2.4.2-pre3 i686)


The logic to check the maximum stack size in __pthread_attr_setstacksize
is not consistent with that in __pthread_initialize_manager, and does
not limit the maximum stack size.   Calls to pthread_attr_setstacksize
may accept overly larger stack sizes without returning an error code
before the manager is already started.


Reproducible: Always
Steps to Reproduce:
1.  Call pthread_attr_setstacksize with a stack size over 8MB before the
manage is initialized.
2.
3.
	

Actual Results:  Function returns 0, success.

Expected Results:  Expected EINVAL.


Possible patch:

*** attr.c~	Tue Jan  9 04:58:34 2001
--- attr.c	Sun Feb 18 07:40:33 2001
***************
*** 189,208 ****
  int __pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize)
  {
  #ifdef FLOATING_STACKS
!   /* We have to check against the maximum allowed stack size.  This is no
!      problem if the manager is already started and we determined it.  If
!      this hasn't happened, we have to find the limit outself.  */
    if (__pthread_max_stacksize == 0)
!     {
!       struct rlimit limit;
! 
!       getrlimit(RLIMIT_STACK, &limit);
! # ifdef NEED_SEPARATE_REGISTER_STACK
!       __pthread_max_stacksize = limit.rlim_max / 2;
! # else
!       __pthread_max_stacksize = limit.rlim_max;
! # endif
!     }
  
    if (stacksize > __pthread_max_stacksize)
      return EINVAL;
--- 189,198 ----
  int __pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize)
  {
  #ifdef FLOATING_STACKS
!   /* We have to check against the maximum allowed stack size, so ensure
!      it has been initialized. */
    if (__pthread_max_stacksize == 0)
!     __pthread_init_max_stacksize();
  
    if (stacksize > __pthread_max_stacksize)
      return EINVAL;
*** internals.h~	Tue Jan  9 05:42:30 2001
--- internals.h	Sun Feb 18 07:44:30 2001
***************
*** 429,434 ****
--- 429,435 ----
  
  extern void __pthread_destroy_specifics (void);
  extern void __pthread_perform_cleanup (void);
+ extern size_t __pthread_init_max_stacksize(void);
  extern int __pthread_initialize_manager (void);
  extern void __pthread_message (char * fmt, ...);
  extern int __pthread_manager (void *reqfd);
*** pthread.c~	Sun Jan 14 19:46:28 2001
--- pthread.c	Sun Feb 18 07:42:19 2001
***************
*** 454,473 ****
    pthread_initialize();
  }
  
! int __pthread_initialize_manager(void)
  {
-   int manager_pipe[2];
-   int pid;
-   struct pthread_request request;
    struct rlimit limit;
    int max_stack;
  
- #ifndef HAVE_Z_NODELETE
-   if (__builtin_expect (&__dso_handle != NULL, 1))
-     __cxa_atexit ((void (*) (void *)) pthread_atexit_retcode, NULL,
- 		  __dso_handle);
- #endif
- 
    getrlimit(RLIMIT_STACK, &limit);
  #ifdef FLOATING_STACKS
    if (limit.rlim_cur == RLIM_INFINITY)
--- 454,466 ----
    pthread_initialize();
  }
  
! 
! #ifdef FLOATING_STACKS
! size_t __pthread_init_max_stacksize(void)
  {
    struct rlimit limit;
    int max_stack;
  
    getrlimit(RLIMIT_STACK, &limit);
  #ifdef FLOATING_STACKS
    if (limit.rlim_cur == RLIM_INFINITY)
***************
*** 494,499 ****
--- 487,514 ----
      setrlimit(RLIMIT_STACK, &limit);
    }
  #endif
+ 
+   return __pthread_max_stacksize;
+ }
+ #endif
+ 
+ 
+ int __pthread_initialize_manager(void)
+ {
+   int manager_pipe[2];
+   int pid;
+   struct pthread_request request;
+ 
+ #ifndef HAVE_Z_NODELETE
+   if (__builtin_expect (&__dso_handle != NULL, 1))
+     __cxa_atexit ((void (*) (void *)) pthread_atexit_retcode, NULL,
+ 		  __dso_handle);
+ #endif
+ 
+ #ifdef FLOATING_STACKS
+   __pthread_init_max_stacksize();
+ #endif
+ 
    /* If basic initialization not done yet (e.g. we're called from a
       constructor run before our constructor), do it now */
    if (__pthread_initial_thread_bos == NULL) pthread_initialize();
Comment 1 Jakub Jelinek 2001-03-21 07:58:09 EST
Should be fixed in glibc-2.2.2-7.

Note You need to log in before you can comment on or make changes to this bug.