mm/secretmem: fix panic when growing a memfd_secret
Linux
Affected versions
| Product | Affected | Fixed in |
|---|---|---|
| Linux Linux |
| No fix yet |
| Linux Linux |
|
|
Linux
| Product | Affected | Fixed in |
|---|---|---|
| Linux Linux |
| No fix yet |
| Linux Linux |
|
|
5.15.355.17.45.18In the Linux kernel, the following vulnerability has been resolved:
mm/secretmem: fix panic when growing a memfd_secret
When one tries to grow an existing memfd_secret with ftruncate, one gets a panic [1]. For example, doing the following reliably induces the panic:
fd = memfd_secret();
ftruncate(fd, 10); ptr = mmap(NULL, 10, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); strcpy(ptr, "123456789");
munmap(ptr, 10); ftruncate(fd, 20);
The basic reason for this is, when we grow with ftruncate, we call down into simple_setattr, and then truncate_inode_pages_range, and eventually we try to zero part of the memory. The normal truncation code does this via the direct map (i.e., it calls page_address() and hands that to memset()).
For memfd_secret though, we specifically don't map our pages via the direct map (i.e. we call set_direct_map_invalid_noflush() on every fault). So the address returned by page_address() isn't useful, and when we try to memset() with it we panic.
From the CVE record · Linux
The Linux kernel's memfd_secret handling can panic when an existing secret-memory file is grown with ftruncate. A local process can trigger the panic after mapping and writing to the file; the input does not specify additional authorization or user-interaction requirements.
Engineers running Linux kernels with memfd_secret should check their kernel version; affected versions are not specified in the input.