Bug 58006 - "limit datasize" does not work
Summary: "limit datasize" does not work
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: glibc   
(Show other bugs)
Version: 7.2
Hardware: i386
OS: Linux
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact: Brian Brock
Depends On:
TreeView+ depends on / blocked
Reported: 2002-01-05 00:34 UTC by Jamie Zawinski
Modified: 2016-11-24 15:12 UTC (History)
1 user (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2004-08-26 04:19:17 UTC
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)
malloc-bomb.c source: program that verbosely allocates memory (1.23 KB, text/plain)
2002-01-05 00:35 UTC, Jamie Zawinski
no flags Details
limiter.pl -- program to demonstrate that setrlimit() works correctly (2.04 KB, text/plain)
2002-01-05 00:36 UTC, Jamie Zawinski
no flags Details

Description Jamie Zawinski 2002-01-05 00:34:05 UTC
From Bugzilla Helper:
User-Agent: Mozilla/4.78 [en] (X11; U; Linux 2.4.9-13smp i686; Nav)

Description of problem:
"limit datasize 10m" should limit the sbrk+stack size to 10M in tcsh;
that try to brk beyond that should fail (causing brk/malloc to return 0.)

This does not work in tcsh 6.10; tested on Red Hat 6.2, 7.0, and 7.2.

Version-Release number of selected component (if applicable):

How reproducible:

Steps to Reproduce:
1. tcsh
2. limit datasize 5m
3. ./malloc-bomb

Actual Results:  Program continues allocating memory forever.

Expected Results:  Program should have died after allocating around 5M.

Additional info:

Attached is the source to the malloc-bomb program I used to test this.
Following that is the source to limiter.pl, a perl script that *does*
work ("./limiter.pl 5M malloc-bomb").  That limiter.pl works demonstrates
that the problem is with tcsh and not with the setrlimit() syscall.

FWIW, bash 1.14 also had this problem, but it appears to have been
corrected by bash 2.04.

Comment 1 Jamie Zawinski 2002-01-05 00:35:23 UTC
Created attachment 41831 [details]
malloc-bomb.c source: program that verbosely allocates memory

Comment 2 Jamie Zawinski 2002-01-05 00:36:33 UTC
Created attachment 41832 [details]
limiter.pl -- program to demonstrate that setrlimit() works correctly

Comment 3 Miloslav Trmač 2004-08-18 15:41:33 UTC
The difference is that limiter.pl (and (ulimit -v) referenced
in malloc-bomb.c) use RLIMIT_AS, but (limit datasize) uses
RLIMIT_DATA. If you use (limit vmemoryuse) under tcsh
(to also use RLIMIT_AS), bash and tcsh behave exactly the same.

OTOH SUSv3 specifies:
              This is the maximum size of a processâ data segment,  in
              If this limit is exceeded, the malloc() function shall
fail with
              errno set to [ENOMEM].

In fact, RLIMIT_DATA limits memory allocated through sbrk (),
but malloc () in glibc can also use mmap (). This seems like a
violation of the standard by glibc.

Comment 4 Ulrich Drepper 2004-08-26 04:19:17 UTC
That POSIX text is ancient.  If one insists to have this definition of
RLIMIT_DATA, simply start the application with


in the environment.  That is perfectly fine with POSIX.  POSIX
specifies only that there must be one environment in which all the
rules apply.  The default environment does not have this stupid
limitation which nobody wants.

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