Package: linux-libc-dev
Version: 6.12.107-1
Severity: normal
Dear Maintainer,

  The problem is that sbrk(2) checks each new request against the machine's total RAM + swap space.  It should check each new request against total RAM + swap space - memory that has already been allocated to the current process.

Steps to reproduce:
1. Compile & run the program below on a machine with 32 GiB memory & 24 GiB swap

--- eatmem_bad.c
#include <stdio.h>
#include <unistd.h>

intptr_t bigMem = (intptr_t) 128LL*1024*1024*1024;

int main(int argc,char *argv[]) {
    intptr_t i;
    unsigned long long mem;

    if (argc != 1)
        { (void) fprintf(stderr,"Usage: %s\n", argv[0]); return 2; }

    mem=0;
    for (i = bigMem; i >= 16; i /= 2)
        if (sbrk(i) != (void *) -1)
            mem |= i;

    (void) printf("Memory=%llu MiB\n",mem / (1024*1024));

    return 0;
    }
---

Expected (and correct) result:
Memory=56718 MiB

Actual result:
Memory=65535 MiB

-- System Information:
Debian Release: 13.6
  APT prefers stable-updates
  APT policy: (500, 'stable-updates'), (500, 'stable-security'), (500, 'stable')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 6.12.107+deb13-amd64 (SMP w/14 CPU threads; PREEMPT)
Kernel taint flags: TAINT_OOT_MODULE, TAINT_UNSIGNED_MODULE
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8), LANGUAGE not set
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled

-- no debconf information

Reply via email to