[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#803417: apt-get: Segfault upon low memory (ENOMEM not caught in MMap::MMap)



Package: apt
Version: 1.0.9.8.1
Severity: normal

Dear Maintainer,

indeed the Seagate dockstar with 128 Mbyte RAM just meets the
"Minimum Hardware Requirements" as in the installation guide[1].
However it's getting quite tight and causes segmentation faults
repeatedly here, e.g. when trying to install another package.

Some more analysis revealed ENOMEM is not properly caught in the MMap
class.

According to strace:

(...)
55629 open("/var/cache/apt/pkgcache.bin", O_RDONLY|O_LARGEFILE) = 5
    This is "FileFd CacheF(CacheFile,FileFd::ReadOnly);" in
    apt-pkg/pkgcachegen.cc:1182
55629 fcntl64(5, F_SETFD, FD_CLOEXEC)   = 0
55629 fstat64(5, {st_mode=S_IFREG|0644, st_size=31003485, ...}) = 0
55629 mmap2(NULL, 31003485, PROT_READ|PROT_WRITE, MAP_PRIVATE, 5, 0) = -1 ENOMEM (Cannot allocate memory)
    Note: ENOMEM is not caught!

55629 pipe([6, 7])                      = 0
    This is "pipe(external) != 0" in apt-pkg/aptconfiguration.cc:336
55629 clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0xb6f9d068) = 55631
(...)
55629 close(6)                          = 0
55629 munmap(0xb68d4000, 4096)          = 0
55629 wait4(55631,  <unfinished ...>
55631 +++ exited with 0 +++
55629 <... wait4 resumed> [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0, NULL) = 55631
55629 --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=55631, si_uid=0, si_status=0, si_utime=15, si_stime=423} ---
55629 --- SIGSEGV {si_signo=SIGSEGV, si_code=SEGV_MAPERR, si_addr=0xffffffff} ---
55629 +++ killed by SIGSEGV +++


As far as I can see, MMap::Map in apt-pkg/contrib/mmap.cc detects
errors but this does not get through to the MMap call in 
apt-pkg/pkgcachegen.cc:1183 and that code happily continues operation.

The following quick and dirty patch confirms my analysis. Using that,
apt-get exits "Out of memory" which doesn't help much but at least
avoids potentially harmful things.

--- a/apt-pkg/contrib/mmap.cc
+++ b/apt-pkg/contrib/mmap.cc
@@ -114,7 +114,10 @@ bool MMap::Map(FileFd &Fd)
         SyncToFd = new FileFd (dupped_fd);
         if (!SyncToFd->Seek(0L) || !SyncToFd->Read(Base, iSize))
            return false;
-      }
+      } else if (errno == ENOMEM) {
+        std::cerr << "Out of memory!\n";
+        exit(1);
+    }
       else
         return _error->Errno("mmap",_("Couldn't make mmap of %llu bytes"),
                              iSize);

Note I can work around the low memory problem by other means. So I'm
just asking to handle ENOMEM gracefully in the future.

Regards,

    Christoph

[1] https://www.debian.org/releases/stable/armel/ch03s04.html.en

-- Package-specific info:

-- (no /etc/apt/preferences present) --

-- (/etc/apt/sources.list present, but not submitted) --

-- System Information:
Debian Release: 8.2
  APT prefers stable-updates
  APT policy: (500, 'stable-updates'), (500, 'stable')
Architecture: armel (armv5tel)

Kernel: Linux 4.1.10
Locale: LANG=C, LC_CTYPE=C (charmap=ANSI_X3.4-1968)
Shell: /bin/sh linked to /bin/dash
Init: sysvinit (via /sbin/init)

Versions of packages apt depends on:
ii  debian-archive-keyring  2014.3
ii  gnupg                   1.4.18-7
ii  libapt-pkg4.12          1.0.9.8.1
ii  libc6                   2.19-18+deb8u1
ii  libgcc1                 1:4.9.2-10
ii  libstdc++6              4.9.2-10

apt recommends no packages.

Versions of packages apt suggests:
pn  apt-doc                      <none>
pn  aptitude | synaptic | wajig  <none>
ii  dpkg-dev                     1.17.25
pn  python-apt                   <none>

-- Configuration Files:
/etc/logrotate.d/apt changed [not included]

-- no debconf information

Attachment: signature.asc
Description: Digital signature


Reply to: