Opened 4 years ago

Last modified 3 years ago

#11522 new bug

maxStkSize can overflow

Reported by: rwbarton Owned by:
Priority: normal Milestone:
Component: Runtime System Version: 7.8.4
Keywords: Cc: simonmar, MarcelineVQ
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s): Phab:D1895
Wiki Page:


The maxStkSize field of GC_FLAGS is a nat, or unsigned int. It's measured in words, but still 32G is not an unreasonable amount of memory by today's standards.

Maybe it's unlikely that anyone would want to set the stack size limit to more than 32G. But if you happen to have just over 40G of physical memory then the default stack size limit will overflow to a value just above zero and then Bad Things would happen.

If we want to actually enforce stack limits that are greater than 232 words, we would need to increase the size of the tot_stack_size field of a TSO also.

Simple test of overflow behavior: ghci +RTS -K32.0001G will exit with a stack overflow.

Change History (3)

comment:1 Changed 4 years ago by thomie

Cc: MarcelineVQ added

MarcelineVQ: maybe you can have a look at this one as well, while you're working on #11502. Don't forget a test.

comment:2 Changed 4 years ago by MarcelineVQ

Differential Rev(s): Phab:D1895
Owner: set to MarcelineVQ

The suggested overflow test of -K32.0001G can overflow enough to be above the minimally required stack size to run a small program. Decided to use -K4294967297W to overflow it to exactly 1 for testing.

According to the invariants in TSO.h:
tso->stack_size <= tso->max_stack_size
Which means I'll need to change StgStack.stack_size too but its implications reach farther than the other two, offsets and such, so please double-check if that's a good idea.

comment:3 Changed 3 years ago by MarcelineVQ

Owner: MarcelineVQ deleted
Note: See TracTickets for help on using tickets.