| 0/0 |
2026/06/01 10:04 |
flow |
assessment-security |
52m
Results: map[DenialOfService:false Explanation:Based on the analysis of the bug report and the kernel source code, here is the
assessment of the issue:
**Root Cause and Mechanism:**
The bug is a KMSAN report for the use of an uninitialized value during
filesystem encryption (`fscrypt`). It occurs when an unprivileged user writes to
an encrypted file at an offset that leaves a hole at the beginning of a page
cache folio (e.g., writing to block 1 while block 0 remains a hole).
1. When the write occurs, `ext4_write_begin` allocates a new folio for the page
cache. This folio is allocated without the `__GFP_ZERO` flag, meaning it
contains uninitialized memory (leftover data from previous uses).
2. `ext4_block_write_begin` processes the blocks within the folio. It only
initializes (reads from disk or zeroes) the blocks that intersect with the write
range. The blocks corresponding to the hole (e.g., block 0) are left unmapped
and uninitialized.
3. Later, during the writeback phase, `ext4_bio_write_folio` is called to write
the dirty folio to disk. It determines the length of the data to write (usually
up to `i_size`).
4. It then calls `fscrypt_encrypt_pagecache_blocks` to encrypt the data into a
newly allocated bounce page. However, `fscrypt_encrypt_pagecache_blocks`
encrypts the data starting from offset 0 up to the rounded-up length, regardless
of whether the underlying blocks are mapped or dirty.
5. This causes the kernel to read and encrypt the uninitialized memory in the
unmapped hole blocks, which triggers the KMSAN warning.
**Security Impact:**
Despite reading uninitialized memory, this bug has **no security impact** and is
**not exploitable**:
- After the encryption completes, `ext4_bio_write_folio` iterates over the
buffer heads of the folio to submit them to the block layer.
- It strictly checks each buffer head and only submits those that were marked
for asynchronous write (i.e., the blocks that were actually mapped and dirty).
- The ciphertext corresponding to the uninitialized hole blocks is placed in the
bounce page but is **never submitted to the block layer**.
- Consequently, the uninitialized memory (and its ciphertext) is immediately
discarded, never written to disk, and never exposed to userspace. It is a benign
read of uninitialized memory that only trips debugging tools like KMSAN.
- In production builds (where KMSAN is disabled), this will silently encrypt
garbage and discard it without causing any memory corruption, crashes, or
information leaks.
**Trigger:**
The bug can be triggered by any unprivileged user who has the ability to create
and write to an encrypted directory/file (which is standard on systems utilizing
`fscrypt`, like Android or typical Linux desktops). No special capabilities or
namespaces are required. Exploitable:false FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:false RemoteTrigger:false Unprivileged:true UserNamespace:true VMGuestTrigger:false VMHostTrigger:false]
|
| 1/1 |
2026/06/01 10:04 |
action |
syz-repro-to-c-repro |
0m
Results: map[SimplifiedCRepro:// autogenerated by syzkaller (https://github.com/google/syzkaller)
#define _GNU_SOURCE
#include <endian.h>
#include <errno.h>
#include <fcntl.h>
#include <setjmp.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/mount.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <unistd.h>
#include <linux/loop.h>
#ifndef __NR_memfd_create
#define __NR_memfd_create 319
#endif
#ifndef __NR_pwritev2
#define __NR_pwritev2 328
#endif
static unsigned long long procid;
//% This code is derived from puff.{c,h}, found in the zlib development. The
//% original files come with the following copyright notice:
//% Copyright (C) 2002-2013 Mark Adler, all rights reserved
//% version 2.3, 21 Jan 2013
//% This software is provided 'as-is', without any express or implied
//% warranty. In no event will the author be held liable for any damages
//% arising from the use of this software.
//% Permission is granted to anyone to use this software for any purpose,
//% including commercial applications, and to alter it and redistribute it
//% freely, subject to the following restrictions:
//% 1. The origin of this software must not be misrepresented; you must not
//% claim that you wrote the original software. If you use this software
//% in a product, an acknowledgment in the product documentation would be
//% appreciated but is not required.
//% 2. Altered source versions must be plainly marked as such, and must not be
//% misrepresented as being the original software.
//% 3. This notice may not be removed or altered from any source distribution.
//% Mark Adler madler@alumni.caltech.edu
//% BEGIN CODE DERIVED FROM puff.{c,h}
#define MAXBITS 15
#define MAXLCODES 286
#define MAXDCODES 30
#define MAXCODES (MAXLCODES + MAXDCODES)
#define FIXLCODES 288
struct puff_state {
unsigned char* out;
unsigned long outlen;
unsigned long outcnt;
const unsigned char* in;
unsigned long inlen;
unsigned long incnt;
int bitbuf;
int bitcnt;
jmp_buf env;
};
static int puff_bits(struct puff_state* s, int need)
{
long val = s->bitbuf;
while (s->bitcnt < need) {
if (s->incnt == s->inlen)
longjmp(s->env, 1);
val |= (long)(s->in[s->incnt++]) << s->bitcnt;
s->bitcnt += 8;
}
s->bitbuf = (int)(val >> need);
s->bitcnt -= need;
return (int)(val & ((1L << need) - 1));
}
static int puff_stored(struct puff_state* s)
{
s->bitbuf = 0;
s->bitcnt = 0;
if (s->incnt + 4 > s->inlen)
return 2;
unsigned len = s->in[s->incnt++];
len |= s->in[s->incnt++] << 8;
if (s->in[s->incnt++] != (~len & 0xff) ||
s->in[s->incnt++] != ((~len >> 8) & 0xff))
return -2;
if (s->incnt + len > s->inlen)
return 2;
if (s->outcnt + len > s->outlen)
return 1;
for (; len--; s->outcnt++, s->incnt++) {
if (s->in[s->incnt])
s->out[s->outcnt] = s->in[s->incnt];
}
return 0;
}
struct puff_huffman {
short* count;
short* symbol;
};
static int puff_decode(struct puff_state* s, const struct puff_huffman* h)
{
int first = 0;
int index = 0;
int bitbuf = s->bitbuf;
int left = s->bitcnt;
int code = first = index = 0;
int len = 1;
short* next = h->count + 1;
while (1) {
while (left--) {
code |= bitbuf & 1;
bitbuf >>= 1;
int count = *next++;
if (code - count < first) {
s->bitbuf = bitbuf;
s->bitcnt = (s->bitcnt - len) & 7;
return h->symbol[index + (code - first)];
}
index += count;
first += count;
first <<= 1;
code <<= 1;
len++;
}
left = (MAXBITS + 1) - len;
if (left == 0)
break;
if (s->incnt == s->inlen)
longjmp(s->env, 1);
bitbuf = s->in[s->incnt++];
if (left > 8)
left = 8;
}
return -10;
}
static int puff_construct(struct puff_huffman* h, const short* length, int n)
{
int len;
for (len = 0; len <= MAXBITS; len++)
h->count[len] = 0;
int symbol;
for (symbol = 0; symbol < n; symbol++)
(h->count[length[symbol]])++;
if (h->count[0] == n)
return 0;
int left = 1;
for (len = 1; len <= MAXBITS; len++) {
left <<= 1;
left -= h->count[len];
if (left < 0)
return left;
}
short offs[MAXBITS + 1];
offs[1] = 0;
for (len = 1; len < MAXBITS; len++)
offs[len + 1] = offs[len] + h->count[len];
for (symbol = 0; symbol < n; symbol++)
if (length[symbol] != 0)
h->symbol[offs[length[symbol]]++] = symbol;
return left;
}
static int puff_codes(struct puff_state* s,
const struct puff_huffman* lencode,
const struct puff_huffman* distcode)
{
static const short lens[29] = {
3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258};
static const short lext[29] = {
0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0};
static const short dists[30] = {
1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
8193, 12289, 16385, 24577};
static const short dext[30] = {
0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,
7, 7, 8, 8, 9, 9, 10, 10, 11, 11,
12, 12, 13, 13};
int symbol;
do {
symbol = puff_decode(s, lencode);
if (symbol < 0)
return symbol;
if (symbol < 256) {
if (s->outcnt == s->outlen)
return 1;
if (symbol)
s->out[s->outcnt] = symbol;
s->outcnt++;
} else if (symbol > 256) {
symbol -= 257;
if (symbol >= 29)
return -10;
int len = lens[symbol] + puff_bits(s, lext[symbol]);
symbol = puff_decode(s, distcode);
if (symbol < 0)
return symbol;
unsigned dist = dists[symbol] + puff_bits(s, dext[symbol]);
if (dist > s->outcnt)
return -11;
if (s->outcnt + len > s->outlen)
return 1;
while (len--) {
if (dist <= s->outcnt && s->out[s->outcnt - dist])
s->out[s->outcnt] = s->out[s->outcnt - dist];
s->outcnt++;
}
}
} while (symbol != 256);
return 0;
}
static int puff_fixed(struct puff_state* s)
{
static int virgin = 1;
static short lencnt[MAXBITS + 1], lensym[FIXLCODES];
static short distcnt[MAXBITS + 1], distsym[MAXDCODES];
static struct puff_huffman lencode, distcode;
if (virgin) {
lencode.count = lencnt;
lencode.symbol = lensym;
distcode.count = distcnt;
distcode.symbol = distsym;
short lengths[FIXLCODES];
int symbol;
for (symbol = 0; symbol < 144; symbol++)
lengths[symbol] = 8;
for (; symbol < 256; symbol++)
lengths[symbol] = 9;
for (; symbol < 280; symbol++)
lengths[symbol] = 7;
for (; symbol < FIXLCODES; symbol++)
lengths[symbol] = 8;
puff_construct(&lencode, lengths, FIXLCODES);
for (symbol = 0; symbol < MAXDCODES; symbol++)
lengths[symbol] = 5;
puff_construct(&distcode, lengths, MAXDCODES);
virgin = 0;
}
return puff_codes(s, &lencode, &distcode);
}
static int puff_dynamic(struct puff_state* s)
{
static const short order[19] =
{16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
int nlen = puff_bits(s, 5) + 257;
int ndist = puff_bits(s, 5) + 1;
int ncode = puff_bits(s, 4) + 4;
if (nlen > MAXLCODES || ndist > MAXDCODES)
return -3;
short lengths[MAXCODES];
int index;
for (index = 0; index < ncode; index++)
lengths[order[index]] = puff_bits(s, 3);
for (; index < 19; index++)
lengths[order[index]] = 0;
short lencnt[MAXBITS + 1], lensym[MAXLCODES];
struct puff_huffman lencode = {lencnt, lensym};
int err = puff_construct(&lencode, lengths, 19);
if (err != 0)
return -4;
index = 0;
while (index < nlen + ndist) {
int symbol;
int len;
symbol = puff_decode(s, &lencode);
if (symbol < 0)
return symbol;
if (symbol < 16)
lengths[index++] = symbol;
else {
len = 0;
if (symbol == 16) {
if (index == 0)
return -5;
len = lengths[index - 1];
symbol = 3 + puff_bits(s, 2);
} else if (symbol == 17)
symbol = 3 + puff_bits(s, 3);
else
symbol = 11 + puff_bits(s, 7);
if (index + symbol > nlen + ndist)
return -6;
while (symbol--)
lengths[index++] = len;
}
}
if (lengths[256] == 0)
return -9;
err = puff_construct(&lencode, lengths, nlen);
if (err && (err < 0 || nlen != lencode.count[0] + lencode.count[1]))
return -7;
short distcnt[MAXBITS + 1], distsym[MAXDCODES];
struct puff_huffman distcode = {distcnt, distsym};
err = puff_construct(&distcode, lengths + nlen, ndist);
if (err && (err < 0 || ndist != distcode.count[0] + distcode.count[1]))
return -8;
return puff_codes(s, &lencode, &distcode);
}
static int puff(
unsigned char* dest,
unsigned long* destlen,
const unsigned char* source,
unsigned long sourcelen)
{
struct puff_state s = {
.out = dest,
.outlen = *destlen,
.outcnt = 0,
.in = source,
.inlen = sourcelen,
.incnt = 0,
.bitbuf = 0,
.bitcnt = 0,
};
int err;
if (setjmp(s.env) != 0)
err = 2;
else {
int last;
do {
last = puff_bits(&s, 1);
int type = puff_bits(&s, 2);
err = type == 0 ? puff_stored(&s) : (type == 1 ? puff_fixed(&s) : (type == 2 ? puff_dynamic(&s) : -1));
if (err != 0)
break;
} while (!last);
}
*destlen = s.outcnt;
return err;
}
//% END CODE DERIVED FROM puff.{c,h}
#define ZLIB_HEADER_WIDTH 2
static int puff_zlib_to_file(const unsigned char* source, unsigned long sourcelen, int dest_fd)
{
if (sourcelen < ZLIB_HEADER_WIDTH)
return 0;
source += ZLIB_HEADER_WIDTH;
sourcelen -= ZLIB_HEADER_WIDTH;
const unsigned long max_destlen = 132 << 20;
void* ret = mmap(0, max_destlen, PROT_WRITE | PROT_READ, MAP_PRIVATE | MAP_ANON, -1, 0);
if (ret == MAP_FAILED)
return -1;
unsigned char* dest = (unsigned char*)ret;
unsigned long destlen = max_destlen;
int err = puff(dest, &destlen, source, sourcelen);
if (err) {
munmap(dest, max_destlen);
errno = -err;
return -1;
}
if (write(dest_fd, dest, destlen) != (ssize_t)destlen) {
munmap(dest, max_destlen);
return -1;
}
return munmap(dest, max_destlen);
}
static int setup_loop_device(unsigned char* data, unsigned long size, const char* loopname, int* loopfd_p)
{
int err = 0, loopfd = -1;
int memfd = syscall(__NR_memfd_create, "syzkaller", 0);
if (memfd == -1) {
err = errno;
goto error;
}
if (puff_zlib_to_file(data, size, memfd)) {
err = errno;
goto error_close_memfd;
}
loopfd = open(loopname, O_RDWR);
if (loopfd == -1) {
err = errno;
goto error_close_memfd;
}
if (ioctl(loopfd, LOOP_SET_FD, memfd)) {
if (errno != EBUSY) {
err = errno;
goto error_close_loop;
}
ioctl(loopfd, LOOP_CLR_FD, 0);
usleep(1000);
if (ioctl(loopfd, LOOP_SET_FD, memfd)) {
err = errno;
goto error_close_loop;
}
}
close(memfd);
*loopfd_p = loopfd;
return 0;
error_close_loop:
close(loopfd);
error_close_memfd:
close(memfd);
error:
errno = err;
return -1;
}
static void reset_loop_device(const char* loopname)
{
int loopfd = open(loopname, O_RDWR);
if (loopfd == -1) {
return;
}
if (ioctl(loopfd, LOOP_CLR_FD, 0)) {
}
close(loopfd);
}
static long syz_mount_image(
volatile long fsarg,
volatile long dir,
volatile long flags,
volatile long optsarg,
volatile long change_dir,
volatile unsigned long size,
volatile long image)
{
unsigned char* data = (unsigned char*)image;
int res = -1, err = 0, need_loop_device = !!size;
char* mount_opts = (char*)optsarg;
char* target = (char*)dir;
char* fs = (char*)fsarg;
char* source = NULL;
char loopname[64];
if (need_loop_device) {
int loopfd;
memset(loopname, 0, sizeof(loopname));
snprintf(loopname, sizeof(loopname), "/dev/loop%llu", procid);
if (setup_loop_device(data, size, loopname, &loopfd) == -1)
return -1;
close(loopfd);
source = loopname;
}
mkdir(target, 0777);
char opts[256];
memset(opts, 0, sizeof(opts));
if (strlen(mount_opts) > (sizeof(opts) - 32)) {
}
strncpy(opts, mount_opts, sizeof(opts) - 32);
if (strcmp(fs, "iso9660") == 0) {
flags |= MS_RDONLY;
} else if (strncmp(fs, "ext", 3) == 0) {
bool has_remount_ro = false;
char* remount_ro_start = strstr(opts, "errors=remount-ro");
if (remount_ro_start != NULL) {
char after = *(remount_ro_start + strlen("errors=remount-ro"));
char before = remount_ro_start == opts ? '\0' : *(remount_ro_start - 1);
has_remount_ro = ((before == '\0' || before == ',') && (after == '\0' || after == ','));
}
if (strstr(opts, "errors=panic") || !has_remount_ro)
strcat(opts, ",errors=continue");
} else if (strcmp(fs, "xfs") == 0) {
strcat(opts, ",nouuid");
} else if (strncmp(fs, "gfs2", 4) == 0 && (strstr(opts, "errors=panic") || strstr(opts, "debug"))) {
strcat(opts, ",errors=withdraw");
}
res = mount(source, target, fs, flags, opts);
if (res == -1) {
err = errno;
goto error_clear_loop;
}
res = open(target, O_RDONLY | O_DIRECTORY);
if (res == -1) {
err = errno;
goto error_clear_loop;
}
if (change_dir) {
res = chdir(target);
if (res == -1) {
err = errno;
}
}
error_clear_loop:
if (need_loop_device)
reset_loop_device(loopname);
errno = err;
return res;
}
uint64_t r[1] = {0xffffffffffffffff};
int main(void)
{
syscall(__NR_mmap, /*addr=*/0x1ffffffff000ul, /*len=*/0x1000ul, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul);
syscall(__NR_mmap, /*addr=*/0x200000000000ul, /*len=*/0x1000000ul, /*prot=PROT_WRITE|PROT_READ|PROT_EXEC*/7ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul);
syscall(__NR_mmap, /*addr=*/0x200001000000ul, /*len=*/0x1000ul, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul);
const char* reason;
(void)reason;
intptr_t res = 0;
if (write(1, "executing program\n", sizeof("executing program\n") - 1)) {}
// syz_mount_image$ext4 arguments: [
// fs: ptr[in, buffer] {
// buffer: {65 78 74 34 00} (length 0x5)
// }
// dir: ptr[in, buffer] {
// buffer: {2e 2f 66 69 6c 65 30 00} (length 0x8)
// }
// flags: mount_flags = 0x800 (8 bytes)
// opts: ptr[in, fs_options[ext4_options]] {
// fs_options[ext4_options] {
// elems: array[fs_opt_elem[ext4_options]] {
// fs_opt_elem[ext4_options] {
// elem: union ext4_options {
// debug: buffer: {64 65 62 75 67} (length 0x5)
// }
// comma: const = 0x2c (1 bytes)
// }
// fs_opt_elem[ext4_options] {
// elem: union ext4_options {
// nolazytime: buffer: {6e 6f 6c 61 7a 79 74 69 6d 65} (length 0xa)
// }
// comma: const = 0x2c (1 bytes)
// }
// fs_opt_elem[ext4_options] {
// elem: union ext4_options {
// dax_inode: buffer: {64 61 78 3d 69 6e 6f 64 65} (length 0x9)
// }
// comma: const = 0x2c (1 bytes)
// }
// fs_opt_elem[ext4_options] {
// elem: union ext4_options {
// jqfmt_vfsv0: buffer: {6a 71 66 6d 74 3d 76 66 73 76 30} (length 0xb)
// }
// comma: const = 0x2c (1 bytes)
// }
// fs_opt_elem[ext4_options] {
// elem: union ext4_options {
// dioread_lock: buffer: {64 69 6f 72 65 61 64 5f 6c 6f 63 6b} (length 0xc)
// }
// comma: const = 0x2c (1 bytes)
// }
// fs_opt_elem[ext4_options] {
// elem: union ext4_options {
// usrjquota_path: fs_opt["usrjquota", stringnoz[filename]] {
// name: buffer: {75 73 72 6a 71 75 6f 74 61} (length 0x9)
// eq: const = 0x3d (1 bytes)
// val: buffer: {2e} (length 0x1)
// }
// }
// comma: const = 0x2c (1 bytes)
// }
// fs_opt_elem[ext4_options] {
// elem: union ext4_options {
// test_dummy_encryption: buffer: {74 65 73 74 5f 64 75 6d 6d 79 5f 65 6e 63 72 79 70 74 69 6f 6e} (length 0x15)
// }
// comma: const = 0x2c (1 bytes)
// }
// }
// common: array[fs_opt_elem[fs_options_common]] {
// }
// null: const = 0x0 (1 bytes)
// }
// }
// chdir: int8 = 0x3 (1 bytes)
// size: len = 0x236 (8 bytes)
// img: ptr[in, buffer] {
// buffer: (compressed buffer with length 0x236)
// }
// ]
// returns fd_dir
memcpy((void*)0x200000000240, "ext4\000", 5);
memcpy((void*)0x200000000640, "./file0\000", 8);
memcpy((void*)0x200000000680, "debug", 5);
*(uint8_t*)0x200000000685 = 0x2c;
memcpy((void*)0x200000000686, "nolazytime", 10);
*(uint8_t*)0x200000000690 = 0x2c;
memcpy((void*)0x200000000691, "dax=inode", 9);
*(uint8_t*)0x20000000069a = 0x2c;
memcpy((void*)0x20000000069b, "jqfmt=vfsv0", 11);
*(uint8_t*)0x2000000006a6 = 0x2c;
memcpy((void*)0x2000000006a7, "dioread_lock", 12);
*(uint8_t*)0x2000000006b3 = 0x2c;
memcpy((void*)0x2000000006b4, "usrjquota", 9);
*(uint8_t*)0x2000000006bd = 0x3d;
memset((void*)0x2000000006be, 46, 1);
*(uint8_t*)0x2000000006bf = 0x2c;
memcpy((void*)0x2000000006c0, "test_dummy_encryption", 21);
*(uint8_t*)0x2000000006d5 = 0x2c;
*(uint8_t*)0x2000000006d6 = 0;
memcpy((void*)0x200000000300, "... [truncated large byte array] ...", 566);
syz_mount_image(/*fs=*/0x200000000240, /*dir=*/0x200000000640, /*flags=MS_NODIRATIME*/0x800, /*opts=*/0x200000000680, /*chdir=*/3, /*size=*/0x236, /*img=*/0x200000000300);
// openat arguments: [
// fd: fd_dir (resource)
// file: ptr[in, buffer] {
// buffer: {2e 2f 66 69 6c 65 31 00} (length 0x8)
// }
// flags: open_flags = 0x143041 (4 bytes)
// mode: open_mode = 0x0 (2 bytes)
// ]
// returns fd
memcpy((void*)0x200000000280, "./file1\000", 8);
res = syscall(__NR_openat, /*fd=*/0xffffff9c, /*file=*/0x200000000280ul, /*flags=O_SYNC|O_NOATIME|O_CREAT|FASYNC|O_WRONLY*/0x143041, /*mode=*/0);
if (res != -1)
r[0] = res;
// pwritev2 arguments: [
// fd: fd (resource)
// vec: ptr[in, array[iovec[in, array[int8]]]] {
// array[iovec[in, array[int8]]] {
// iovec[in, array[int8]] {
// addr: ptr[in, buffer] {
// buffer: {ff} (length 0x1)
// }
// len: len = 0xfdef (8 bytes)
// }
// }
// }
// vlen: len = 0x1 (8 bytes)
// off_low: int32 = 0xe7b (4 bytes)
// off_high: int32 = 0x0 (4 bytes)
// flags: rwf_flags = 0x0 (8 bytes)
// ]
*(uint64_t*)0x2000000001c0 = 0x200000000080;
memset((void*)0x200000000080, 255, 1);
*(uint64_t*)0x2000000001c8 = 0xfdef;
syscall(__NR_pwritev2, /*fd=*/r[0], /*vec=*/0x2000000001c0ul, /*vlen=*/1ul, /*off_low=*/0xe7b, /*off_high=*/0, /*flags=*/0ul);
return 0;
}
]
|
| 2/1 |
2026/06/01 10:04 |
action |
kernel-checkouter |
1m
Results: map[KernelSrc:/app/workdir/cache/src/b853932181ea41cd21f5f4f533dca12b8d8efc79]
|
| 3/1 |
2026/06/01 10:06 |
action |
kernel-builder |
28m
Results: map[KernelObj:/app/workdir/cache/build/a76b46c4a1c401fe15fb3bfad4c2bcd60451cd62]
|
| 4/1 |
2026/06/01 10:34 |
action |
codesearch-prepare |
12m
Results: map[Index:codesearch-index]
|
| 5/1 |
2026/06/01 10:47 |
agent |
expert |
9m
Model:
Results: map[DenialOfService:false Exploitable:false FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:false RemoteTrigger:false Unprivileged:true UserNamespace:true VMGuestTrigger:false VMHostTrigger:false]
Instruction: You are an experienced Linux kernel security engineer. Your task is to analyze given kernel bug report
and determine its security impact based on the following dimensions.
Use the provided tools to examine the source code, check for capability checks (e.g., capable(), ns_capable()),
and understand the nature of the bug. Analyze the given kernel build and configuration.
You can check the kernel config by grepping ".config" file; you can check kernel cmdline by grepping
".config" file for "CONFIG_CMDLINE=". Assume sysctl parameters have default values.
But analyze for the corresponding production build w/o debugging tools enabled (like KASAN, KMSAN, UBSAN).
Try different strategies when analyzing the bug:
- think of ways in which the vulnerable code is unreachable
- or the other way around: try to come up with different ideas of how an unprivileged user can reach the bug
If still unsure err on the side of the bug being non-exploitable/not-accessible.
In the final reply, provide a reasoning for your assessment.
Analysis dimensions:
* Exploitable:
Determine if the bug can result in memory corruption or elevated privileges.
Memory safety issues are almost always exploitable (KASAN or UBSAN reports for use-after-free, out-of-bounds;
refcounting issues, corrupted lists, etc). When kernel is crashing on a completely wild pointer access
(e.g. user-space address, or non-canonical address, but not on NULL or address corresponding to KASAN shadow
for NULL address), including both data accesses and control transfers, that also usually implies possibility
of exploitation. Such reports usually say "unable to handle kernel paging request".
Uses of uninitialized values detected by KMSAN may be exploitable b/c attacker frequently can affect uninit
values with spraying techniques. However, for these exploitability depends on how exactly the uninit value
is used in the code, and what it affects.
Think of what happens after the bug is triggered. Some bugs cause kernel panic and halt execution,
they are harder to exploit. For example, BUG reports halts the kernel. However, WARNING reports don't halt
execution in production builds. Debug bug detection tools (like KASAN, KMSAN, KCSAN, UBSAN) are also not enabled
in production builds, so attacker can freely exploit these bugs w/o being detected by these tools.
If you see an integer overflow, think how the overflowed value used later (if it's used as allocation size,
or an array index). If you see an out-of-bounds read, think if it's followed by an out-of-bounds write as well.
Some KCSAN data-races may be exploitable by skilled attackers as well. Think what data structures got corrupted
as the result of data races and how. However, note that kernel has lots of "benign" data races that don't lead
to any runtime misbehavior at all.
* Denial Of Service:
Determine if the bug can result in denial-of-service. Most bugs can, since they cause system crash,
hangs, deadlocks, or resource leaks. This is mostly applicable to WARNING bugs that won't cause system crash
in production. For these think what will be consequences of the violation of the kernel assumptions flagged
by the WARNING. In some cases the unexpected condition is also properly handled by the normal control flow
(e.g. with "if (WARN_ON(...))"), these won't cause denial-of-service. If the condition is not handled,
then it may or may not cause denial-of-service.
* Accessible From Unprivileged Processes:
Determine if the bug can be reached from a typical (non-root) user process that does NOT have any special capabilities
(like CAP_SYS_ADMIN, CAP_NET_ADMIN, CAP_NET_RAW, CAP_PERFMON) or access to device nodes restricted to root.
Assume that unprivileged_bpf_disabled=1, that is eBPF loading is not accessible. However, cBPF (classical BPF)
is still accessible to non-root processes.
Assume that user namespaces are not accessible, that is, the process cannot get the mentioned capabilities even
within a new user namespace (checked by ns_capable() function in the kernel sources).
* Accessible From User Namespaces:
Determine if the bug can be reached within a user-namespace where the process has all capabilities
(including CAP_SYS_ADMIN, CAP_NET_ADMIN, CAP_NET_RAW, CAP_PERFMON). Such capabilities are checked with ns_capable()
function in the kernel sources.
* VM Guest Trigger:
Determine if the bug can be triggered from the context of a typical KVM guest (e.g., set up by a QEMU VMM).
Consider accesses to standard Linux host paravirtualized features (virtio-blk, virtio-net, etc.),
and handling of VM exits in the KVM code.
* VM Host Trigger in The Confidential Computing Context:
Determine if the bug can be triggered in a confidential computing guest kernel from the context of a KVM host.
Consider access to standard Linux guest paravirtualized features (virtio-blk, virtio-net, etc.).
* Ethernet Network Trigger:
Determine if the bug can be triggered by processing ingress network Ethernet traffic, either directly (network stack)
or via drivers exposed to network data.
* Other Remote Trigger:
Determine if the bug can be triggered by processing remote traffic other than Ethernet (Wifi, Bluetooth, NFC, etc).
* Peripheral Trigger:
Determine if the bug can be triggered via an untrusted peripheral device that can be physically plugged
into a system, such as a USB device or a niche hardware driver handling external hardware inputs.
This is particularly important for mobile and desktop environments where users can plug in unknown devices.
* Malicious Filesystem Trigger:
Determine if the bug can be triggered by the kernel mounting and parsing a malicious filesystem image.
This is highly critical for Desktop and Mobile environments where external media or downloaded images
might be auto-mounted.
Don't make assumptions about the kernel source code (it may be different from what you assume it is).
Extensively use the provided code access tools (codesearch-*, git-*, grepper, etc)
to examine the actual source code, and confirm any assumptions.
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt:
The kernel bug report is:
EXT4-fs (loop0): mounted filesystem 76b65be2-f6da-4727-8c75-0525a5b65a09 r/w without journal. Quota mode: writeback.
ext4 filesystem being mounted at /0/file0 supports timestamps until 2038-01-19 (0x7fffffff)
fscrypt: AES-256-XTS using implementation "xts(ecb(aes-lib))"
=====================================================
BUG: KMSAN: uninit-value in enc_quarterround lib/crypto/aes.c:330 [inline]
BUG: KMSAN: uninit-value in aes_encrypt_generic lib/crypto/aes.c:368 [inline]
BUG: KMSAN: uninit-value in aes_encrypt_arch lib/crypto/aes.c:464 [inline]
BUG: KMSAN: uninit-value in aes_encrypt+0x92d/0x11b0 lib/crypto/aes.c:504
enc_quarterround lib/crypto/aes.c:330 [inline]
aes_encrypt_generic lib/crypto/aes.c:368 [inline]
aes_encrypt_arch lib/crypto/aes.c:464 [inline]
aes_encrypt+0x92d/0x11b0 lib/crypto/aes.c:504
crypto_aes_encrypt+0x3f/0x50 crypto/aes.c:26
crypto_ecb_crypt crypto/ecb.c:23 [inline]
crypto_ecb_encrypt2+0x142/0x300 crypto/ecb.c:40
crypto_lskcipher_crypt_sg+0x3ad/0x960 crypto/lskcipher.c:188
crypto_lskcipher_encrypt_sg+0x8b/0xc0 crypto/lskcipher.c:207
crypto_skcipher_encrypt+0x111/0x1e0 crypto/skcipher.c:443
xts_encrypt+0x2e1/0x570 crypto/xts.c:269
crypto_skcipher_encrypt+0x18a/0x1e0 crypto/skcipher.c:444
fscrypt_crypt_data_unit+0x38e/0x590 fs/crypto/crypto.c:139
fscrypt_encrypt_pagecache_blocks+0x430/0x900 fs/crypto/crypto.c:197
ext4_bio_write_folio+0x138c/0x32a0 fs/ext4/page-io.c:553
mpage_submit_folio+0x399/0x3d0 fs/ext4/inode.c:2080
mpage_process_page_bufs+0xaef/0xf50 fs/ext4/inode.c:2191
mpage_prepare_extent_to_map+0x175d/0x2660 fs/ext4/inode.c:2730
ext4_do_writepages+0x11a0/0x7950 fs/ext4/inode.c:2871
ext4_writepages+0x337/0x870 fs/ext4/inode.c:3019
do_writepages+0x3f2/0x860 mm/page-writeback.c:2554
filemap_writeback mm/filemap.c:387 [inline]
filemap_fdatawrite_range mm/filemap.c:412 [inline]
file_write_and_wait_range+0x6f0/0x7d0 mm/filemap.c:786
generic_buffers_fsync_noflush+0x7a/0x3f0 fs/buffer.c:606
ext4_fsync_nojournal fs/ext4/fsync.c:88 [inline]
ext4_sync_file+0x586/0x13a0 fs/ext4/fsync.c:147
vfs_fsync_range+0x135/0x1c0 fs/sync.c:186
generic_write_sync include/linux/fs.h:2640 [inline]
ext4_buffered_write_iter+0xae9/0xce0 fs/ext4/file.c:306
ext4_file_write_iter+0x24b4/0x3d80 fs/ext4/file.c:-1
do_iter_readv_writev+0x9e0/0xc10 fs/read_write.c:-1
vfs_writev+0x52a/0x1500 fs/read_write.c:1059
do_pwritev fs/read_write.c:1155 [inline]
__do_sys_pwritev2 fs/read_write.c:1213 [inline]
__se_sys_pwritev2+0x22f/0x470 fs/read_write.c:1204
__x64_sys_pwritev2+0xe4/0x150 fs/read_write.c:1204
x64_sys_call+0x10a2/0x3ea0 arch/x86/include/generated/asm/syscalls_64.h:329
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0x134/0xf80 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
Uninit was stored to memory at:
le128_xor include/crypto/b128ops.h:69 [inline]
xts_xor_tweak+0x576/0xa90 crypto/xts.c:123
xts_xor_tweak_pre crypto/xts.c:135 [inline]
xts_encrypt+0x278/0x570 crypto/xts.c:268
crypto_skcipher_encrypt+0x18a/0x1e0 crypto/skcipher.c:444
fscrypt_crypt_data_unit+0x38e/0x590 fs/crypto/crypto.c:139
fscrypt_encrypt_pagecache_blocks+0x430/0x900 fs/crypto/crypto.c:197
ext4_bio_write_folio+0x138c/0x32a0 fs/ext4/page-io.c:553
mpage_submit_folio+0x399/0x3d0 fs/ext4/inode.c:2080
mpage_process_page_bufs+0xaef/0xf50 fs/ext4/inode.c:2191
mpage_prepare_extent_to_map+0x175d/0x2660 fs/ext4/inode.c:2730
ext4_do_writepages+0x11a0/0x7950 fs/ext4/inode.c:2871
ext4_writepages+0x337/0x870 fs/ext4/inode.c:3019
do_writepages+0x3f2/0x860 mm/page-writeback.c:2554
filemap_writeback mm/filemap.c:387 [inline]
filemap_fdatawrite_range mm/filemap.c:412 [inline]
file_write_and_wait_range+0x6f0/0x7d0 mm/filemap.c:786
generic_buffers_fsync_noflush+0x7a/0x3f0 fs/buffer.c:606
ext4_fsync_nojournal fs/ext4/fsync.c:88 [inline]
ext4_sync_file+0x586/0x13a0 fs/ext4/fsync.c:147
vfs_fsync_range+0x135/0x1c0 fs/sync.c:186
generic_write_sync include/linux/fs.h:2640 [inline]
ext4_buffered_write_iter+0xae9/0xce0 fs/ext4/file.c:306
ext4_file_write_iter+0x24b4/0x3d80 fs/ext4/file.c:-1
do_iter_readv_writev+0x9e0/0xc10 fs/read_write.c:-1
vfs_writev+0x52a/0x1500 fs/read_write.c:1059
do_pwritev fs/read_write.c:1155 [inline]
__do_sys_pwritev2 fs/read_write.c:1213 [inline]
__se_sys_pwritev2+0x22f/0x470 fs/read_write.c:1204
__x64_sys_pwritev2+0xe4/0x150 fs/read_write.c:1204
x64_sys_call+0x10a2/0x3ea0 arch/x86/include/generated/asm/syscalls_64.h:329
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0x134/0xf80 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
Uninit was created at:
__alloc_frozen_pages_noprof+0x6f7/0x1020 mm/page_alloc.c:5273
alloc_pages_mpol+0x328/0x860 mm/mempolicy.c:2484
alloc_frozen_pages_noprof mm/mempolicy.c:2555 [inline]
alloc_pages_noprof mm/mempolicy.c:2575 [inline]
folio_alloc_noprof+0x108/0x360 mm/mempolicy.c:2585
filemap_alloc_folio_noprof+0xd9/0x480 mm/filemap.c:1013
__filemap_get_folio_mpol+0xb43/0x1960 mm/filemap.c:2011
__filemap_get_folio include/linux/pagemap.h:774 [inline]
write_begin_get_folio include/linux/pagemap.h:800 [inline]
ext4_write_begin+0x6dd/0x2db0 fs/ext4/inode.c:1316
ext4_da_write_begin+0x75e/0x1490 fs/ext4/inode.c:3123
generic_perform_write+0x364/0x1050 mm/filemap.c:4319
ext4_buffered_write_iter+0x61a/0xce0 fs/ext4/file.c:300
ext4_file_write_iter+0x24b4/0x3d80 fs/ext4/file.c:-1
do_iter_readv_writev+0x9e0/0xc10 fs/read_write.c:-1
vfs_writev+0x52a/0x1500 fs/read_write.c:1059
do_pwritev fs/read_write.c:1155 [inline]
__do_sys_pwritev2 fs/read_write.c:1213 [inline]
__se_sys_pwritev2+0x22f/0x470 fs/read_write.c:1204
__x64_sys_pwritev2+0xe4/0x150 fs/read_write.c:1204
x64_sys_call+0x10a2/0x3ea0 arch/x86/include/generated/asm/syscalls_64.h:329
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0x134/0xf80 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
CPU: 0 UID: 0 PID: 6023 Comm: syz.0.17 Not tainted syzkaller #0 PREEMPT(full)
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 02/12/2026
=====================================================
It is reproducible with the followint program.
Keep in mind that it may lack the precise threading, sandboxing, and some arguments of a working reproducer.
But it should give an idea of the involved syscalls.
// autogenerated by syzkaller (https://github.com/google/syzkaller)
#define _GNU_SOURCE
#include <endian.h>
#include <errno.h>
#include <fcntl.h>
#include <setjmp.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/mount.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <unistd.h>
#include <linux/loop.h>
#ifndef __NR_memfd_create
#define __NR_memfd_create 319
#endif
#ifndef __NR_pwritev2
#define __NR_pwritev2 328
#endif
static unsigned long long procid;
//% This code is derived from puff.{c,h}, found in the zlib development. The
//% original files come with the following copyright notice:
//% Copyright (C) 2002-2013 Mark Adler, all rights reserved
//% version 2.3, 21 Jan 2013
//% This software is provided 'as-is', without any express or implied
//% warranty. In no event will the author be held liable for any damages
//% arising from the use of this software.
//% Permission is granted to anyone to use this software for any purpose,
//% including commercial applications, and to alter it and redistribute it
//% freely, subject to the following restrictions:
//% 1. The origin of this software must not be misrepresented; you must not
//% claim that you wrote the original software. If you use this software
//% in a product, an acknowledgment in the product documentation would be
//% appreciated but is not required.
//% 2. Altered source versions must be plainly marked as such, and must not be
//% misrepresented as being the original software.
//% 3. This notice may not be removed or altered from any source distribution.
//% Mark Adler madler@alumni.caltech.edu
//% BEGIN CODE DERIVED FROM puff.{c,h}
#define MAXBITS 15
#define MAXLCODES 286
#define MAXDCODES 30
#define MAXCODES (MAXLCODES + MAXDCODES)
#define FIXLCODES 288
struct puff_state {
unsigned char* out;
unsigned long outlen;
unsigned long outcnt;
const unsigned char* in;
unsigned long inlen;
unsigned long incnt;
int bitbuf;
int bitcnt;
jmp_buf env;
};
static int puff_bits(struct puff_state* s, int need)
{
long val = s->bitbuf;
while (s->bitcnt < need) {
if (s->incnt == s->inlen)
longjmp(s->env, 1);
val |= (long)(s->in[s->incnt++]) << s->bitcnt;
s->bitcnt += 8;
}
s->bitbuf = (int)(val >> need);
s->bitcnt -= need;
return (int)(val & ((1L << need) - 1));
}
static int puff_stored(struct puff_state* s)
{
s->bitbuf = 0;
s->bitcnt = 0;
if (s->incnt + 4 > s->inlen)
return 2;
unsigned len = s->in[s->incnt++];
len |= s->in[s->incnt++] << 8;
if (s->in[s->incnt++] != (~len & 0xff) ||
s->in[s->incnt++] != ((~len >> 8) & 0xff))
return -2;
if (s->incnt + len > s->inlen)
return 2;
if (s->outcnt + len > s->outlen)
return 1;
for (; len--; s->outcnt++, s->incnt++) {
if (s->in[s->incnt])
s->out[s->outcnt] = s->in[s->incnt];
}
return 0;
}
struct puff_huffman {
short* count;
short* symbol;
};
static int puff_decode(struct puff_state* s, const struct puff_huffman* h)
{
int first = 0;
int index = 0;
int bitbuf = s->bitbuf;
int left = s->bitcnt;
int code = first = index = 0;
int len = 1;
short* next = h->count + 1;
while (1) {
while (left--) {
code |= bitbuf & 1;
bitbuf >>= 1;
int count = *next++;
if (code - count < first) {
s->bitbuf = bitbuf;
s->bitcnt = (s->bitcnt - len) & 7;
return h->symbol[index + (code - first)];
}
index += count;
first += count;
first <<= 1;
code <<= 1;
len++;
}
left = (MAXBITS + 1) - len;
if (left == 0)
break;
if (s->incnt == s->inlen)
longjmp(s->env, 1);
bitbuf = s->in[s->incnt++];
if (left > 8)
left = 8;
}
return -10;
}
static int puff_construct(struct puff_huffman* h, const short* length, int n)
{
int len;
for (len = 0; len <= MAXBITS; len++)
h->count[len] = 0;
int symbol;
for (symbol = 0; symbol < n; symbol++)
(h->count[length[symbol]])++;
if (h->count[0] == n)
return 0;
int left = 1;
for (len = 1; len <= MAXBITS; len++) {
left <<= 1;
left -= h->count[len];
if (left < 0)
return left;
}
short offs[MAXBITS + 1];
offs[1] = 0;
for (len = 1; len < MAXBITS; len++)
offs[len + 1] = offs[len] + h->count[len];
for (symbol = 0; symbol < n; symbol++)
if (length[symbol] != 0)
h->symbol[offs[length[symbol]]++] = symbol;
return left;
}
static int puff_codes(struct puff_state* s,
const struct puff_huffman* lencode,
const struct puff_huffman* distcode)
{
static const short lens[29] = {
3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258};
static const short lext[29] = {
0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0};
static const short dists[30] = {
1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
8193, 12289, 16385, 24577};
static const short dext[30] = {
0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,
7, 7, 8, 8, 9, 9, 10, 10, 11, 11,
12, 12, 13, 13};
int symbol;
do {
symbol = puff_decode(s, lencode);
if (symbol < 0)
return symbol;
if (symbol < 256) {
if (s->outcnt == s->outlen)
return 1;
if (symbol)
s->out[s->outcnt] = symbol;
s->outcnt++;
} else if (symbol > 256) {
symbol -= 257;
if (symbol >= 29)
return -10;
int len = lens[symbol] + puff_bits(s, lext[symbol]);
symbol = puff_decode(s, distcode);
if (symbol < 0)
return symbol;
unsigned dist = dists[symbol] + puff_bits(s, dext[symbol]);
if (dist > s->outcnt)
return -11;
if (s->outcnt + len > s->outlen)
return 1;
while (len--) {
if (dist <= s->outcnt && s->out[s->outcnt - dist])
s->out[s->outcnt] = s->out[s->outcnt - dist];
s->outcnt++;
}
}
} while (symbol != 256);
return 0;
}
static int puff_fixed(struct puff_state* s)
{
static int virgin = 1;
static short lencnt[MAXBITS + 1], lensym[FIXLCODES];
static short distcnt[MAXBITS + 1], distsym[MAXDCODES];
static struct puff_huffman lencode, distcode;
if (virgin) {
lencode.count = lencnt;
lencode.symbol = lensym;
distcode.count = distcnt;
distcode.symbol = distsym;
short lengths[FIXLCODES];
int symbol;
for (symbol = 0; symbol < 144; symbol++)
lengths[symbol] = 8;
for (; symbol < 256; symbol++)
lengths[symbol] = 9;
for (; symbol < 280; symbol++)
lengths[symbol] = 7;
for (; symbol < FIXLCODES; symbol++)
lengths[symbol] = 8;
puff_construct(&lencode, lengths, FIXLCODES);
for (symbol = 0; symbol < MAXDCODES; symbol++)
lengths[symbol] = 5;
puff_construct(&distcode, lengths, MAXDCODES);
virgin = 0;
}
return puff_codes(s, &lencode, &distcode);
}
static int puff_dynamic(struct puff_state* s)
{
static const short order[19] =
{16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
int nlen = puff_bits(s, 5) + 257;
int ndist = puff_bits(s, 5) + 1;
int ncode = puff_bits(s, 4) + 4;
if (nlen > MAXLCODES || ndist > MAXDCODES)
return -3;
short lengths[MAXCODES];
int index;
for (index = 0; index < ncode; index++)
lengths[order[index]] = puff_bits(s, 3);
for (; index < 19; index++)
lengths[order[index]] = 0;
short lencnt[MAXBITS + 1], lensym[MAXLCODES];
struct puff_huffman lencode = {lencnt, lensym};
int err = puff_construct(&lencode, lengths, 19);
if (err != 0)
return -4;
index = 0;
while (index < nlen + ndist) {
int symbol;
int len;
symbol = puff_decode(s, &lencode);
if (symbol < 0)
return symbol;
if (symbol < 16)
lengths[index++] = symbol;
else {
len = 0;
if (symbol == 16) {
if (index == 0)
return -5;
len = lengths[index - 1];
symbol = 3 + puff_bits(s, 2);
} else if (symbol == 17)
symbol = 3 + puff_bits(s, 3);
else
symbol = 11 + puff_bits(s, 7);
if (index + symbol > nlen + ndist)
return -6;
while (symbol--)
lengths[index++] = len;
}
}
if (lengths[256] == 0)
return -9;
err = puff_construct(&lencode, lengths, nlen);
if (err && (err < 0 || nlen != lencode.count[0] + lencode.count[1]))
return -7;
short distcnt[MAXBITS + 1], distsym[MAXDCODES];
struct puff_huffman distcode = {distcnt, distsym};
err = puff_construct(&distcode, lengths + nlen, ndist);
if (err && (err < 0 || ndist != distcode.count[0] + distcode.count[1]))
return -8;
return puff_codes(s, &lencode, &distcode);
}
static int puff(
unsigned char* dest,
unsigned long* destlen,
const unsigned char* source,
unsigned long sourcelen)
{
struct puff_state s = {
.out = dest,
.outlen = *destlen,
.outcnt = 0,
.in = source,
.inlen = sourcelen,
.incnt = 0,
.bitbuf = 0,
.bitcnt = 0,
};
int err;
if (setjmp(s.env) != 0)
err = 2;
else {
int last;
do {
last = puff_bits(&s, 1);
int type = puff_bits(&s, 2);
err = type == 0 ? puff_stored(&s) : (type == 1 ? puff_fixed(&s) : (type == 2 ? puff_dynamic(&s) : -1));
if (err != 0)
break;
} while (!last);
}
*destlen = s.outcnt;
return err;
}
//% END CODE DERIVED FROM puff.{c,h}
#define ZLIB_HEADER_WIDTH 2
static int puff_zlib_to_file(const unsigned char* source, unsigned long sourcelen, int dest_fd)
{
if (sourcelen < ZLIB_HEADER_WIDTH)
return 0;
source += ZLIB_HEADER_WIDTH;
sourcelen -= ZLIB_HEADER_WIDTH;
const unsigned long max_destlen = 132 << 20;
void* ret = mmap(0, max_destlen, PROT_WRITE | PROT_READ, MAP_PRIVATE | MAP_ANON, -1, 0);
if (ret == MAP_FAILED)
return -1;
unsigned char* dest = (unsigned char*)ret;
unsigned long destlen = max_destlen;
int err = puff(dest, &destlen, source, sourcelen);
if (err) {
munmap(dest, max_destlen);
errno = -err;
return -1;
}
if (write(dest_fd, dest, destlen) != (ssize_t)destlen) {
munmap(dest, max_destlen);
return -1;
}
return munmap(dest, max_destlen);
}
static int setup_loop_device(unsigned char* data, unsigned long size, const char* loopname, int* loopfd_p)
{
int err = 0, loopfd = -1;
int memfd = syscall(__NR_memfd_create, "syzkaller", 0);
if (memfd == -1) {
err = errno;
goto error;
}
if (puff_zlib_to_file(data, size, memfd)) {
err = errno;
goto error_close_memfd;
}
loopfd = open(loopname, O_RDWR);
if (loopfd == -1) {
err = errno;
goto error_close_memfd;
}
if (ioctl(loopfd, LOOP_SET_FD, memfd)) {
if (errno != EBUSY) {
err = errno;
goto error_close_loop;
}
ioctl(loopfd, LOOP_CLR_FD, 0);
usleep(1000);
if (ioctl(loopfd, LOOP_SET_FD, memfd)) {
err = errno;
goto error_close_loop;
}
}
close(memfd);
*loopfd_p = loopfd;
return 0;
error_close_loop:
close(loopfd);
error_close_memfd:
close(memfd);
error:
errno = err;
return -1;
}
static void reset_loop_device(const char* loopname)
{
int loopfd = open(loopname, O_RDWR);
if (loopfd == -1) {
return;
}
if (ioctl(loopfd, LOOP_CLR_FD, 0)) {
}
close(loopfd);
}
static long syz_mount_image(
volatile long fsarg,
volatile long dir,
volatile long flags,
volatile long optsarg,
volatile long change_dir,
volatile unsigned long size,
volatile long image)
{
unsigned char* data = (unsigned char*)image;
int res = -1, err = 0, need_loop_device = !!size;
char* mount_opts = (char*)optsarg;
char* target = (char*)dir;
char* fs = (char*)fsarg;
char* source = NULL;
char loopname[64];
if (need_loop_device) {
int loopfd;
memset(loopname, 0, sizeof(loopname));
snprintf(loopname, sizeof(loopname), "/dev/loop%llu", procid);
if (setup_loop_device(data, size, loopname, &loopfd) == -1)
return -1;
close(loopfd);
source = loopname;
}
mkdir(target, 0777);
char opts[256];
memset(opts, 0, sizeof(opts));
if (strlen(mount_opts) > (sizeof(opts) - 32)) {
}
strncpy(opts, mount_opts, sizeof(opts) - 32);
if (strcmp(fs, "iso9660") == 0) {
flags |= MS_RDONLY;
} else if (strncmp(fs, "ext", 3) == 0) {
bool has_remount_ro = false;
char* remount_ro_start = strstr(opts, "errors=remount-ro");
if (remount_ro_start != NULL) {
char after = *(remount_ro_start + strlen("errors=remount-ro"));
char before = remount_ro_start == opts ? '\0' : *(remount_ro_start - 1);
has_remount_ro = ((before == '\0' || before == ',') && (after == '\0' || after == ','));
}
if (strstr(opts, "errors=panic") || !has_remount_ro)
strcat(opts, ",errors=continue");
} else if (strcmp(fs, "xfs") == 0) {
strcat(opts, ",nouuid");
} else if (strncmp(fs, "gfs2", 4) == 0 && (strstr(opts, "errors=panic") || strstr(opts, "debug"))) {
strcat(opts, ",errors=withdraw");
}
res = mount(source, target, fs, flags, opts);
if (res == -1) {
err = errno;
goto error_clear_loop;
}
res = open(target, O_RDONLY | O_DIRECTORY);
if (res == -1) {
err = errno;
goto error_clear_loop;
}
if (change_dir) {
res = chdir(target);
if (res == -1) {
err = errno;
}
}
error_clear_loop:
if (need_loop_device)
reset_loop_device(loopname);
errno = err;
return res;
}
uint64_t r[1] = {0xffffffffffffffff};
int main(void)
{
syscall(__NR_mmap, /*addr=*/0x1ffffffff000ul, /*len=*/0x1000ul, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul);
syscall(__NR_mmap, /*addr=*/0x200000000000ul, /*len=*/0x1000000ul, /*prot=PROT_WRITE|PROT_READ|PROT_EXEC*/7ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul);
syscall(__NR_mmap, /*addr=*/0x200001000000ul, /*len=*/0x1000ul, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul);
const char* reason;
(void)reason;
intptr_t res = 0;
if (write(1, "executing program\n", sizeof("executing program\n") - 1)) {}
// syz_mount_image$ext4 arguments: [
// fs: ptr[in, buffer] {
// buffer: {65 78 74 34 00} (length 0x5)
// }
// dir: ptr[in, buffer] {
// buffer: {2e 2f 66 69 6c 65 30 00} (length 0x8)
// }
// flags: mount_flags = 0x800 (8 bytes)
// opts: ptr[in, fs_options[ext4_options]] {
// fs_options[ext4_options] {
// elems: array[fs_opt_elem[ext4_options]] {
// fs_opt_elem[ext4_options] {
// elem: union ext4_options {
// debug: buffer: {64 65 62 75 67} (length 0x5)
// }
// comma: const = 0x2c (1 bytes)
// }
// fs_opt_elem[ext4_options] {
// elem: union ext4_options {
// nolazytime: buffer: {6e 6f 6c 61 7a 79 74 69 6d 65} (length 0xa)
// }
// comma: const = 0x2c (1 bytes)
// }
// fs_opt_elem[ext4_options] {
// elem: union ext4_options {
// dax_inode: buffer: {64 61 78 3d 69 6e 6f 64 65} (length 0x9)
// }
// comma: const = 0x2c (1 bytes)
// }
// fs_opt_elem[ext4_options] {
// elem: union ext4_options {
// jqfmt_vfsv0: buffer: {6a 71 66 6d 74 3d 76 66 73 76 30} (length 0xb)
// }
// comma: const = 0x2c (1 bytes)
// }
// fs_opt_elem[ext4_options] {
// elem: union ext4_options {
// dioread_lock: buffer: {64 69 6f 72 65 61 64 5f 6c 6f 63 6b} (length 0xc)
// }
// comma: const = 0x2c (1 bytes)
// }
// fs_opt_elem[ext4_options] {
// elem: union ext4_options {
// usrjquota_path: fs_opt["usrjquota", stringnoz[filename]] {
// name: buffer: {75 73 72 6a 71 75 6f 74 61} (length 0x9)
// eq: const = 0x3d (1 bytes)
// val: buffer: {2e} (length 0x1)
// }
// }
// comma: const = 0x2c (1 bytes)
// }
// fs_opt_elem[ext4_options] {
// elem: union ext4_options {
// test_dummy_encryption: buffer: {74 65 73 74 5f 64 75 6d 6d 79 5f 65 6e 63 72 79 70 74 69 6f 6e} (length 0x15)
// }
// comma: const = 0x2c (1 bytes)
// }
// }
// common: array[fs_opt_elem[fs_options_common]] {
// }
// null: const = 0x0 (1 bytes)
// }
// }
// chdir: int8 = 0x3 (1 bytes)
// size: len = 0x236 (8 bytes)
// img: ptr[in, buffer] {
// buffer: (compressed buffer with length 0x236)
// }
// ]
// returns fd_dir
memcpy((void*)0x200000000240, "ext4\000", 5);
memcpy((void*)0x200000000640, "./file0\000", 8);
memcpy((void*)0x200000000680, "debug", 5);
*(uint8_t*)0x200000000685 = 0x2c;
memcpy((void*)0x200000000686, "nolazytime", 10);
*(uint8_t*)0x200000000690 = 0x2c;
memcpy((void*)0x200000000691, "dax=inode", 9);
*(uint8_t*)0x20000000069a = 0x2c;
memcpy((void*)0x20000000069b, "jqfmt=vfsv0", 11);
*(uint8_t*)0x2000000006a6 = 0x2c;
memcpy((void*)0x2000000006a7, "dioread_lock", 12);
*(uint8_t*)0x2000000006b3 = 0x2c;
memcpy((void*)0x2000000006b4, "usrjquota", 9);
*(uint8_t*)0x2000000006bd = 0x3d;
memset((void*)0x2000000006be, 46, 1);
*(uint8_t*)0x2000000006bf = 0x2c;
memcpy((void*)0x2000000006c0, "test_dummy_encryption", 21);
*(uint8_t*)0x2000000006d5 = 0x2c;
*(uint8_t*)0x2000000006d6 = 0;
memcpy((void*)0x200000000300, "... [truncated large byte array] ...", 566);
syz_mount_image(/*fs=*/0x200000000240, /*dir=*/0x200000000640, /*flags=MS_NODIRATIME*/0x800, /*opts=*/0x200000000680, /*chdir=*/3, /*size=*/0x236, /*img=*/0x200000000300);
// openat arguments: [
// fd: fd_dir (resource)
// file: ptr[in, buffer] {
// buffer: {2e 2f 66 69 6c 65 31 00} (length 0x8)
// }
// flags: open_flags = 0x143041 (4 bytes)
// mode: open_mode = 0x0 (2 bytes)
// ]
// returns fd
memcpy((void*)0x200000000280, "./file1\000", 8);
res = syscall(__NR_openat, /*fd=*/0xffffff9c, /*file=*/0x200000000280ul, /*flags=O_SYNC|O_NOATIME|O_CREAT|FASYNC|O_WRONLY*/0x143041, /*mode=*/0);
if (res != -1)
r[0] = res;
// pwritev2 arguments: [
// fd: fd (resource)
// vec: ptr[in, array[iovec[in, array[int8]]]] {
// array[iovec[in, array[int8]]] {
// iovec[in, array[int8]] {
// addr: ptr[in, buffer] {
// buffer: {ff} (length 0x1)
// }
// len: len = 0xfdef (8 bytes)
// }
// }
// }
// vlen: len = 0x1 (8 bytes)
// off_low: int32 = 0xe7b (4 bytes)
// off_high: int32 = 0x0 (4 bytes)
// flags: rwf_flags = 0x0 (8 bytes)
// ]
*(uint64_t*)0x2000000001c0 = 0x200000000080;
memset((void*)0x200000000080, 255, 1);
*(uint64_t*)0x2000000001c8 = 0xfdef;
syscall(__NR_pwritev2, /*fd=*/r[0], /*vec=*/0x2000000001c0ul, /*vlen=*/1ul, /*off_low=*/0xe7b, /*off_high=*/0, /*flags=*/0ul);
return 0;
}
Reply: Based on the analysis of the bug report and the kernel source code, here is the assessment of the issue:
**Root Cause and Mechanism:**
The bug is a KMSAN report for the use of an uninitialized value during filesystem encryption (`fscrypt`). It occurs when an unprivileged user writes to an encrypted file at an offset that leaves a hole at the beginning of a page cache folio (e.g., writing to block 1 while block 0 remains a hole).
1. When the write occurs, `ext4_write_begin` allocates a new folio for the page cache. This folio is allocated without the `__GFP_ZERO` flag, meaning it contains uninitialized memory (leftover data from previous uses).
2. `ext4_block_write_begin` processes the blocks within the folio. It only initializes (reads from disk or zeroes) the blocks that intersect with the write range. The blocks corresponding to the hole (e.g., block 0) are left unmapped and uninitialized.
3. Later, during the writeback phase, `ext4_bio_write_folio` is called to write the dirty folio to disk. It determines the length of the data to write (usually up to `i_size`).
4. It then calls `fscrypt_encrypt_pagecache_blocks` to encrypt the data into a newly allocated bounce page. However, `fscrypt_encrypt_pagecache_blocks` encrypts the data starting from offset 0 up to the rounded-up length, regardless of whether the underlying blocks are mapped or dirty.
5. This causes the kernel to read and encrypt the uninitialized memory in the unmapped hole blocks, which triggers the KMSAN warning.
**Security Impact:**
Despite reading uninitialized memory, this bug has **no security impact** and is **not exploitable**:
- After the encryption completes, `ext4_bio_write_folio` iterates over the buffer heads of the folio to submit them to the block layer.
- It strictly checks each buffer head and only submits those that were marked for asynchronous write (i.e., the blocks that were actually mapped and dirty).
- The ciphertext corresponding to the uninitialized hole blocks is placed in the bounce page but is **never submitted to the block layer**.
- Consequently, the uninitialized memory (and its ciphertext) is immediately discarded, never written to disk, and never exposed to userspace. It is a benign read of uninitialized memory that only trips debugging tools like KMSAN.
- In production builds (where KMSAN is disabled), this will silently encrypt garbage and discard it without causing any memory corruption, crashes, or information leaks.
**Trigger:**
The bug can be triggered by any unprivileged user who has the ability to create and write to an encrypted directory/file (which is standard on systems utilizing `fscrypt`, like Android or typical Linux desktops). No special capabilities or namespaces are required.
|
| 6/2 |
2026/06/01 10:47 |
llm |
expert |
0m
Model:
Tokens:
input: 17001
output: 35
thoughts: 1384
Thoughts: **KMSAN Uninit Value in AES Encryption: A Deep Dive**
Okay, so I've got a KMSAN report screaming about an uninitialized value, specifically within `enc_quarterround` in `lib/crypto/aes.c:330`. My initial thought is to trace the flow. This uninitialized value seems to originate during a page allocation, specifically at `__alloc_frozen_pages_noprof`. Right, that's expected behavior during page faults and allocations. I see it's then getting stored to memory via `le128_xor` within `xts_xor_tweak`, and eventually used within `enc_quarterround` through the `aes_encrypt_generic` function.
The stack trace clarifies the call chain, highlighting a path through `aes_encrypt_arch` then `aes_encrypt`. The trace then leads through the crypto layer and into the XTS mode encryption. This eventually hits the filesystem, specifically through `fscrypt_crypt_data_unit` which indicates that this is tied to filesystem encryption. Looks like we're working with encrypted data being written to disk. It's calling `ext4_bio_write_folio`, which suggests this might be an issue with ext4.
Digging further, I see the uninitialized value is getting stored in the tweak calculation within XTS mode, specifically the `xts_xor_tweak` function. This makes sense; the tweak is often derived from the sector number or other non-user-provided data. The trace back to the page allocation shows the same path from the earlier stack trace: it's tied to an ext4 write.
The key to the issue is the allocation: it goes through `ext4_write_begin`, which calls `ext4_da_write_begin` to allocate folios for the data write. Then itβs passing through `generic_perform_write`, which copies the data from userspace into those folios.
Now, let's examine the reproducer. There's a `pwritev2` syscall involved, writing to a file at an offset of 0xe7b with a length of 0xfdef. The iovec tells me that the buffer being written to is at a user-space address, and only *one* byte of it is initialized. The user buffer is `0x200000000080`. The write starts at 0xe7b.
Wait a secondβ¦ if `generic_perform_write` is copying data from user space, and the user space buffer only has one byte initialized, then itβs going to copy uninitialized user space memory into the kernel's folio, right? I wonder why KMSAN is complaining about uninitialized memory in this case. Usually, KMSAN flags kernel-allocated memory that's uninitialized, not user memory. Does KMSAN track user memory as initialized when copied from user? But `copy_from_user` *should* mark the copied memory as initialized... what happens if `copy_from_user` *fails* or only partially succeeds? If there's a page fault, it might return the number of bytes that *weren't* copied. If `generic_perform_write` doesn't account for this, could it leave the rest of the folio uninitialized? That's the key. Let's trace `generic_perform_write`'s code to confirm.
|
| 7/2 |
2026/06/01 10:47 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:mm/filemap.c Name:generic_perform_write]
Results: map[SourceCode:4291: ssize_t generic_perform_write(struct kiocb *iocb, struct iov_iter *i)
4292: {
4293: struct file *file = iocb->ki_filp;
4294: loff_t pos = iocb->ki_pos;
4295: struct address_space *mapping = file->f_mapping;
4296: const struct address_space_operations *a_ops = mapping->a_ops;
4297: size_t chunk = mapping_max_folio_size(mapping);
4298: long status = 0;
4299: ssize_t written = 0;
4300:
4301: do {
4302: struct folio *folio;
4303: size_t offset; /* Offset into folio */
4304: size_t bytes; /* Bytes to write to folio */
4305: size_t copied; /* Bytes copied from user */
4306: void *fsdata = NULL;
4307:
4308: bytes = iov_iter_count(i);
4309: retry:
4310: offset = pos & (chunk - 1);
4311: bytes = min(chunk - offset, bytes);
4312: balance_dirty_pages_ratelimited(mapping);
4313:
4314: if (fatal_signal_pending(current)) {
4315: status = -EINTR;
4316: break;
4317: }
4318:
4319: status = a_ops->write_begin(iocb, mapping, pos, bytes,
4320: &folio, &fsdata);
4321: if (unlikely(status < 0))
4322: break;
4323:
4324: offset = offset_in_folio(folio, pos);
4325: if (bytes > folio_size(folio) - offset)
4326: bytes = folio_size(folio) - offset;
4327:
4328: if (mapping_writably_mapped(mapping))
4329: flush_dcache_folio(folio);
4330:
4331: /*
4332: * Faults here on mmap()s can recurse into arbitrary
4333: * filesystem code. Lots of locks are held that can
4334: * deadlock. Use an atomic copy to avoid deadlocking
4335: * in page fault handling.
4336: */
4337: copied = copy_folio_from_iter_atomic(folio, offset, bytes, i);
4338: flush_dcache_folio(folio);
4339:
4340: status = a_ops->write_end(iocb, mapping, pos, bytes, copied,
4341: folio, fsdata);
4342: if (unlikely(status != copied)) {
4343: iov_iter_revert(i, copied - max(status, 0L));
4344: if (unlikely(status < 0))
4345: break;
4346: }
4347: cond_resched();
4348:
4349: if (unlikely(status == 0)) {
4350: /*
4351: * A short copy made ->write_end() reject the
4352: * thing entirely. Might be memory poisoning
4353: * halfway through, might be a race with munmap,
4354: * might be severe memory pressure.
4355: */
4356: if (chunk > PAGE_SIZE)
4357: chunk /= 2;
4358: if (copied) {
4359: bytes = copied;
4360: goto retry;
4361: }
4362:
4363: /*
4364: * 'folio' is now unlocked and faults on it can be
4365: * handled. Ensure forward progress by trying to
4366: * fault it in now.
4367: */
4368: if (fault_in_iov_iter_readable(i, bytes) == bytes) {
4369: status = -EFAULT;
4370: break;
4371: }
4372: } else {
4373: pos += status;
4374: written += status;
4375: }
4376: } while (iov_iter_count(i));
4377:
4378: if (!written)
4379: return status;
4380: iocb->ki_pos += written;
4381: return written;
4382: }
SourceFile:mm/filemap.c]
|
| 8/2 |
2026/06/01 10:48 |
llm |
expert |
0m
Model:
Tokens:
input: 20481
output: 40
thoughts: 625
Thoughts: **Uninitialized Data in Encrypted Files: A Deep Dive**
Okay, so I've got this interesting situation brewing. An uninitialized value is being created in `__alloc_frozen_pages_noprof`, and it's ending up in memory at `le128_xor`. The stack trace reveals this uninitialized data is being stored *during encryption*! My expertise is telling me, based on the call stack, that the encryption is happening within the XTS mode implementation (`xts_xor_tweak`, `xts_encrypt`, `crypto_skcipher_encrypt`) and down to the file system layer (`fscrypt_crypt_data_unit`, `fscrypt_encrypt_pagecache_blocks`). That initial allocation is coming from `ext4_write_begin`, through `__filemap_get_folio`, all the way down to the allocation function.
This is where things get really interesting. It seems like a folio allocated in `ext4_write_begin` is being populated with uninitialized data, and this dirty folio, data and all, is being fed to the encryption process and, ultimately, written to disk. My immediate question is *why* is the folio uninitialized? In `ext4_write_begin`, the folio allocation happens when we're writing to a file. If the write doesn't fully cover a block, we either have to read the existing block or zero it out.
Aha! There's a vital clue here... the mount options include `test_dummy_encryption`. This implies the file *is* encrypted. Okay, so now I'm starting to build a better picture. I should double check `ext4_da_write_begin` and `ext4_write_begin` to be certain. It's looking like we're not properly initializing the page before encrypting and writing it, probably due to some logic related to partial writes in the encryption context.
|
| 9/2 |
2026/06/01 10:48 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/ext4/inode.c Name:ext4_da_write_begin]
Results: map[SourceCode:3105: static int ext4_da_write_begin(const struct kiocb *iocb,
3106: struct address_space *mapping,
3107: loff_t pos, unsigned len,
3108: struct folio **foliop, void **fsdata)
3109: {
3110: int ret, retries = 0;
3111: struct folio *folio;
3112: pgoff_t index;
3113: struct inode *inode = mapping->host;
3114:
3115: ret = ext4_emergency_state(inode->i_sb);
3116: if (unlikely(ret))
3117: return ret;
3118:
3119: index = pos >> PAGE_SHIFT;
3120:
3121: if (ext4_nonda_switch(inode->i_sb) || ext4_verity_in_progress(inode)) {
3122: *fsdata = (void *)FALL_BACK_TO_NONDELALLOC;
3123: return ext4_write_begin(iocb, mapping, pos,
3124: len, foliop, fsdata);
3125: }
3126: *fsdata = (void *)0;
3127: trace_ext4_da_write_begin(inode, pos, len);
3128:
3129: if (ext4_test_inode_state(inode, EXT4_STATE_MAY_INLINE_DATA)) {
3130: ret = ext4_generic_write_inline_data(mapping, inode, pos, len,
3131: foliop, fsdata, true);
3132: if (ret < 0)
3133: return ret;
3134: if (ret == 1)
3135: return 0;
3136: }
3137:
3138: retry:
3139: folio = write_begin_get_folio(iocb, mapping, index, len);
3140: if (IS_ERR(folio))
3141: return PTR_ERR(folio);
3142:
3143: if (len > folio_next_pos(folio) - pos)
3144: len = folio_next_pos(folio) - pos;
3145:
3146: ret = ext4_block_write_begin(NULL, folio, pos, len,
3147: ext4_da_get_block_prep);
3148: if (ret < 0) {
3149: folio_unlock(folio);
3150: folio_put(folio);
3151: /*
3152: * ext4_block_write_begin may have instantiated a few blocks
3153: * outside i_size. Trim these off again. Don't need
3154: * i_size_read because we hold inode lock.
3155: */
3156: if (pos + len > inode->i_size)
3157: ext4_truncate_failed_write(inode);
3158:
3159: if (ret == -ENOSPC &&
3160: ext4_should_retry_alloc(inode->i_sb, &retries))
3161: goto retry;
3162: return ret;
3163: }
3164:
3165: *foliop = folio;
3166: return ret;
3167: }
SourceFile:fs/ext4/inode.c]
|
| 10/2 |
2026/06/01 10:48 |
llm |
expert |
0m
Model:
Tokens:
input: 22546
output: 38
thoughts: 223
Thoughts: **Analyzing the Ext4 Write Path**
Okay, so the stack trace points to `ext4_da_write_begin` calling `ext4_write_begin`. Specifically, I see `ext4_write_begin+0x6dd/0x2db0` and then `ext4_da_write_begin+0x75e/0x1490`. That makes sense; `ext4_da_write_begin` is a crucial part of the delayed allocation path. Let me double-check the code at fs/ext4/inode.c:3123... Aha! `ext4_da_write_begin` *does* explicitly call `ext4_write_begin` under certain conditions.
It looks like the `ext4_nonda_switch` check or the `ext4_verity_in_progress` is triggering this fallback to the non-delayed allocation path. That makes perfect sense - if we need to bypass DA, we call that other function, passing the `FALL_BACK_TO_NONDELALLOC` flag. Now I need to understand why this fallback is happening. Let me take a look at the implementation of `ext4_write_begin`...
|
| 11/2 |
2026/06/01 10:48 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/ext4/inode.c Name:ext4_write_begin]
Results: map[SourceCode:1266: /*
1267: * To preserve ordering, it is essential that the hole instantiation and
1268: * the data write be encapsulated in a single transaction. We cannot
1269: * close off a transaction and start a new one between the ext4_get_block()
1270: * and the ext4_write_end(). So doing the jbd2_journal_start at the start of
1271: * ext4_write_begin() is the right place.
1272: */
1273: static int ext4_write_begin(const struct kiocb *iocb,
1274: struct address_space *mapping,
1275: loff_t pos, unsigned len,
1276: struct folio **foliop, void **fsdata)
1277: {
1278: struct inode *inode = mapping->host;
1279: int ret, needed_blocks;
1280: handle_t *handle;
1281: int retries = 0;
1282: struct folio *folio;
1283: pgoff_t index;
1284: unsigned from, to;
1285:
1286: ret = ext4_emergency_state(inode->i_sb);
1287: if (unlikely(ret))
1288: return ret;
1289:
1290: trace_ext4_write_begin(inode, pos, len);
1291: /*
1292: * Reserve one block more for addition to orphan list in case
1293: * we allocate blocks but write fails for some reason
1294: */
1295: needed_blocks = ext4_chunk_trans_extent(inode,
1296: ext4_journal_blocks_per_folio(inode)) + 1;
1297: index = pos >> PAGE_SHIFT;
1298:
1299: if (ext4_test_inode_state(inode, EXT4_STATE_MAY_INLINE_DATA)) {
1300: ret = ext4_try_to_write_inline_data(mapping, inode, pos, len,
1301: foliop);
1302: if (ret < 0)
1303: return ret;
1304: if (ret == 1)
1305: return 0;
1306: }
1307:
1308: /*
1309: * write_begin_get_folio() can take a long time if the
1310: * system is thrashing due to memory pressure, or if the folio
1311: * is being written back. So grab it first before we start
1312: * the transaction handle. This also allows us to allocate
1313: * the folio (if needed) without using GFP_NOFS.
1314: */
1315: retry_grab:
1316: folio = write_begin_get_folio(iocb, mapping, index, len);
1317: if (IS_ERR(folio))
1318: return PTR_ERR(folio);
1319:
1320: if (len > folio_next_pos(folio) - pos)
1321: len = folio_next_pos(folio) - pos;
1322:
1323: from = offset_in_folio(folio, pos);
1324: to = from + len;
1325:
1326: /*
1327: * The same as page allocation, we prealloc buffer heads before
1328: * starting the handle.
1329: */
1330: if (!folio_buffers(folio))
1331: create_empty_buffers(folio, inode->i_sb->s_blocksize, 0);
1332:
1333: folio_unlock(folio);
1334:
1335: retry_journal:
1336: handle = ext4_journal_start(inode, EXT4_HT_WRITE_PAGE, needed_blocks);
1337: if (IS_ERR(handle)) {
1338: folio_put(folio);
1339: return PTR_ERR(handle);
1340: }
1341:
1342: folio_lock(folio);
1343: if (folio->mapping != mapping) {
1344: /* The folio got truncated from under us */
1345: folio_unlock(folio);
1346: folio_put(folio);
1347: ext4_journal_stop(handle);
1348: goto retry_grab;
1349: }
1350: /* In case writeback began while the folio was unlocked */
1351: folio_wait_stable(folio);
1352:
1353: if (ext4_should_dioread_nolock(inode))
1354: ret = ext4_block_write_begin(handle, folio, pos, len,
1355: ext4_get_block_unwritten);
1356: else
1357: ret = ext4_block_write_begin(handle, folio, pos, len,
1358: ext4_get_block);
1359: if (!ret && ext4_should_journal_data(inode)) {
1360: ret = ext4_walk_page_buffers(handle, inode,
1361: folio_buffers(folio), from, to,
1362: NULL, do_journal_get_write_access);
1363: }
1364:
1365: if (ret) {
1366: bool extended = (pos + len > inode->i_size) &&
1367: !ext4_verity_in_progress(inode);
1368:
1369: folio_unlock(folio);
1370: /*
1371: * ext4_block_write_begin may have instantiated a few blocks
1372: * outside i_size. Trim these off again. Don't need
1373: * i_size_read because we hold i_rwsem.
1374: *
1375: * Add inode to orphan list in case we crash before
1376: * truncate finishes
1377: */
1378: if (extended && ext4_can_truncate(inode))
1379: ext4_orphan_add(handle, inode);
1380:
1381: ext4_journal_stop(handle);
1382: if (extended) {
1383: ext4_truncate_failed_write(inode);
1384: /*
1385: * If truncate failed early the inode might
1386: * still be on the orphan list; we need to
1387: * make sure the inode is removed from the
1388: * orphan list in that case.
1389: */
1390: if (inode->i_nlink)
1391: ext4_orphan_del(NULL, inode);
1392: }
1393:
1394: if (ret == -EAGAIN ||
1395: (ret == -ENOSPC &&
1396: ext4_should_retry_alloc(inode->i_sb, &retries)))
1397: goto retry_journal;
1398: folio_put(folio);
1399: return ret;
1400: }
1401: *foliop = folio;
1402: return ret;
1403: }
SourceFile:fs/ext4/inode.c]
|
| 12/2 |
2026/06/01 10:48 |
llm |
expert |
0m
Model:
Tokens:
input: 25161
output: 40
thoughts: 120
Thoughts: **My Line of Inquiry: Encryption and Block Zeroing in ext4**
Okay, so I'm trying to wrap my head around this `ext4_block_write_begin` function, and how it handles encryption. I know that `ext4_block_write_begin` calls `__block_write_begin_int` β that's the key function. Now, in `__block_write_begin_int`, if I'm not completely overwriting a block and it's a *new* block, there's the standard behavior of zeroing the unwritten portions. But here's the crucial question: if the block is *encrypted*, does it first have to read the block from disk, decrypt it, and *then* zero the unwritten parts? Or, does it skip the decryption and just zero it, considering it a new block? That's what I'm trying to figure out. It makes sense that if it's new, it would just zero, but I need to understand whether this applies to the *folio* that holds the block, or the *block* on disk. Time to go back and check the `ext4_block_write_begin` function itself and confirm this.
|
| 13/2 |
2026/06/01 10:48 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/ext4/inode.c Name:ext4_block_write_begin]
Results: map[SourceCode:1155: int ext4_block_write_begin(handle_t *handle, struct folio *folio,
1156: loff_t pos, unsigned len,
1157: get_block_t *get_block)
1158: {
1159: unsigned int from = offset_in_folio(folio, pos);
1160: unsigned to = from + len;
1161: struct inode *inode = folio->mapping->host;
1162: unsigned block_start, block_end;
1163: sector_t block;
1164: int err = 0;
1165: unsigned int blocksize = i_blocksize(inode);
1166: struct buffer_head *bh, *head, *wait[2];
1167: int nr_wait = 0;
1168: int i;
1169: bool should_journal_data = ext4_should_journal_data(inode);
1170:
1171: BUG_ON(!folio_test_locked(folio));
1172: BUG_ON(to > folio_size(folio));
1173: BUG_ON(from > to);
1174: WARN_ON_ONCE(blocksize > folio_size(folio));
1175:
1176: head = folio_buffers(folio);
1177: if (!head)
1178: head = create_empty_buffers(folio, blocksize, 0);
1179: block = EXT4_PG_TO_LBLK(inode, folio->index);
1180:
1181: for (bh = head, block_start = 0; bh != head || !block_start;
1182: block++, block_start = block_end, bh = bh->b_this_page) {
1183: block_end = block_start + blocksize;
1184: if (block_end <= from || block_start >= to) {
1185: if (folio_test_uptodate(folio)) {
1186: set_buffer_uptodate(bh);
1187: }
1188: continue;
1189: }
1190: if (WARN_ON_ONCE(buffer_new(bh)))
1191: clear_buffer_new(bh);
1192: if (!buffer_mapped(bh)) {
1193: WARN_ON(bh->b_size != blocksize);
1194: err = ext4_journal_ensure_extent_credits(handle, inode);
1195: if (!err)
1196: err = get_block(inode, block, bh, 1);
1197: if (err)
1198: break;
1199: if (buffer_new(bh)) {
1200: /*
1201: * We may be zeroing partial buffers or all new
1202: * buffers in case of failure. Prepare JBD2 for
1203: * that.
1204: */
1205: if (should_journal_data)
1206: do_journal_get_write_access(handle,
1207: inode, bh);
1208: if (folio_test_uptodate(folio)) {
1209: /*
1210: * Unlike __block_write_begin() we leave
1211: * dirtying of new uptodate buffers to
1212: * ->write_end() time or
1213: * folio_zero_new_buffers().
1214: */
1215: set_buffer_uptodate(bh);
1216: continue;
1217: }
1218: if (block_end > to || block_start < from)
1219: folio_zero_segments(folio, to,
1220: block_end,
1221: block_start, from);
1222: continue;
1223: }
1224: }
1225: if (folio_test_uptodate(folio)) {
1226: set_buffer_uptodate(bh);
1227: continue;
1228: }
1229: if (!buffer_uptodate(bh) && !buffer_delay(bh) &&
1230: !buffer_unwritten(bh) &&
1231: (block_start < from || block_end > to)) {
1232: ext4_read_bh_lock(bh, 0, false);
1233: wait[nr_wait++] = bh;
1234: }
1235: }
1236: /*
1237: * If we issued read requests, let them complete.
1238: */
1239: for (i = 0; i < nr_wait; i++) {
1240: wait_on_buffer(wait[i]);
1241: if (!buffer_uptodate(wait[i]))
1242: err = -EIO;
1243: }
1244: if (unlikely(err)) {
1245: if (should_journal_data)
1246: ext4_journalled_zero_new_buffers(handle, inode, folio,
1247: from, to);
1248: else
1249: folio_zero_new_buffers(folio, from, to);
1250: } else if (fscrypt_inode_uses_fs_layer_crypto(inode)) {
1251: for (i = 0; i < nr_wait; i++) {
1252: int err2;
1253:
1254: err2 = fscrypt_decrypt_pagecache_blocks(folio,
1255: blocksize, bh_offset(wait[i]));
1256: if (err2) {
1257: clear_buffer_uptodate(wait[i]);
1258: err = err2;
1259: }
1260: }
1261: }
1262:
1263: return err;
1264: }
SourceFile:fs/ext4/inode.c]
|
| 14/2 |
2026/06/01 10:48 |
llm |
expert |
0m
Model:
Tokens:
input: 27284
output: 38
thoughts: 285
Thoughts: **My Ext4 Block Write Dilemma**
Okay, so I'm digging into `ext4_block_write_begin`, and it's hitting me that if it's a new block, the function uses `folio_zero_segments` to zero out any unwritten portions, which is good. The code snippet confirms it, especially if the buffer is brand new. I'm seeing:
```c
if (buffer_new(bh)) {
...
if (block_end > to || block_start < from)
folio_zero_segments(folio, to,
block_end,
block_start, from);
continue;
}
```
My concern now lies in what `folio_zero_segments` *actually* zeroes: `[to, block_end)` and `[block_start, from)`. That makes sense. But, isn't `[from, to)` the region *I* intend to write to, using `generic_perform_write`, with its copy function?
```c
copied = copy_folio_from_iter_atomic(folio, offset, bytes, i);
```
Then I start to worry: what if that copy fails, `copied < bytes`? `copy_folio_from_iter_atomic` doesn't get *everything*? Then `ext4_write_end` gets called. Now, will `write_end` then ensure the buffer is still properly marked as uptodate, or will it zero out the bits I didn't get to?
```c
status = a_ops->write_end(iocb, mapping, pos, bytes, copied,
folio, fsdata);
```
Hmm, I think I need to dive into `ext4_write_end` to fully understand the implications here. Gotta verify that error handling is correct, and unwritten areas are zeroed correctly, even with partial writes.
|
| 15/2 |
2026/06/01 10:48 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/ext4/inode.c Name:ext4_write_end]
Results: map[SourceCode:1420: /*
1421: * We need to pick up the new inode size which generic_commit_write gave us
1422: * `iocb` can be NULL - eg, when called from page_symlink().
1423: *
1424: * ext4 never places buffers on inode->i_mapping->i_private_list. metadata
1425: * buffers are managed internally.
1426: */
1427: static int ext4_write_end(const struct kiocb *iocb,
1428: struct address_space *mapping,
1429: loff_t pos, unsigned len, unsigned copied,
1430: struct folio *folio, void *fsdata)
1431: {
1432: handle_t *handle = ext4_journal_current_handle();
1433: struct inode *inode = mapping->host;
1434: loff_t old_size = inode->i_size;
1435: int ret = 0, ret2;
1436: int i_size_changed = 0;
1437: bool verity = ext4_verity_in_progress(inode);
1438:
1439: trace_ext4_write_end(inode, pos, len, copied);
1440:
1441: if (ext4_has_inline_data(inode) &&
1442: ext4_test_inode_state(inode, EXT4_STATE_MAY_INLINE_DATA))
1443: return ext4_write_inline_data_end(inode, pos, len, copied,
1444: folio);
1445:
1446: copied = block_write_end(pos, len, copied, folio);
1447: /*
1448: * it's important to update i_size while still holding folio lock:
1449: * page writeout could otherwise come in and zero beyond i_size.
1450: *
1451: * If FS_IOC_ENABLE_VERITY is running on this inode, then Merkle tree
1452: * blocks are being written past EOF, so skip the i_size update.
1453: */
1454: if (!verity)
1455: i_size_changed = ext4_update_inode_size(inode, pos + copied);
1456: folio_unlock(folio);
1457: folio_put(folio);
1458:
1459: if (old_size < pos && !verity) {
1460: pagecache_isize_extended(inode, old_size, pos);
1461: ext4_zero_partial_blocks(handle, inode, old_size, pos - old_size);
1462: }
1463: /*
1464: * Don't mark the inode dirty under folio lock. First, it unnecessarily
1465: * makes the holding time of folio lock longer. Second, it forces lock
1466: * ordering of folio lock and transaction start for journaling
1467: * filesystems.
1468: */
1469: if (i_size_changed)
1470: ret = ext4_mark_inode_dirty(handle, inode);
1471:
1472: if (pos + len > inode->i_size && !verity && ext4_can_truncate(inode))
1473: /* if we have allocated more blocks and copied
1474: * less. We will have blocks allocated outside
1475: * inode->i_size. So truncate them
1476: */
1477: ext4_orphan_add(handle, inode);
1478:
1479: ret2 = ext4_journal_stop(handle);
1480: if (!ret)
1481: ret = ret2;
1482:
1483: if (pos + len > inode->i_size && !verity) {
1484: ext4_truncate_failed_write(inode);
1485: /*
1486: * If truncate failed early the inode might still be
1487: * on the orphan list; we need to make sure the inode
1488: * is removed from the orphan list in that case.
1489: */
1490: if (inode->i_nlink)
1491: ext4_orphan_del(NULL, inode);
1492: }
1493:
1494: return ret ? ret : copied;
1495: }
SourceFile:fs/ext4/inode.c]
|
| 16/2 |
2026/06/01 10:48 |
llm |
expert |
0m
Model:
Tokens:
input: 29287
output: 34
thoughts: 16
Thoughts: Okay, here's my take on those thoughts, framed as an expert's internal monologue:
**File System Write Completion: A Familiar Dance**
Right, `ext4_write_end`... that's the final piece of the write puzzle for ext4, isn't it? My mind immediately jumps to `block_write_end`. Of course, it's pretty clear that `ext4_write_end` is just acting as a wrapper, a specific implementation detail for the ext4 file system. It's delegating the real heavy lifting to the more general `block_write_end`. That's how it should be. Maintain the separation of concerns. The ext4 layer likely handles any file-system specific metadata updates, journal writes, and the like, but the fundamental block-level I/O completion logic? That belongs in the generic `block_write_end`. No need to reinvent the wheel. I'd need to dig in to confirm, but I'd guess that `block_write_end` is responsible for properly updating the page cache, possibly managing writeback, and potentially setting up any necessary dirty page accounting. I'd expect it to handle things like completing the bio and calling the appropriate completion routines. All standard operating procedure. A well-designed, modular system.
|
| 17/2 |
2026/06/01 10:48 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/buffer.c Name:block_write_end]
Results: map[SourceCode:2265: int block_write_end(loff_t pos, unsigned len, unsigned copied,
2266: struct folio *folio)
2267: {
2268: size_t start = pos - folio_pos(folio);
2269:
2270: if (unlikely(copied < len)) {
2271: /*
2272: * The buffers that were written will now be uptodate, so
2273: * we don't have to worry about a read_folio reading them
2274: * and overwriting a partial write. However if we have
2275: * encountered a short write and only partially written
2276: * into a buffer, it will not be marked uptodate, so a
2277: * read_folio might come in and destroy our partial write.
2278: *
2279: * Do the simplest thing, and just treat any short write to a
2280: * non uptodate folio as a zero-length write, and force the
2281: * caller to redo the whole thing.
2282: */
2283: if (!folio_test_uptodate(folio))
2284: copied = 0;
2285:
2286: folio_zero_new_buffers(folio, start+copied, start+len);
2287: }
2288: flush_dcache_folio(folio);
2289:
2290: /* This could be a short (even 0-length) commit */
2291: block_commit_write(folio, start, start + copied);
2292:
2293: return copied;
2294: }
SourceFile:fs/buffer.c]
|
| 18/2 |
2026/06/01 10:48 |
llm |
expert |
0m
Model:
Tokens:
input: 30095
output: 34
thoughts: 1212
Thoughts: **Unraveling a Potential Uninitialized Memory Write in ext4**
Okay, let's break this down. I'm looking at a potential issue in `ext4`'s block write path. The crux seems to be in the interaction between `block_write_end`, `ext4_block_write_begin`, and how buffers are handled, especially when there's a partial write or a failure in `copy_folio_from_iter_atomic`.
My initial thought is that in `block_write_end`, if the `copied` amount is less than the intended `len`, and the folio isn't uptodate, `copied` gets reset to 0. Then, `folio_zero_new_buffers` is called. The odd thing is that the function only zeros buffers if they are considered "new" which in `ext4_block_write_begin` clears the `buffer_new` flag, but then `get_block` is called which could set it. This might be a hint.
But, if the buffer was already mapped and *not* new. If the buffer is not uptodate, then it's read from disk. But wait! If the requested write region doesn't overlap the entire block, the block isn't read from disk and remains not uptodate. That's a key observation.
Now, `generic_perform_write` does a `copy_folio_from_iter_atomic`. If this fails (returns 0), `copied` becomes 0. `block_write_end` gets called with `copied = 0`. The folio is still not uptodate, so `copied` remains 0. Then `folio_zero_new_buffers` is called, but because the buffer wasn't new, it does nothing! Then `block_commit_write` doesn't mark the buffer uptodate. `ext4_write_end` returns 0.
Back in `generic_perform_write`, if the `status` is 0 (meaning the write seemingly failed), and `copied` is also 0, it calls `fault_in_iov_iter_readable`. Here's the potential loop! If `fault_in_iov_iter_readable` *succeeds*, it loops back to the beginning! So `generic_perform_write` might be trying again and again, but the buffer state may never change!
What if `generic_perform_write` *always* returns 0? And if `fault_in_iov_iter_readable` does return something, we break.
The question then becomes: How does uninitialized memory end up on disk? The stack trace shows the writeback path: `ext4_bio_write_folio`, `mpage_submit_folio`, etc. So the folio *is* being written back! But, if `copied == 0`, `block_commit_write` *doesn't* mark the buffer dirty! That's a crucial piece. I need to check `block_commit_write` very carefully, because there seems to be a disconnect between the buffer's state (not uptodate, not dirty) and it being written to disk.
|
| 19/2 |
2026/06/01 10:48 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/buffer.c Name:block_commit_write]
Results: map[SourceCode:2195: void block_commit_write(struct folio *folio, size_t from, size_t to)
2196: {
2197: size_t block_start, block_end;
2198: bool partial = false;
2199: unsigned blocksize;
2200: struct buffer_head *bh, *head;
2201:
2202: bh = head = folio_buffers(folio);
2203: if (!bh)
2204: return;
2205: blocksize = bh->b_size;
2206:
2207: block_start = 0;
2208: do {
2209: block_end = block_start + blocksize;
2210: if (block_end <= from || block_start >= to) {
2211: if (!buffer_uptodate(bh))
2212: partial = true;
2213: } else {
2214: set_buffer_uptodate(bh);
2215: mark_buffer_dirty(bh);
2216: }
2217: if (buffer_new(bh))
2218: clear_buffer_new(bh);
2219:
2220: block_start = block_end;
2221: bh = bh->b_this_page;
2222: } while (bh != head);
2223:
2224: /*
2225: * If this is a partial write which happened to make all buffers
2226: * uptodate then we can optimize away a bogus read_folio() for
2227: * the next read(). Here we 'discover' whether the folio went
2228: * uptodate as a result of this (potentially partial) write.
2229: */
2230: if (!partial)
2231: folio_mark_uptodate(folio);
2232: }
SourceFile:fs/buffer.c]
|
| 20/2 |
2026/06/01 10:48 |
llm |
expert |
0m
Model:
Tokens:
input: 32584
output: 41
thoughts: 729
Thoughts: **Analyzing ext4 Write Path with a Focus on Buffer Dirtying**
Okay, let's break this down. My initial thought was that if `from` equals `to`, the buffer-related functions `set_buffer_uptodate` and `mark_buffer_dirty` would *never* be called. This seemed to imply the buffer wouldn't be marked dirty. That seemed wrong. I had to look further.
Then I recalled that `ext4_write_end` extends the file using `pagecache_isize_extended` and potentially zeroes partial blocks, but I was tripped up thinking about the meaning of `pos`. It's the *start* of the write, which is relevant for the check `pos > old_size`. Regardless of that, `ext4_write_end` *does* call `ext4_mark_inode_dirty`, which is important for the overall I/O flow, but does not mark the folio dirty if `copied == 0`.
The next point I pondered: What happens if `copied` is greater than zero but less than the intended length of the write (`len`)? If `copied < len`, `block_write_end` potentially sets `copied` back to zero if the folio isn't uptodate. That happens because of the `folio_test_uptodate` call. So, effectively the write is no-op'd. Then, `block_commit_write` gets called with a zero-length write, from `from` to `from + 0`, which means the buffer isn't marked dirty. But, the real question that comes to mind is: If the folio *is* uptodate, doesn't that mean there's no uninitialized memory? If the folio is uptodate, and `copied` remains greater than zero, then `block_commit_write` *does* mark the buffer dirty. That makes sense.
But then, the most likely path that I missed is the `ext4_should_dioread_nolock(inode)` check. If this is true, then `ext4_block_write_begin` is called with `ext4_get_block_unwritten`. This is where it gets interesting because `ext4_get_block_unwritten` allocates an unwritten extent. An unwritten buffer implies `buffer_unwritten(bh)` is true. If this is true, that implies `ext4_block_write_begin` does *not* read the buffer from disk. This is because the check in the code:
```c
if (!buffer_uptodate(bh) && !buffer_delay(bh) &&
!buffer_unwritten(bh) &&
(block_start < from || block_end > to)) {
ext4_read_bh_lock(bh, 0, false);
wait[nr_wait++] = bh;
}
```
... is skipped. Even if the block range is partially within the write range! The `buffer_unwritten` check short-circuits the read. Now I need to check how `buffer_new(bh)` behaves in the presence of unwritten buffers. I'll need to check the exact behavior of `ext4_get_block_unwritten`. This path is crucial for understanding how the ext4 handles new, unwritten data blocks.
|
| 21/2 |
2026/06/01 10:49 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/ext4/inode.c Name:ext4_get_block_unwritten]
Results: map[SourceCode: 930: /*
931: * Get block function used when preparing for buffered write if we require
932: * creating an unwritten extent if blocks haven't been allocated. The extent
933: * will be converted to written after the IO is complete.
934: */
935: int ext4_get_block_unwritten(struct inode *inode, sector_t iblock,
936: struct buffer_head *bh_result, int create)
937: {
938: int ret = 0;
939:
940: ext4_debug("ext4_get_block_unwritten: inode %lu, create flag %d\n",
941: inode->i_ino, create);
942: ret = _ext4_get_block(inode, iblock, bh_result,
943: EXT4_GET_BLOCKS_CREATE_UNWRIT_EXT);
944:
945: /*
946: * If the buffer is marked unwritten, mark it as new to make sure it is
947: * zeroed out correctly in case of partial writes. Otherwise, there is
948: * a chance of stale data getting exposed.
949: */
950: if (ret == 0 && buffer_unwritten(bh_result))
951: set_buffer_new(bh_result);
952:
953: return ret;
954: }
SourceFile:fs/ext4/inode.c]
|
| 22/2 |
2026/06/01 10:49 |
llm |
expert |
0m
Model:
Tokens:
input: 34517
output: 34
thoughts: 882
Thoughts: **Uninitialized Memory Leak in ext4 Write Operations**
Okay, so I'm digging into this `ext4` write path and I've spotted something concerning. It starts with `ext4_get_block_unwritten` setting `buffer_new` on a buffer head (`bh`) if the block is unwritten. Makes sense. Then `ext4_block_write_begin` comes in. It checks if `buffer_new(bh)` is set and, if so, zero-fills the partial blocks *outside* the write range `[from, to)`. That's normal behavior.
But here's the kicker: What if the block *was already* marked as unwritten before `ext4_write_begin`? If it *was* unwritten, then `ext4_block_write_begin` does some checks, and if `buffer_mapped(bh)` is true, it skips calling `get_block`. Then it runs into a `folio_test_uptodate` check. Since the block is also unwritten, it skips `ext4_read_bh_lock`. So, it doesn't read from disk, *and* it doesn't zero any partial blocks!
The real issue is that if the block is already unwritten, mapped, and we *don't* zero parts outside the `[from, to)` range. Those regions remain uninitialized.
Later on, `generic_perform_write` copies the user-space data into the buffer. Then, `block_write_end` gets called. Now, here's where things get interesting. `block_commit_write` marks the buffer uptodate and dirty *if* `block_end > from && block_start < to`. The key is that it does this even if we're only writing a *portion* of the buffer (if len < blocksize), even though the rest of the buffer *remains uninitialized*.
Essentially, we're marking the *entire* block as uptodate and dirty, even though only a part of it has been initialized by `generic_perform_write`! The uninitialized data remains, and that dirty, uptodate block will eventually be written to disk, thus leaking uninitialized memory from the filesystem.
This needs further verification, but it seems there's a potential vulnerability here.
|
| 23/2 |
2026/06/01 10:49 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/buffer.c Name:block_commit_write]
Results: map[SourceCode:2195: void block_commit_write(struct folio *folio, size_t from, size_t to)
2196: {
2197: size_t block_start, block_end;
2198: bool partial = false;
2199: unsigned blocksize;
2200: struct buffer_head *bh, *head;
2201:
2202: bh = head = folio_buffers(folio);
2203: if (!bh)
2204: return;
2205: blocksize = bh->b_size;
2206:
2207: block_start = 0;
2208: do {
2209: block_end = block_start + blocksize;
2210: if (block_end <= from || block_start >= to) {
2211: if (!buffer_uptodate(bh))
2212: partial = true;
2213: } else {
2214: set_buffer_uptodate(bh);
2215: mark_buffer_dirty(bh);
2216: }
2217: if (buffer_new(bh))
2218: clear_buffer_new(bh);
2219:
2220: block_start = block_end;
2221: bh = bh->b_this_page;
2222: } while (bh != head);
2223:
2224: /*
2225: * If this is a partial write which happened to make all buffers
2226: * uptodate then we can optimize away a bogus read_folio() for
2227: * the next read(). Here we 'discover' whether the folio went
2228: * uptodate as a result of this (potentially partial) write.
2229: */
2230: if (!partial)
2231: folio_mark_uptodate(folio);
2232: }
SourceFile:fs/buffer.c]
|
| 24/2 |
2026/06/01 10:49 |
llm |
expert |
0m
Model:
Tokens:
input: 36493
output: 42
thoughts: 1235
Thoughts: **The Uninitialized Memory Bug in ext4: A Deep Dive**
Okay, here's what's running through my head. I'm looking at this ext4 write path, and something doesn't sit right. It starts with this conditional check: `block_end > from && block_start < to`. If that's true, it means we're writing to a partial block. The code then calls `set_buffer_uptodate(bh)` and `mark_buffer_dirty(bh)`. Seems reasonable... but then I consider if the write is smaller than the block size (`len < blocksize`). This means only part of the block is being written to, but `block_commit_write` marks the ENTIRE buffer as uptodate and dirty! That's the first red flag.
Then I double-check the `block_write_end` code, particularly the potential zeroing logic:
```c
if (unlikely(copied < len)) {
if (!folio_test_uptodate(folio))
copied = 0;
folio_zero_new_buffers(folio, start+copied, start+len);
}
```
If `copied == len`, no zeroing happens, which is expected. And `block_commit_write` marks the buffer uptodate.
Next, I go back to `ext4_block_write_begin`. Here's where it gets interesting:
```c
if (!buffer_mapped(bh)) {
...
if (buffer_new(bh)) {
...
if (block_end > to || block_start < from)
folio_zero_segments(folio, to,
block_end,
block_start, from);
continue;
}
}
```
If a buffer isn't mapped, it will call `get_block`. If `get_block` returns a *new*, unwritten buffer (`buffer_new(bh)` is true), the code zeroes the rest of the block. Makes sense β initialize a new block before writing.
But what if the buffer WAS already mapped, but unwritten? In this scenario, `buffer_mapped(bh)` is true, so it skips the `get_block` call. Then, it hits this check:
```c
if (!buffer_uptodate(bh) && !buffer_delay(bh) &&
!buffer_unwritten(bh) &&
(block_start < from || block_end > to)) {
ext4_read_bh_lock(bh, 0, false);
wait[nr_wait++] = bh;
}
```
Here's the crucial part: since `buffer_unwritten(bh)` is true, this section is skipped! No zeroing of the unwritten parts happens.
I'm starting to zero in. Remember at the beginning of the loop of `ext4_block_write_begin`, the code does this:
```c
if (WARN_ON_ONCE(buffer_new(bh)))
clear_buffer_new(bh);
```
So it clears `buffer_new(bh)`. If the buffer was already mapped AND unwritten, it does NOT zero the rest of the block. It also doesn't read it from disk! So, now we have an uninitialized portion of the block. `block_commit_write` then marks the buffer as uptodate and dirty. BANG! We're writing uninitialized memory to disk! That's the bug.
Now, the question is *how* can a buffer be mapped, unwritten, but *not* uptodate? If you read from an unwritten extent, you get zeros (and it's marked uptodate). So that's out.
How does a buffer become mapped and unwritten? The first thing that comes to mind is using `fallocate` for preallocation β it creates unwritten extents. Then, when you write to a page, `ext4_get_block_unwritten` maps the buffer.
The tricky scenario I see now: Imagine writing to the same page twice. The first write maps the block as unwritten (but possibly doesn't zero the rest). The second write *re-uses* the already mapped unwritten buffer. But wait, if `ext4_block_write_begin` DOES zero partial blocks on the first write (which seems like it *should*), then `block_commit_write` marks it as uptodate and there is no problem! If the buffer is uptodate from the first write, the second write will see `folio_test_upt
|
| 25/2 |
2026/06/01 10:49 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/ext4/inode.c Name:ext4_da_get_block_prep]
Results: map[SourceCode:1987: /*
1988: * This is a special get_block_t callback which is used by
1989: * ext4_da_write_begin(). It will either return mapped block or
1990: * reserve space for a single block.
1991: *
1992: * For delayed buffer_head we have BH_Mapped, BH_New, BH_Delay set.
1993: * We also have b_blocknr = -1 and b_bdev initialized properly
1994: *
1995: * For unwritten buffer_head we have BH_Mapped, BH_New, BH_Unwritten set.
1996: * We also have b_blocknr = physicalblock mapping unwritten extent and b_bdev
1997: * initialized properly.
1998: */
1999: int ext4_da_get_block_prep(struct inode *inode, sector_t iblock,
2000: struct buffer_head *bh, int create)
2001: {
2002: struct ext4_map_blocks map;
2003: sector_t invalid_block = ~((sector_t) 0xffff);
2004: int ret = 0;
2005:
2006: BUG_ON(create == 0);
2007: BUG_ON(bh->b_size != inode->i_sb->s_blocksize);
2008:
2009: if (invalid_block < ext4_blocks_count(EXT4_SB(inode->i_sb)->s_es))
2010: invalid_block = ~0;
2011:
2012: map.m_lblk = iblock;
2013: map.m_len = 1;
2014:
2015: /*
2016: * first, we need to know whether the block is allocated already
2017: * preallocated blocks are unmapped but should treated
2018: * the same as allocated blocks.
2019: */
2020: ret = ext4_da_map_blocks(inode, &map);
2021: if (ret < 0)
2022: return ret;
2023:
2024: if (map.m_flags & EXT4_MAP_DELAYED) {
2025: map_bh(bh, inode->i_sb, invalid_block);
2026: set_buffer_new(bh);
2027: set_buffer_delay(bh);
2028: return 0;
2029: }
2030:
2031: map_bh(bh, inode->i_sb, map.m_pblk);
2032: ext4_update_bh_state(bh, map.m_flags);
2033:
2034: if (buffer_unwritten(bh)) {
2035: /* A delayed write to unwritten bh should be marked
2036: * new and mapped. Mapped ensures that we don't do
2037: * get_block multiple times when we write to the same
2038: * offset and new ensures that we do proper zero out
2039: * for partial write.
2040: */
2041: set_buffer_new(bh);
2042: set_buffer_mapped(bh);
2043: }
2044: return 0;
2045: }
SourceFile:fs/ext4/inode.c]
|
| 26/2 |
2026/06/01 10:49 |
llm |
expert |
0m
Model:
Tokens:
input: 39755
output: 40
thoughts: 1591
Thoughts: **Debugging an Ext4 Write with KMSAN**
Okay, so I'm looking at this ext4 write issue, and here's my thought process. Initially, I was thinking it's related to `ext4_da_get_block_prep` and how it handles unwritten blocks. Specifically, whether `buffer_new(bh)` and `buffer_mapped(bh)` are set correctly. But then, the stack trace points to `ext4_da_write_begin` calling `ext4_write_begin`. `ext4_nonda_switch` causes the code to use `ext4_write_begin` instead of `ext4_da_get_block_prep`, which uses either `ext4_get_block` or `ext4_get_block_unwritten`. The latter sets `buffer_new(bh)`, and then `ext4_block_write_begin` is supposed to zero any partial blocks.
The core of my confusion is where this bug is actually surfacing.
I'm examining a reproducer that's using `dioread_lock` and `test_dummy_encryption`. It's doing `pwritev2` with specific offsets and lengths. The buffer is mapped in user space, but there's a problem: it appears only the first byte is initialized. The user code looks like this:
```c
*(uint64_t*)0x2000000001c0 = 0x200000000080;
memset((void*)0x200000000080, 255, 1);
*(uint64_t*)0x2000000001c8 = 0xfdef;
```
My initial thought was that an uninitialized user buffer was being read by `copy_from_user`. But then I realized KMSAN would catch that, right? It _should_ flag uninitialized memory copied from user space. I remember that KMSAN tracks uninitialized memory, which caused me to dive into the documentation, specifically: "KMSAN does not track uninitialized values in userspace. When a buffer is copied from userspace, KMSAN marks it as initialized." So, KMSAN is not the source of our problem, because the kernel assumes that user memory is initialized.
The KMSAN report is the key. The report says the uninitialized memory is coming from the FOLIO ALLOCATION, not the user buffer! This means the folio was allocated, but part of it wasn't initialized by `copy_from_user` and wasn't zeroed by `ext4_block_write_begin`. But why didn't `copy_from_user` initialize it?
Was the `copy_from_user` call failing? The user buffer is mapped. The mmap call uses `MAP_FIXED` so the buffer should be fully mapped. It looks like:
```c
syscall(__NR_mmap, /*addr=*/0x200000000000ul, /*len=*/0x1000000ul, /*prot=PROT_WRITE|PROT_READ|PROT_EXEC*/7ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul);
```
So `copy_from_user` *should* copy the data. It seems like the issue is related to the amount of data being copied, since it has this structure:
```c
copied = copy_folio_from_iter_atomic(folio, offset, bytes, i);
```
If the entire `bytes` portion is copied, the `[offset, offset + bytes)` part is initialized. What about the rest of the folio? `ext4_block_write_begin` should zero it if it's a new block. If it's *not* a new block, the data should be read from disk first.
The question then is, what happens if `ext4_block_write_begin` *thinks* it's not a new block, but it's *also* not read from disk? Time to re-examine `ext4_block_write_begin` again.
|
| 27/2 |
2026/06/01 10:49 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/ext4/inode.c Name:ext4_block_write_begin]
Results: map[SourceCode:1155: int ext4_block_write_begin(handle_t *handle, struct folio *folio,
1156: loff_t pos, unsigned len,
1157: get_block_t *get_block)
1158: {
1159: unsigned int from = offset_in_folio(folio, pos);
1160: unsigned to = from + len;
1161: struct inode *inode = folio->mapping->host;
1162: unsigned block_start, block_end;
1163: sector_t block;
1164: int err = 0;
1165: unsigned int blocksize = i_blocksize(inode);
1166: struct buffer_head *bh, *head, *wait[2];
1167: int nr_wait = 0;
1168: int i;
1169: bool should_journal_data = ext4_should_journal_data(inode);
1170:
1171: BUG_ON(!folio_test_locked(folio));
1172: BUG_ON(to > folio_size(folio));
1173: BUG_ON(from > to);
1174: WARN_ON_ONCE(blocksize > folio_size(folio));
1175:
1176: head = folio_buffers(folio);
1177: if (!head)
1178: head = create_empty_buffers(folio, blocksize, 0);
1179: block = EXT4_PG_TO_LBLK(inode, folio->index);
1180:
1181: for (bh = head, block_start = 0; bh != head || !block_start;
1182: block++, block_start = block_end, bh = bh->b_this_page) {
1183: block_end = block_start + blocksize;
1184: if (block_end <= from || block_start >= to) {
1185: if (folio_test_uptodate(folio)) {
1186: set_buffer_uptodate(bh);
1187: }
1188: continue;
1189: }
1190: if (WARN_ON_ONCE(buffer_new(bh)))
1191: clear_buffer_new(bh);
1192: if (!buffer_mapped(bh)) {
1193: WARN_ON(bh->b_size != blocksize);
1194: err = ext4_journal_ensure_extent_credits(handle, inode);
1195: if (!err)
1196: err = get_block(inode, block, bh, 1);
1197: if (err)
1198: break;
1199: if (buffer_new(bh)) {
1200: /*
1201: * We may be zeroing partial buffers or all new
1202: * buffers in case of failure. Prepare JBD2 for
1203: * that.
1204: */
1205: if (should_journal_data)
1206: do_journal_get_write_access(handle,
1207: inode, bh);
1208: if (folio_test_uptodate(folio)) {
1209: /*
1210: * Unlike __block_write_begin() we leave
1211: * dirtying of new uptodate buffers to
1212: * ->write_end() time or
1213: * folio_zero_new_buffers().
1214: */
1215: set_buffer_uptodate(bh);
1216: continue;
1217: }
1218: if (block_end > to || block_start < from)
1219: folio_zero_segments(folio, to,
1220: block_end,
1221: block_start, from);
1222: continue;
1223: }
1224: }
1225: if (folio_test_uptodate(folio)) {
1226: set_buffer_uptodate(bh);
1227: continue;
1228: }
1229: if (!buffer_uptodate(bh) && !buffer_delay(bh) &&
1230: !buffer_unwritten(bh) &&
1231: (block_start < from || block_end > to)) {
1232: ext4_read_bh_lock(bh, 0, false);
1233: wait[nr_wait++] = bh;
1234: }
1235: }
1236: /*
1237: * If we issued read requests, let them complete.
1238: */
1239: for (i = 0; i < nr_wait; i++) {
1240: wait_on_buffer(wait[i]);
1241: if (!buffer_uptodate(wait[i]))
1242: err = -EIO;
1243: }
1244: if (unlikely(err)) {
1245: if (should_journal_data)
1246: ext4_journalled_zero_new_buffers(handle, inode, folio,
1247: from, to);
1248: else
1249: folio_zero_new_buffers(folio, from, to);
1250: } else if (fscrypt_inode_uses_fs_layer_crypto(inode)) {
1251: for (i = 0; i < nr_wait; i++) {
1252: int err2;
1253:
1254: err2 = fscrypt_decrypt_pagecache_blocks(folio,
1255: blocksize, bh_offset(wait[i]));
1256: if (err2) {
1257: clear_buffer_uptodate(wait[i]);
1258: err = err2;
1259: }
1260: }
1261: }
1262:
1263: return err;
1264: }
SourceFile:fs/ext4/inode.c]
|
| 28/2 |
2026/06/01 10:49 |
llm |
expert |
0m
Model:
Tokens:
input: 44041
output: 40
thoughts: 1695
Thoughts: **Analyzing a Potential KMSAN Vulnerability in Ext4 Write Operations**
Okay, let's break this down. My initial thought process is centered around how `ext4` handles buffer states during write operations, particularly in scenarios where data is partially written to a block. If a buffer is NOT uptodate, not delayed, and not unwritten, and a portion of the block is being written, then `ext4_read_bh_lock` gets called. This reads the block from disk, initializing it. However, if the entire buffer falls *within* the write region (from to), then no read from disk is supposed to happen. Instead, `generic_perform_write` copies data from userspace, and the entire buffer should get initialized.
But, if `copy_from_user` fails, the write operation continues to `block_write_end`. The buffer isn't marked as uptodate (because `copied < len` and `folio_test_uptodate(folio)` is false), and `folio_zero_new_buffers` should zero the buffer if it is new. Since buffer_new is false, this does NOT happen. The buffer is NOT marked as uptodate, and is NOT dirty. The write goes on. If `fault_in_iov_iter_readable` fails later, then it's a -EFAULT.
The code retries if `fault_in_iov_iter_readable` succeeds. The failed `copy_from_user` means the buffer remains uninitialized and, crucially, is *not* marked dirty. Thus, it should *not* be written back to disk.
But what happens if the write is *smaller* than the block size? In this case, there's a *read* from disk via `ext4_read_bh_lock`, so that initializes the *entire* block to disk. BUT, if the buffer is *unwritten* (that is, `buffer_unwritten(bh)` is true), the `ext4_read_bh_lock` is skipped. The buffer is NOT initialized, but the *parts* outside the write region (`[from, to)`) are untouched and remain potentially uninitialized.
Now, `generic_perform_write` will still copy the data, then `block_commit_write` is called. Because `copied == len`, the buffer IS marked uptodate and dirty, even though the unwritten data is outside of the write region. Crucially, `block_commit_write` *always* marks the buffer as uptodate and dirty, if the write does *not* cover the entire block. This means the *uninitialized* parts of the buffer *will* be written to disk.
The issue arises when considering *encrypted* data. If the block contains uninitialized data and is written due to this logic, it becomes encrypted garbage on disk β the KMSAN bug!
Now, how can a buffer be simultaneously mapped, unwritten, *not* uptodate, and *not* new? `ext4_da_write_begin` calls `ext4_da_get_block_prep`, which sets `buffer_new` and `buffer_mapped` for unwritten blocks. Then `ext4_da_write_begin` calls `ext4_block_write_begin`. Here, `buffer_new` gets *cleared* at the beginning of the loop via `WARN_ON_ONCE(buffer_new(bh))`, printing a warning. Wait, no. `ext4_block_write_begin` clears it, but the critical point is that the `get_block` function is called *inside* `ext4_block_write_begin`. `ext4_da_get_block_prep` is passed in as `get_block`. `get_block` is the function that actually *sets* `buffer_new(bh)`! So it's true *after* `get_block`! So why is this a bug? It calls `folio_zero_segments`, which *should* zero the parts of the block not being written!
Therefore, there should *not* be any uninitialized memory after the `get_block` call since that partial block zeroes. Then why is there uninitialized memory at all? I need to rethink this, I missed something fundamental here!
|
| 29/2 |
2026/06/01 10:50 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/ext4/inode.c Name:ext4_da_write_begin]
Results: map[SourceCode:3105: static int ext4_da_write_begin(const struct kiocb *iocb,
3106: struct address_space *mapping,
3107: loff_t pos, unsigned len,
3108: struct folio **foliop, void **fsdata)
3109: {
3110: int ret, retries = 0;
3111: struct folio *folio;
3112: pgoff_t index;
3113: struct inode *inode = mapping->host;
3114:
3115: ret = ext4_emergency_state(inode->i_sb);
3116: if (unlikely(ret))
3117: return ret;
3118:
3119: index = pos >> PAGE_SHIFT;
3120:
3121: if (ext4_nonda_switch(inode->i_sb) || ext4_verity_in_progress(inode)) {
3122: *fsdata = (void *)FALL_BACK_TO_NONDELALLOC;
3123: return ext4_write_begin(iocb, mapping, pos,
3124: len, foliop, fsdata);
3125: }
3126: *fsdata = (void *)0;
3127: trace_ext4_da_write_begin(inode, pos, len);
3128:
3129: if (ext4_test_inode_state(inode, EXT4_STATE_MAY_INLINE_DATA)) {
3130: ret = ext4_generic_write_inline_data(mapping, inode, pos, len,
3131: foliop, fsdata, true);
3132: if (ret < 0)
3133: return ret;
3134: if (ret == 1)
3135: return 0;
3136: }
3137:
3138: retry:
3139: folio = write_begin_get_folio(iocb, mapping, index, len);
3140: if (IS_ERR(folio))
3141: return PTR_ERR(folio);
3142:
3143: if (len > folio_next_pos(folio) - pos)
3144: len = folio_next_pos(folio) - pos;
3145:
3146: ret = ext4_block_write_begin(NULL, folio, pos, len,
3147: ext4_da_get_block_prep);
3148: if (ret < 0) {
3149: folio_unlock(folio);
3150: folio_put(folio);
3151: /*
3152: * ext4_block_write_begin may have instantiated a few blocks
3153: * outside i_size. Trim these off again. Don't need
3154: * i_size_read because we hold inode lock.
3155: */
3156: if (pos + len > inode->i_size)
3157: ext4_truncate_failed_write(inode);
3158:
3159: if (ret == -ENOSPC &&
3160: ext4_should_retry_alloc(inode->i_sb, &retries))
3161: goto retry;
3162: return ret;
3163: }
3164:
3165: *foliop = folio;
3166: return ret;
3167: }
SourceFile:fs/ext4/inode.c]
|
| 30/2 |
2026/06/01 10:50 |
llm |
expert |
0m
Model:
Tokens:
input: 47689
output: 35
thoughts: 1674
Thoughts: **Unraveling the Ext4 Partial Block Zeroing Mystery**
Okay, let's break this down. The stack trace shows `ext4_da_write_begin` falling back to `ext4_write_begin`. This happens because either `ext4_nonda_switch` or `ext4_verity_in_progress` is true, which is triggered by the reproducer's mount options: `dioread_lock` and `test_dummy_encryption`. So, under these specific conditions, we're hitting `ext4_write_begin`.
Now, within `ext4_write_begin`, the code uses `ext4_get_block_unwritten` (due to `ext4_should_dioread_nolock` being true). This function sets `buffer_new(bh)` if the block is unwritten. Consequently, `ext4_block_write_begin` then zeroes partial blocks using `folio_zero_segments`. That makes sense. But...
The core of the problem lies in *retries*. What if the buffer is *already* mapped and unwritten *before* the first `ext4_write_begin` call? In this case, `buffer_mapped(bh)` is true, meaning `get_block` is skipped. If `get_block` is skipped, then `buffer_new(bh)` remains false. Because `buffer_unwritten(bh)` is true, the `ext4_read_bh_lock` is also skipped. And since `buffer_new(bh)` is false, *zeroing of partial blocks is also skipped*!
This leads to the crucial scenario: `generic_perform_write` does a copy of `[from, to)`. If it *fails* partway through the `copy_from_user` call, it calls `ext4_write_end`, which returns a zero on the first run. `generic_perform_write` retries. The problem is that on retry, we're *already* mapped and unwritten. The prior `ext4_write_begin` mapped and set the `buffer_unwritten(bh)` flag. Crucially, `ext4_write_begin` does NOT reset `buffer_mapped(bh)` or `buffer_unwritten(bh)` on failure.
During the *retry*, now `buffer_mapped(bh)` is TRUE, but `buffer_new(bh)` is *cleared* at the start of `ext4_block_write_begin` loop. This is critical:
```c
if (WARN_ON_ONCE(buffer_new(bh)))
clear_buffer_new(bh);
```
Thus, we skip `get_block` again. We skip `ext4_read_bh_lock` because `buffer_unwritten(bh)` is true. And we *also* skip the zeroing of partial blocks, because `buffer_new(bh)` is FALSE at this time. So those blocks *are never* zeroed.
If, and this is the crux, *this* time `copy_from_user` succeeds, then `block_commit_write` marks the buffer as uptodate and dirty. And the uninitialized memory now *lands* on disk!
But wait, I should also note. On the first try, if the buffer was *new*, `ext4_block_write_begin` DID zero the partial blocks, using `folio_zero_segments`. So on that first try, those regions *are* correctly zeroed. So, why are we seeing uninitialized memory? The second time the buffer is already mapped, and the zeroing does not occur.
So, the issue isn't the *initial* write, but the *retried* write where the buffer is already mapped, where partial blocks are skipped and thus are not zeroed. This means the regions outside the bounds of the successful copy from user are not zeroed. So this is a bug, but I'm unclear what is in the buffer when its not zeroed.
|
| 31/2 |
2026/06/01 10:50 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:mm/filemap.c Name:generic_perform_write]
Results: map[SourceCode:4291: ssize_t generic_perform_write(struct kiocb *iocb, struct iov_iter *i)
4292: {
4293: struct file *file = iocb->ki_filp;
4294: loff_t pos = iocb->ki_pos;
4295: struct address_space *mapping = file->f_mapping;
4296: const struct address_space_operations *a_ops = mapping->a_ops;
4297: size_t chunk = mapping_max_folio_size(mapping);
4298: long status = 0;
4299: ssize_t written = 0;
4300:
4301: do {
4302: struct folio *folio;
4303: size_t offset; /* Offset into folio */
4304: size_t bytes; /* Bytes to write to folio */
4305: size_t copied; /* Bytes copied from user */
4306: void *fsdata = NULL;
4307:
4308: bytes = iov_iter_count(i);
4309: retry:
4310: offset = pos & (chunk - 1);
4311: bytes = min(chunk - offset, bytes);
4312: balance_dirty_pages_ratelimited(mapping);
4313:
4314: if (fatal_signal_pending(current)) {
4315: status = -EINTR;
4316: break;
4317: }
4318:
4319: status = a_ops->write_begin(iocb, mapping, pos, bytes,
4320: &folio, &fsdata);
4321: if (unlikely(status < 0))
4322: break;
4323:
4324: offset = offset_in_folio(folio, pos);
4325: if (bytes > folio_size(folio) - offset)
4326: bytes = folio_size(folio) - offset;
4327:
4328: if (mapping_writably_mapped(mapping))
4329: flush_dcache_folio(folio);
4330:
4331: /*
4332: * Faults here on mmap()s can recurse into arbitrary
4333: * filesystem code. Lots of locks are held that can
4334: * deadlock. Use an atomic copy to avoid deadlocking
4335: * in page fault handling.
4336: */
4337: copied = copy_folio_from_iter_atomic(folio, offset, bytes, i);
4338: flush_dcache_folio(folio);
4339:
4340: status = a_ops->write_end(iocb, mapping, pos, bytes, copied,
4341: folio, fsdata);
4342: if (unlikely(status != copied)) {
4343: iov_iter_revert(i, copied - max(status, 0L));
4344: if (unlikely(status < 0))
4345: break;
4346: }
4347: cond_resched();
4348:
4349: if (unlikely(status == 0)) {
4350: /*
4351: * A short copy made ->write_end() reject the
4352: * thing entirely. Might be memory poisoning
4353: * halfway through, might be a race with munmap,
4354: * might be severe memory pressure.
4355: */
4356: if (chunk > PAGE_SIZE)
4357: chunk /= 2;
4358: if (copied) {
4359: bytes = copied;
4360: goto retry;
4361: }
4362:
4363: /*
4364: * 'folio' is now unlocked and faults on it can be
4365: * handled. Ensure forward progress by trying to
4366: * fault it in now.
4367: */
4368: if (fault_in_iov_iter_readable(i, bytes) == bytes) {
4369: status = -EFAULT;
4370: break;
4371: }
4372: } else {
4373: pos += status;
4374: written += status;
4375: }
4376: } while (iov_iter_count(i));
4377:
4378: if (!written)
4379: return status;
4380: iocb->ki_pos += written;
4381: return written;
4382: }
SourceFile:mm/filemap.c]
|
| 32/2 |
2026/06/01 10:50 |
llm |
expert |
0m
Model:
Tokens:
input: 51595
output: 40
thoughts: 917
Thoughts: **The Uninitialized Data Bug: A Deep Dive**
Okay, so I'm seeing a critical flaw in how this write operation handles partial writes and retries within the ext4 filesystem, and it's leading to uninitialized data on disk. Let's break this down.
The core of the problem stems from this scenario: `generic_perform_write` is called, and a write operation starts with a larger chunk of data (let's say `4096` bytes). It hits a snag (like a page fault during the copy from userspace) and only manages to copy a smaller amount of data before failing (for example, `2048` bytes). The crucial bit is in the retry logic within `generic_perform_write` and how it interacts with `ext4_write_begin`.
Here's where it all unravels:
1. **Initial Write Attempt:** `ext4_write_begin` gets the initial larger request (`4096` bytes), and block allocation happens. The write begins. Because the entire block is uninitialized, the code zeroes the outside of the data range.
2. **Partial Copy and Retry:** The first `copy_folio_from_iter_atomic` fails midway, maybe after writing `2048` bytes. The code retries, but with a smaller `bytes` request. This is the first critical point.
3. **The Shrinking Window:** The retry call to `ext4_write_begin` is now with the smaller `bytes`. The block is *already* allocated. `block_start`, `block_end`, `from`, `to` now become smaller. The portion between the original `to` and the new `to` was not zeroed during the first try because it was inside the `[from, to)` interval, so it wasn't outside. It *should* be zeroed on the second try, but `buffer_new(bh)` is now FALSE, so this does NOT happen. The code then copies data up to the *new* `to`.
4. **Marking Up-to-Date and Dirty:** Here's the kicker! `block_commit_write` marks the block as *uptodate* and *dirty*, even though the data between the original `to` and the new `to` remains uninitialized. This effectively lies to the system, claiming the block has valid data. The uninitialized portion is essentially ignored.
5. **Disk Write with Garbage:** The filesystem writes the *uptodate* and *dirty* block to disk. And the uninitialized data is written to the disk! This is the core of the bug.
Tracing the logic confirms the flow of the problem. A large write request, followed by a partial copy (e.g. page fault) results in a smaller write request. This means the block allocation is already done, and so `buffer_new(bh)` is not set. The code does NOT zero the data on subsequent writes where `buffer_new(bh)` is false. This leaves data uninitialized, even though the filesystem *believes* the block is valid and *uptodate*. That's where it goes wrong.
|
| 33/2 |
2026/06/01 10:50 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/ext4/inode.c Name:ext4_block_write_begin]
Results: map[SourceCode:1155: int ext4_block_write_begin(handle_t *handle, struct folio *folio,
1156: loff_t pos, unsigned len,
1157: get_block_t *get_block)
1158: {
1159: unsigned int from = offset_in_folio(folio, pos);
1160: unsigned to = from + len;
1161: struct inode *inode = folio->mapping->host;
1162: unsigned block_start, block_end;
1163: sector_t block;
1164: int err = 0;
1165: unsigned int blocksize = i_blocksize(inode);
1166: struct buffer_head *bh, *head, *wait[2];
1167: int nr_wait = 0;
1168: int i;
1169: bool should_journal_data = ext4_should_journal_data(inode);
1170:
1171: BUG_ON(!folio_test_locked(folio));
1172: BUG_ON(to > folio_size(folio));
1173: BUG_ON(from > to);
1174: WARN_ON_ONCE(blocksize > folio_size(folio));
1175:
1176: head = folio_buffers(folio);
1177: if (!head)
1178: head = create_empty_buffers(folio, blocksize, 0);
1179: block = EXT4_PG_TO_LBLK(inode, folio->index);
1180:
1181: for (bh = head, block_start = 0; bh != head || !block_start;
1182: block++, block_start = block_end, bh = bh->b_this_page) {
1183: block_end = block_start + blocksize;
1184: if (block_end <= from || block_start >= to) {
1185: if (folio_test_uptodate(folio)) {
1186: set_buffer_uptodate(bh);
1187: }
1188: continue;
1189: }
1190: if (WARN_ON_ONCE(buffer_new(bh)))
1191: clear_buffer_new(bh);
1192: if (!buffer_mapped(bh)) {
1193: WARN_ON(bh->b_size != blocksize);
1194: err = ext4_journal_ensure_extent_credits(handle, inode);
1195: if (!err)
1196: err = get_block(inode, block, bh, 1);
1197: if (err)
1198: break;
1199: if (buffer_new(bh)) {
1200: /*
1201: * We may be zeroing partial buffers or all new
1202: * buffers in case of failure. Prepare JBD2 for
1203: * that.
1204: */
1205: if (should_journal_data)
1206: do_journal_get_write_access(handle,
1207: inode, bh);
1208: if (folio_test_uptodate(folio)) {
1209: /*
1210: * Unlike __block_write_begin() we leave
1211: * dirtying of new uptodate buffers to
1212: * ->write_end() time or
1213: * folio_zero_new_buffers().
1214: */
1215: set_buffer_uptodate(bh);
1216: continue;
1217: }
1218: if (block_end > to || block_start < from)
1219: folio_zero_segments(folio, to,
1220: block_end,
1221: block_start, from);
1222: continue;
1223: }
1224: }
1225: if (folio_test_uptodate(folio)) {
1226: set_buffer_uptodate(bh);
1227: continue;
1228: }
1229: if (!buffer_uptodate(bh) && !buffer_delay(bh) &&
1230: !buffer_unwritten(bh) &&
1231: (block_start < from || block_end > to)) {
1232: ext4_read_bh_lock(bh, 0, false);
1233: wait[nr_wait++] = bh;
1234: }
1235: }
1236: /*
1237: * If we issued read requests, let them complete.
1238: */
1239: for (i = 0; i < nr_wait; i++) {
1240: wait_on_buffer(wait[i]);
1241: if (!buffer_uptodate(wait[i]))
1242: err = -EIO;
1243: }
1244: if (unlikely(err)) {
1245: if (should_journal_data)
1246: ext4_journalled_zero_new_buffers(handle, inode, folio,
1247: from, to);
1248: else
1249: folio_zero_new_buffers(folio, from, to);
1250: } else if (fscrypt_inode_uses_fs_layer_crypto(inode)) {
1251: for (i = 0; i < nr_wait; i++) {
1252: int err2;
1253:
1254: err2 = fscrypt_decrypt_pagecache_blocks(folio,
1255: blocksize, bh_offset(wait[i]));
1256: if (err2) {
1257: clear_buffer_uptodate(wait[i]);
1258: err = err2;
1259: }
1260: }
1261: }
1262:
1263: return err;
1264: }
SourceFile:fs/ext4/inode.c]
|
| 34/2 |
2026/06/01 10:50 |
llm |
expert |
0m
Model:
Tokens:
input: 54939
output: 36
thoughts: 158
Thoughts: **My Eureka Moment (and a Quick Check)**
Okay, let me trace this through. So, `get_block` is calling `buffer_new(bh)`, that makes sense. And now I see it, `ext4_block_write_begin` *doesn't* clear that flag after the `get_block` call. It only resets it at the very start of the loop, before getting the block! So that means, when `ext4_block_write_begin` returns, `buffer_new(bh)` *is* still set! That's... interesting.
Now, `block_write_end` gets called, and *it* calls `folio_zero_new_buffers`. Aha! *That's* where the magic happens. If `folio_zero_new_buffers` zeroes the buffer, then we don't have uninitialized memory anymore! The buffer gets cleared by `folio_zero_new_buffers`.
Right, let me just double-check that `folio_zero_new_buffers` is actually doing what I think it is. Just to be completely sure.
|
| 35/2 |
2026/06/01 10:50 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/buffer.c Name:folio_zero_new_buffers]
Results: map[SourceCode:1996: /*
1997: * If a folio has any new buffers, zero them out here, and mark them uptodate
1998: * and dirty so they'll be written out (in order to prevent uninitialised
1999: * block data from leaking). And clear the new bit.
2000: */
2001: void folio_zero_new_buffers(struct folio *folio, size_t from, size_t to)
2002: {
2003: size_t block_start, block_end;
2004: struct buffer_head *head, *bh;
2005:
2006: BUG_ON(!folio_test_locked(folio));
2007: head = folio_buffers(folio);
2008: if (!head)
2009: return;
2010:
2011: bh = head;
2012: block_start = 0;
2013: do {
2014: block_end = block_start + bh->b_size;
2015:
2016: if (buffer_new(bh)) {
2017: if (block_end > from && block_start < to) {
2018: if (!folio_test_uptodate(folio)) {
2019: size_t start, xend;
2020:
2021: start = max(from, block_start);
2022: xend = min(to, block_end);
2023:
2024: folio_zero_segment(folio, start, xend);
2025: set_buffer_uptodate(bh);
2026: }
2027:
2028: clear_buffer_new(bh);
2029: mark_buffer_dirty(bh);
2030: }
2031: }
2032:
2033: block_start = block_end;
2034: bh = bh->b_this_page;
2035: } while (bh != head);
2036: }
SourceFile:fs/buffer.c]
|
| 36/2 |
2026/06/01 10:51 |
llm |
expert |
0m
Model:
Tokens:
input: 55971
output: 40
thoughts: 1856
Thoughts: **Unraveling Potential Uninitialized Memory in Ext4 Writes**
Okay, let's break this down. My initial thought was about how `folio_zero_new_buffers` handles zeroing in the context of `block_write_end`. Specifically, I was tracing the scenario where it's called (or not called) and what that implies for buffer state. The crux of the issue boils down to ensuring the entire block is fully initialized, not just the part we're writing to.
Initially, I see that if `copied` in `block_write_end` is zero, we trigger a full zeroing from `start` to `start + len` using `folio_zero_new_buffers`. This combined with prior zeroing in `ext4_block_write_begin` suggests the whole block is initialized. The fact that `folio_zero_new_buffers` also sets `buffer_uptodate` and clears `buffer_new` solidifies this idea β itβs a full initialization. Subsequent writes then leverage this "uptodate" status, skipping the read/zeroing if `buffer_uptodate` is set.
However, if `copied` equals `len` within `block_write_end`, `folio_zero_new_buffers` is bypassed. Here, `block_commit_write` marks the block `uptodate` and dirty after writing, and the partial blocks are zeroed by `ext4_block_write_begin`. This looks safe, as well, as long as `ext4_block_write_begin` correctly handles the boundaries.
The critical insight arises when I start questioning scenarios where `ext4_block_write_begin` *doesn't* zero partial blocks. This happens when `buffer_new(bh)` is false, meaning the buffer was already mapped and *unwritten* prior to the write. In this case, `ext4_block_write_begin` skips the zeroing of partial blocks, assuming the data on disk is good, so does not need to read from the on-disk data. This is where uninitialized memory *could* arise β unwritten extents pre-allocated, but not initialized.
The crucial link is `fallocate`. If I use `fallocate` to pre-allocate space, it creates unwritten extents. When I then write to those extents, the buffers will not be mapped in the page cache so `buffer_mapped` will be `FALSE` on the first write. This means that a call to `get_block` is issued, which in turn calls `ext4_get_block_unwritten` which *does* set `buffer_new`.
Therefore, the only way a buffer is mapped, unwritten, and *doesn't* have `buffer_new` set, is if the buffer already has data on-disk. Since this write path assumes there is some data, the data does not need to be zeroed and the `buffer_new` is false.
If the buffer has `buffer_new` set, then `ext4_block_write_begin` will correctly handle zeroing of partial blocks. Even if the data written is less than the blocksize and `folio_zero_new_buffers` is not called, after `block_commit_write`, the partial blocks were either zeroed, or will be assumed to contain data from the pre-written extent. So the whole block is initialized.
In summary, potential uninitialized memory can arise only when pre-allocating using `fallocate`, and writing the buffer for the first time, when the blocks are not zeroed by the write_begin call.
|
| 37/2 |
2026/06/01 10:51 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/ext4/inode.c Name:ext4_da_write_end]
Results: map[SourceCode:3262: static int ext4_da_write_end(const struct kiocb *iocb,
3263: struct address_space *mapping,
3264: loff_t pos, unsigned len, unsigned copied,
3265: struct folio *folio, void *fsdata)
3266: {
3267: struct inode *inode = mapping->host;
3268: int write_mode = (int)(unsigned long)fsdata;
3269:
3270: if (write_mode == FALL_BACK_TO_NONDELALLOC)
3271: return ext4_write_end(iocb, mapping, pos,
3272: len, copied, folio, fsdata);
3273:
3274: trace_ext4_da_write_end(inode, pos, len, copied);
3275:
3276: if (write_mode != CONVERT_INLINE_DATA &&
3277: ext4_test_inode_state(inode, EXT4_STATE_MAY_INLINE_DATA) &&
3278: ext4_has_inline_data(inode))
3279: return ext4_write_inline_data_end(inode, pos, len, copied,
3280: folio);
3281:
3282: if (unlikely(copied < len) && !folio_test_uptodate(folio))
3283: copied = 0;
3284:
3285: return ext4_da_do_write_end(mapping, pos, len, copied, folio);
3286: }
SourceFile:fs/ext4/inode.c]
|
| 38/2 |
2026/06/01 10:51 |
llm |
expert |
0m
Model:
Tokens:
input: 59106
output: 42
thoughts: 81
Thoughts: Here's my summary, as I understand it:
**Digging into ext4's Write Operations**
Okay, so I'm tracing through this write path, specifically focusing on `ext4_da_write_end`. The code snippet in front of me is a key moment:
```c
if (unlikely(copied < len) && !folio_test_uptodate(folio))
copied = 0;
```
Interesting... `ext4_da_write_end` checks if the number of bytes copied is less than the requested length *and* if the folio isn't already up-to-date. If both conditions are true, it effectively resets the `copied` variable to zero. The implication is, if there's been a partial write *and* the folio doesn't contain valid data, the entire write is considered a failure at this point. That makes sense, ensuring data integrity. No incomplete writes with stale data being accepted.
But here's the kicker, and the thing I was initially most interested in: it doesn't call `folio_zero_new_buffers` prior to this check. And that's something that stands out as a potential point of optimization, or at least a behavior to be aware of. I need to keep this in mind as I am trying to figure out how this is supposed to work and what the implications are.
The code then proceeds to call `ext4_da_do_write_end`. I need to follow *that* call to fully understand what happens next. That's where the real meat of the write completion is likely handled, and where the buffer management and possibly the zeroing or other necessary operations might occur. So, to get the full picture, I need to understand that call.
|
| 39/2 |
2026/06/01 10:51 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/ext4/inode.c Name:ext4_da_do_write_end]
Results: map[SourceCode:3192: static int ext4_da_do_write_end(struct address_space *mapping,
3193: loff_t pos, unsigned len, unsigned copied,
3194: struct folio *folio)
3195: {
3196: struct inode *inode = mapping->host;
3197: loff_t old_size = inode->i_size;
3198: bool disksize_changed = false;
3199: loff_t new_i_size, zero_len = 0;
3200: handle_t *handle;
3201:
3202: if (unlikely(!folio_buffers(folio))) {
3203: folio_unlock(folio);
3204: folio_put(folio);
3205: return -EIO;
3206: }
3207: /*
3208: * block_write_end() will mark the inode as dirty with I_DIRTY_PAGES
3209: * flag, which all that's needed to trigger page writeback.
3210: */
3211: copied = block_write_end(pos, len, copied, folio);
3212: new_i_size = pos + copied;
3213:
3214: /*
3215: * It's important to update i_size while still holding folio lock,
3216: * because folio writeout could otherwise come in and zero beyond
3217: * i_size.
3218: *
3219: * Since we are holding inode lock, we are sure i_disksize <=
3220: * i_size. We also know that if i_disksize < i_size, there are
3221: * delalloc writes pending in the range up to i_size. If the end of
3222: * the current write is <= i_size, there's no need to touch
3223: * i_disksize since writeback will push i_disksize up to i_size
3224: * eventually. If the end of the current write is > i_size and
3225: * inside an allocated block which ext4_da_should_update_i_disksize()
3226: * checked, we need to update i_disksize here as certain
3227: * ext4_writepages() paths not allocating blocks and update i_disksize.
3228: */
3229: if (new_i_size > inode->i_size) {
3230: unsigned long end;
3231:
3232: i_size_write(inode, new_i_size);
3233: end = offset_in_folio(folio, new_i_size - 1);
3234: if (copied && ext4_da_should_update_i_disksize(folio, end)) {
3235: ext4_update_i_disksize(inode, new_i_size);
3236: disksize_changed = true;
3237: }
3238: }
3239:
3240: folio_unlock(folio);
3241: folio_put(folio);
3242:
3243: if (pos > old_size) {
3244: pagecache_isize_extended(inode, old_size, pos);
3245: zero_len = pos - old_size;
3246: }
3247:
3248: if (!disksize_changed && !zero_len)
3249: return copied;
3250:
3251: handle = ext4_journal_start(inode, EXT4_HT_INODE, 2);
3252: if (IS_ERR(handle))
3253: return PTR_ERR(handle);
3254: if (zero_len)
3255: ext4_zero_partial_blocks(handle, inode, old_size, zero_len);
3256: ext4_mark_inode_dirty(handle, inode);
3257: ext4_journal_stop(handle);
3258:
3259: return copied;
3260: }
SourceFile:fs/ext4/inode.c]
|
| 40/2 |
2026/06/01 10:51 |
llm |
expert |
0m
Model:
Tokens:
input: 60753
output: 39
thoughts: 6428
Thoughts: **Unraveling the Mystery of Uninitialized Memory in ext4 Writes**
Okay, here's the deal, after some serious head-scratching. It all boils down to how `ext4` handles block writes, especially when dealing with potentially uninitialized memory. `ext4_da_do_write_end` calls `block_write_end`. Within `block_write_end` it does call `folio_zero_new_buffers`, which seems like a good start. However, this is only called in the context where *copied* bytes is less than the *length* provided to be written, and if the folio is *not* uptodate. So, we need to consider several scenarios.
Initially I was worried about whether `folio_zero_new_buffers` was *always* being called, but quickly realized that `ext4_da_get_block_prep` and other conditions can affect whether the buffer is considered "new" and therefore needing zeroing. It becomes clear that when `buffer_new(bh)` is false at the beginning of the `ext4_block_write_begin` process, `folio_zero_new_buffers` is NOT called.
One of the key things is that if the block is *already mapped* and *not* "unwritten," the code *will* call `ext4_read_bh_lock`, meaning the block data is read from disk. This *should* initialize the memory. We have to keep track though, that if the block is "delayed" via `buffer_delay(bh)`, we can't be sure it is initialized.
However, if `buffer_delay(bh)` is TRUE, it skips that read, and the block might remain uninitialized unless it was already uptodate. The state of a delayed block depends on what happened in the previous write. If `copied == len` in the *previous* write, everything is set up right (uptodate and `buffer_new(bh)` cleared). If `copied < len`, `folio_zero_new_buffers` SHOULD zero the buffer in the previous write.
I went down a rabbit hole considering a failure in `generic_perform_write`, but realized that it doesn't crash as such - it either works and gets uptodate, or returns, failing the write.
A major thing I looked at was the case where `len == blocksize` so `folio_zero_segments` is skipped. If the user data *copy* fails then `folio_zero_new_buffers` is still called *after* a partial copy, which should zero everything.
I was getting bogged down by the fact that the code *clears* `buffer_new(bh)` at the beginning of the block write loop. If this is done and no block allocation is done the buffer could remain uninitialized. HOWEVER, that would mean `buffer_mapped(bh)` would need to be TRUE, which is only set when the `get_block` is called. So, in that loop, if there is a *previous* write on the page, the `get_block` is skipped and if the `buffer_delay(bh)` is true, the `ext4_read_bh_lock` call is skipped and the block remains uninit.
There's the tricky situation where the *previous* write didn't fully complete, in which case the `buffer_uptodate(bh)` flag is not set properly! The crucial condition is `block_end > from && block_start < to`. This determines whether the buffer is considered "uptodate" and zeroed. I then realized that since we are writing with the given parameters and using `from = start` and `to = start+len` this *should* always be set correctly. This should be alright!
So, the issue of "uninitialized memory" *should* come from the `write_begin_get_folio` call! When we write with `O_SYNC` is where the folio is written back, that's what triggers the KMSAN report.
Since it uses the `ext4_get_block` which creates a normal (not unwritten) block. The buffer should be mapped and zeroed through `folio_zero_segments` if necessary. If it's *not* a new block, it reads the existing disk data.
So, I had a hard time figuring out when it might *not* read from the disk! If the block is *already* allocated *and* the write covers the *entire* block, and `copy_folio_from_iter_atomic` fails, we have to retry and eventually succeed. The *key* here, however, is that if that *initial* read from disk doesn't fully complete, the data gets faulted into memory and the
|
| 41/2 |
2026/06/01 10:52 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/ext4/inode.c Name:_ext4_get_block]
Results: map[SourceCode: 897: static int _ext4_get_block(struct inode *inode, sector_t iblock,
898: struct buffer_head *bh, int flags)
899: {
900: struct ext4_map_blocks map;
901: int ret = 0;
902:
903: if (ext4_has_inline_data(inode))
904: return -ERANGE;
905:
906: map.m_lblk = iblock;
907: map.m_len = bh->b_size >> inode->i_blkbits;
908:
909: ret = ext4_map_blocks(ext4_journal_current_handle(), inode, &map,
910: flags);
911: if (ret > 0) {
912: map_bh(bh, inode->i_sb, map.m_pblk);
913: ext4_update_bh_state(bh, map.m_flags);
914: bh->b_size = inode->i_sb->s_blocksize * map.m_len;
915: ret = 0;
916: } else if (ret == 0) {
917: /* hole case, need to fill in bh->b_size */
918: bh->b_size = inode->i_sb->s_blocksize * map.m_len;
919: }
920: return ret;
921: }
SourceFile:fs/ext4/inode.c]
|
| 42/2 |
2026/06/01 10:52 |
llm |
expert |
0m
Model:
Tokens:
input: 68696
output: 40
thoughts: 20
Thoughts: Okay, here's my interpretation of that thought process, assuming I'm already deep in the weeds of ext4 internals:
**Delving into Block Retrieval: A Quick Mental Walkthrough**
Alright, so `_ext4_get_block` is kicking off. That's the entry point for getting a block, the workhorse of file system block allocation. The mental checklist here is crucial; understanding the block retrieval process is essential to a high-performance system. The critical link in this case is the interaction with `ext4_update_bh_state`. Now, `ext4_update_bh_state` is being called right after `_ext4_get_block`. I know this means that block header states are most likely being updated, and it is a likely spot for state changes for the filesystem. The specifics of the update are important, is it simply recording that we're accessing this block? Is it marking something dirty? Is it related to journaling? Depending on what it is changing, it will affect I/O performance. This call is going to tell me exactly how the block buffer head is manipulated based on the `_ext4_get_block` request.
|
| 43/2 |
2026/06/01 10:52 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/ext4/inode.c Name:ext4_update_bh_state]
Results: map[SourceCode: 850: /*
851: * Update EXT4_MAP_FLAGS in bh->b_state. For buffer heads attached to pages
852: * we have to be careful as someone else may be manipulating b_state as well.
853: */
854: static void ext4_update_bh_state(struct buffer_head *bh, unsigned long flags)
855: {
856: unsigned long old_state;
857: unsigned long new_state;
858:
859: flags &= EXT4_MAP_FLAGS;
860:
861: /* Dummy buffer_head? Set non-atomically. */
862: if (!bh->b_folio) {
863: bh->b_state = (bh->b_state & ~EXT4_MAP_FLAGS) | flags;
864: return;
865: }
866: /*
867: * Someone else may be modifying b_state. Be careful! This is ugly but
868: * once we get rid of using bh as a container for mapping information
869: * to pass to / from get_block functions, this can go away.
870: */
871: old_state = READ_ONCE(bh->b_state);
872: do {
873: new_state = (old_state & ~EXT4_MAP_FLAGS) | flags;
874: } while (unlikely(!try_cmpxchg(&bh->b_state, &old_state, new_state)));
875: }
SourceFile:fs/ext4/inode.c]
|
| 44/2 |
2026/06/01 10:52 |
llm |
expert |
0m
Model:
Tokens:
input: 69466
output: 39
thoughts: 31
Thoughts: Okay, here's my interpretation of those thoughts, presented as a personal thought process, as requested:
**Delving into EXT4 Block Handling**
Alright, let's see, I'm looking at `ext4_update_bh_state`. I know that function is involved in updating block header state within the EXT4 filesystem, but I need a refresher on the precise mechanism. It looks like it's setting `EXT4_MAP_FLAGS`. That triggers a red flag, though. What exactly do those `EXT4_MAP_FLAGS` represent in this context? I need to understand them fully. Theyβre clearly important, indicating something about the mapping or state of those blocks, and probably influencing how the system interacts with the underlying disk. I need to figure out what those flags mean. Are they related to journaling, allocation, caching, or something more fundamental? I need to consult the documentation and source code related to `EXT4_MAP_FLAGS`. I need the details! Knowing what flags are present will help me understand the implications of this function call.
|
| 45/2 |
2026/06/01 10:52 |
tool |
codesearch-definition-source |
0m
Error:
Args: map[ContextFile:fs/ext4/ext4.h Name:EXT4_MAP_FLAGS]
Results: map[SourceCode: SourceFile:]
|
| 46/2 |
2026/06/01 10:52 |
llm |
expert |
0m
Model:
Tokens:
input: 69780
output: 22
thoughts: 13
Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience:
**Diving into EXT4 Map Flags**
Alright, let's get down to brass tacks. I'm thinking I need to find the definition, or at least understand the context, of these `EXT4_MAP_FLAGS`. That name immediately screams something important about how the EXT4 filesystem structures logical blocks to physical sectors. I'm going to start with a `grep`. It's the most expedient way to quickly search the codebase for where these flags are defined and, more importantly, *used*. I'm anticipating that this will quickly lead me to the core data structures and functions involved in block allocation and mapping. From there, I can start to infer the meaning and implications of these flags within EXT4's internal workings. Let's see what we find. I'm expecting this `grep` will get me started down the right track, and it may well answer my questions right away.
|
| 47/2 |
2026/06/01 10:52 |
tool |
grepper |
0m
Args: map[Expression:#define EXT4_MAP_FLAGS]
Results: map[Output:fs/ext4/ext4.h=211=struct ext4_allocation_request {
--
fs/ext4/ext4.h-253-#define EXT4_MAP_QUERY_LAST_IN_LEAF BIT(BH_BITMAP_UPTODATE + 1)
fs/ext4/ext4.h:254:#define EXT4_MAP_FLAGS (EXT4_MAP_NEW | EXT4_MAP_MAPPED |\
fs/ext4/ext4.h-255- EXT4_MAP_UNWRITTEN | EXT4_MAP_BOUNDARY |\
]
|
| 48/2 |
2026/06/01 10:52 |
llm |
expert |
0m
Model:
Tokens:
input: 70174
output: 39
thoughts: 3155
Thoughts: **Analyzing a KMSAN Report with Ext4 and Uninitialized Memory**
Okay, so I'm trying to understand this KMSAN report pointing to uninitialized memory, specifically around `folio_alloc_noprof`. It's all about how `ext4` handles unwritten extents and block writes. Here's what I've figured out, step-by-step:
1. **Initial Mapping and Zeroing:** The code uses `EXT4_MAP_NEW`, which translates to `BH_New` within a buffer head (`bh`). When converting an unwritten extent to a written extent, `ext4_map_blocks` can set this. If `EXT4_MAP_NEW` is set, `buffer_new(bh)` is TRUE, and `ext4_block_write_begin` is supposed to zero out partial blocks in that buffer.
2. **The Key Question: Unwritten Extents:** The crucial point is what happens if the extent *was* unwritten. In that case, `EXT4_MAP_UNWRITTEN` is FALSE. If it converts an unwritten extent to a written extent, it allocates space (or rather, just updates the extent tree). `buffer_unwritten(bh)` is FALSE, and if `buffer_uptodate(bh)` is also FALSE, the code *should* call `ext4_read_bh_lock` to read from disk. The problem is that it is reading potentially uninitialized data from disk which will later be decrypted.
3. **KMSAN and Initialized Memory:** KMSAN doesn't complain about uninitialized memory read from disk because the block device driver is supposed to initialize it. However, the report is complaining about `folio_alloc_noprof` which is memory that wasn't ever written to by a block device driver! So `ext4_read_bh_lock` was *not* called. The key is in why.
4. **Skipping `ext4_read_bh_lock`:** The call to `ext4_read_bh_lock` is skipped if `(block_start < from || block_end > to)` is FALSE, which means the *entire* block is covered by the write. In this scenario, `generic_perform_write` will copy data to the *entire* block.
5. **Failure and Retries:** If `copy_from_user` fails (copies fewer bytes than expected), `folio_zero_new_buffers` is *not* called because `buffer_new(bh)` is FALSE. However, the block becomes uptodate and dirty, which is problematic. On a retry, if the buffer is already mapped (and `buffer_new(bh)` is FALSE), and `copy_from_user` succeeds, the *entire* block is now initialized.
6. **Partial Writes and the Bug:** If the write size (`len`) is less than the block size, `(block_start < from || block_end > to)` *is* TRUE, so `ext4_read_bh_lock` should be called. However, it's NOT.
7. **The Critical Condition:** To reproduce the KMSAN report, we need to end up with uninitialized memory in a buffer. The only way this happens is if:
* `buffer_unwritten(bh)` is TRUE.
* `buffer_new(bh)` is FALSE.
* `len < blocksize` (partial write).
8. **The Scenario for the Bug:** This combination is possible if the buffer was ALREADY mapped and unwritten *before* `ext4_write_begin` (and `ext4_block_write_begin`). The initial `ext4_write_begin` is called with `len = blocksize`. `get_block` is called (which will be `ext4_get_block_unwritten` in this case) sets `buffer_unwritten(bh)` and `buffer_new(bh)`. `ext4_block_write_begin` zeroes the entire block (nothing to zero because `len==blocksize`). Then `copy_from_user` FAILS. Then, `folio_zero_new_buffers` zeroes and marks as uptodate the buffer (but clears `buffer_new(bh)`).
Now the kernel calls `ext4_write_begin` again, but this time a partial block is going to be written. The `ext4_block_write_begin` code clears `buffer_new(bh)` and *does not* read from disk or zero, because `buffer_unwritten(bh)` is still TRUE. If `copy_from_user` fails, then partial
|
| 49/2 |
2026/06/01 10:53 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/ext4/inode.c Name:ext4_page_mkwrite]
Results: map[SourceCode:6598: vm_fault_t ext4_page_mkwrite(struct vm_fault *vmf)
6599: {
6600: struct vm_area_struct *vma = vmf->vma;
6601: struct folio *folio = page_folio(vmf->page);
6602: loff_t size;
6603: unsigned long len;
6604: int err;
6605: vm_fault_t ret;
6606: struct file *file = vma->vm_file;
6607: struct inode *inode = file_inode(file);
6608: struct address_space *mapping = inode->i_mapping;
6609: get_block_t *get_block = ext4_get_block;
6610: int retries = 0;
6611:
6612: if (unlikely(IS_IMMUTABLE(inode)))
6613: return VM_FAULT_SIGBUS;
6614:
6615: sb_start_pagefault(inode->i_sb);
6616: file_update_time(vma->vm_file);
6617:
6618: filemap_invalidate_lock_shared(mapping);
6619:
6620: err = ext4_convert_inline_data(inode);
6621: if (err)
6622: goto out_ret;
6623:
6624: /*
6625: * On data journalling we skip straight to the transaction handle:
6626: * there's no delalloc; page truncated will be checked later; the
6627: * early return w/ all buffers mapped (calculates size/len) can't
6628: * be used; and there's no dioread_nolock, so only ext4_get_block.
6629: */
6630: if (ext4_should_journal_data(inode))
6631: goto retry_alloc;
6632:
6633: /* Delalloc case is easy... */
6634: if (test_opt(inode->i_sb, DELALLOC) &&
6635: !ext4_nonda_switch(inode->i_sb)) {
6636: do {
6637: err = block_page_mkwrite(vma, vmf,
6638: ext4_da_get_block_prep);
6639: } while (err == -ENOSPC &&
6640: ext4_should_retry_alloc(inode->i_sb, &retries));
6641: goto out_ret;
6642: }
6643:
6644: folio_lock(folio);
6645: size = i_size_read(inode);
6646: /* Page got truncated from under us? */
6647: if (folio->mapping != mapping || folio_pos(folio) > size) {
6648: folio_unlock(folio);
6649: ret = VM_FAULT_NOPAGE;
6650: goto out;
6651: }
6652:
6653: len = folio_size(folio);
6654: if (folio_pos(folio) + len > size)
6655: len = size - folio_pos(folio);
6656: /*
6657: * Return if we have all the buffers mapped. This avoids the need to do
6658: * journal_start/journal_stop which can block and take a long time
6659: *
6660: * This cannot be done for data journalling, as we have to add the
6661: * inode to the transaction's list to writeprotect pages on commit.
6662: */
6663: if (folio_buffers(folio)) {
6664: if (!ext4_walk_page_buffers(NULL, inode, folio_buffers(folio),
6665: 0, len, NULL,
6666: ext4_bh_unmapped)) {
6667: /* Wait so that we don't change page under IO */
6668: folio_wait_stable(folio);
6669: ret = VM_FAULT_LOCKED;
6670: goto out;
6671: }
6672: }
6673: folio_unlock(folio);
6674: /* OK, we need to fill the hole... */
6675: if (ext4_should_dioread_nolock(inode))
6676: get_block = ext4_get_block_unwritten;
6677: retry_alloc:
6678: /* Start journal and allocate blocks */
6679: err = ext4_block_page_mkwrite(inode, folio, get_block);
6680: if (err == -EAGAIN ||
6681: (err == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries)))
6682: goto retry_alloc;
6683: out_ret:
6684: ret = vmf_fs_error(err);
6685: out:
6686: filemap_invalidate_unlock_shared(mapping);
6687: sb_end_pagefault(inode->i_sb);
6688: return ret;
6689: }
SourceFile:fs/ext4/inode.c]
|
| 50/2 |
2026/06/01 10:53 |
llm |
expert |
0m
Model:
Tokens:
input: 75883
output: 41
thoughts: 3984
Thoughts: **Analyzing Ext4 Block Write Logic: Uncovering Potential Uninitialized Memory**
Okay, here's the breakdown of my thought process. I'm digging deep into how the ext4 filesystem handles block writes, specifically focusing on the critical issue of potentially uninitialized memory. I started by tracing the execution path, from `block_page_mkwrite` down to the fundamental block write operations.
The key players are functions like `ext4_block_write_begin`, `get_block`, `folio_zero_new_buffers`, and the various buffer flags (`buffer_new`, `buffer_uptodate`, `buffer_unwritten`, etc.). My primary concern is the interplay of these functions and flags, and identifying scenarios where uninitialized memory might slip through.
I've initially observed that `folio_zero_new_buffers` seems designed to address partial block writes and zero out any newly allocated buffers. `buffer_new` appears to be the indicator here. The critical question is when and how `buffer_new` gets set and cleared. It is set by get_block, and should be cleared either during a fault, during zeroing, or on the next loop.
I carefully scrutinized the loops in `ext4_block_write_begin`, recognizing that `get_block` can be called. I examined the scenarios where `get_block` may fail, and the buffers might not be properly zeroed.
I delved into how partial block writes are handled, where the write size (`len`) is less than the block size. Then I realized that if the block is already mapped (not `buffer_new`) and the partial block is *not* read from disk (due to the `buffer_unwritten` flag), then the partial block could be uninitialized.
The issue hinges on ensuring that either the buffer is initialized from disk, or is zeroed out if it's new. `buffer_unwritten` seems to bypass this check.
Then I found a path where `buffer_new` gets set, but the loop fails or has to write to a block that is *already* mapped and unwritten and does not read from disk. The partial block becomes uninitialized.
I have found a path: a previous write set the `buffer_new(bh)`, but it was not cleared. Then a subsequent write to the partial block writes to uninitialized memory.
|
| 51/2 |
2026/06/01 10:53 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/ext4/inode.c Name:ext4_block_page_mkwrite]
Results: map[SourceCode:6549: static int ext4_block_page_mkwrite(struct inode *inode, struct folio *folio,
6550: get_block_t get_block)
6551: {
6552: handle_t *handle;
6553: loff_t size;
6554: unsigned long len;
6555: int credits;
6556: int ret;
6557:
6558: credits = ext4_chunk_trans_extent(inode,
6559: ext4_journal_blocks_per_folio(inode));
6560: handle = ext4_journal_start(inode, EXT4_HT_WRITE_PAGE, credits);
6561: if (IS_ERR(handle))
6562: return PTR_ERR(handle);
6563:
6564: folio_lock(folio);
6565: size = i_size_read(inode);
6566: /* Page got truncated from under us? */
6567: if (folio->mapping != inode->i_mapping || folio_pos(folio) > size) {
6568: ret = -EFAULT;
6569: goto out_error;
6570: }
6571:
6572: len = folio_size(folio);
6573: if (folio_pos(folio) + len > size)
6574: len = size - folio_pos(folio);
6575:
6576: ret = ext4_block_write_begin(handle, folio, 0, len, get_block);
6577: if (ret)
6578: goto out_error;
6579:
6580: if (!ext4_should_journal_data(inode)) {
6581: block_commit_write(folio, 0, len);
6582: folio_mark_dirty(folio);
6583: } else {
6584: ret = ext4_journal_folio_buffers(handle, folio, len);
6585: if (ret)
6586: goto out_error;
6587: }
6588: ext4_journal_stop(handle);
6589: folio_wait_stable(folio);
6590: return ret;
6591:
6592: out_error:
6593: folio_unlock(folio);
6594: ext4_journal_stop(handle);
6595: return ret;
6596: }
SourceFile:fs/ext4/inode.c]
|
| 52/2 |
2026/06/01 10:53 |
llm |
expert |
0m
Model:
Tokens:
input: 81123
output: 45
thoughts: 2001
Thoughts: **The Unwritten Extent Bug: A Deep Dive**
Okay, let's break this down. It started with tracing how `ext4_block_page_mkwrite` interacts with the buffer handling. I initially thought that the buffer would always be zeroed out because of `block_commit_write` clearing `buffer_new(bh)`. Then there was the `folio_zero_new_buffers` call within `ext4_block_write_begin` if it failed, which *also* clears `buffer_new(bh)`. So, the buffer *should* always be initialized.
But how could `buffer_new(bh)` be FALSE, and `buffer_unwritten(bh)` be TRUE *without* the buffer being uptodate? That's the crux. Looking at `ext4_get_block_unwritten`, I realized it *always* sets `buffer_new(bh)` if the buffer is unwritten. So that wasn't the path. But what about the *other* get block function?
The key is in `ext4_get_block`. *This* function doesn't set `buffer_new(bh)` when mapping an *existing* unwritten extent. Instead, it sets `buffer_unwritten(bh)`. The crucial detail is that `ext4_map_blocks` does NOT set `EXT4_MAP_NEW` if mapping an *existing* unwritten extent, only if it *allocates* a new block. So, `buffer_new(bh)` remains FALSE while `buffer_unwritten(bh)` is TRUE, because the extent was already there, unwritten.
That's where the problem arises! In `ext4_block_write_begin`, because `buffer_new(bh)` is FALSE, it skips the partial block zeroing. It *also* skips the `ext4_read_bh_lock` call because `buffer_unwritten(bh)` is TRUE. Thus, the partial blocks remain uninitialized. When `generic_perform_write` comes into play, it copies from the user's buffer into the uninitialized partial blocks of the file, then `block_commit_write` makes it uptodate. And *that* is where the stale data gets written to disk. This perfectly matches the KMSAN report.
Now, when does `ext4_get_block` get called? It turns out that `ext4_write_begin` will use it unless `ext4_should_dioread_nolock` is TRUE. My reproducer has `dioread_lock` on, which *disables* `dioread_nolock`! Bingo!
The final piece: if we try to `create = 1` using `ext4_get_block` on an unwritten extent, we end up calling `ext4_map_blocks` with `EXT4_GET_BLOCKS_CREATE`. I see that converts the unwritten extent to a written extent. So does that mean that it sets EXT4_MAP_NEW? Yes, because then a *new* block is effectively allocated, the function should now set buffer_new true. This is another area that needs further verification within `ext4_map_blocks`, however, the primary bug is clearly visible.
|
| 53/2 |
2026/06/01 10:54 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/ext4/extents.c Name:ext4_ext_handle_unwritten_extents]
Results: map[SourceCode:3966: static struct ext4_ext_path *
3967: ext4_ext_handle_unwritten_extents(handle_t *handle, struct inode *inode,
3968: struct ext4_map_blocks *map,
3969: struct ext4_ext_path *path, int flags,
3970: unsigned int *allocated, ext4_fsblk_t newblock)
3971: {
3972: int err = 0;
3973:
3974: ext_debug(inode, "logical block %llu, max_blocks %u, flags 0x%x, allocated %u\n",
3975: (unsigned long long)map->m_lblk, map->m_len, flags,
3976: *allocated);
3977: ext4_ext_show_leaf(inode, path);
3978:
3979: /*
3980: * When writing into unwritten space, we should not fail to
3981: * allocate metadata blocks for the new extent block if needed.
3982: */
3983: flags |= EXT4_GET_BLOCKS_METADATA_NOFAIL;
3984:
3985: trace_ext4_ext_handle_unwritten_extents(inode, map, flags,
3986: *allocated, newblock);
3987:
3988: /* IO end_io complete, convert the filled extent to written */
3989: if (flags & EXT4_GET_BLOCKS_CONVERT) {
3990: path = ext4_convert_unwritten_extents_endio(handle, inode,
3991: map, path, flags);
3992: if (IS_ERR(path))
3993: return path;
3994: ext4_update_inode_fsync_trans(handle, inode, 1);
3995: goto map_out;
3996: }
3997: /* buffered IO cases */
3998: /*
3999: * repeat fallocate creation request
4000: * we already have an unwritten extent
4001: */
4002: if (flags & EXT4_GET_BLOCKS_UNWRIT_EXT) {
4003: map->m_flags |= EXT4_MAP_UNWRITTEN;
4004: goto map_out;
4005: }
4006:
4007: /* buffered READ or buffered write_begin() lookup */
4008: if ((flags & EXT4_GET_BLOCKS_CREATE) == 0) {
4009: /*
4010: * We have blocks reserved already. We
4011: * return allocated blocks so that delalloc
4012: * won't do block reservation for us. But
4013: * the buffer head will be unmapped so that
4014: * a read from the block returns 0s.
4015: */
4016: map->m_flags |= EXT4_MAP_UNWRITTEN;
4017: goto out1;
4018: }
4019:
4020: /*
4021: * Default case when (flags & EXT4_GET_BLOCKS_CREATE) == 1.
4022: * For buffered writes, at writepage time, etc. Convert a
4023: * discovered unwritten extent to written.
4024: */
4025: path = ext4_ext_convert_to_initialized(handle, inode, map, path,
4026: flags, allocated);
4027: if (IS_ERR(path))
4028: return path;
4029: ext4_update_inode_fsync_trans(handle, inode, 1);
4030: /*
4031: * shouldn't get a 0 allocated when converting an unwritten extent
4032: * unless m_len is 0 (bug) or extent has been corrupted
4033: */
4034: if (unlikely(*allocated == 0)) {
4035: EXT4_ERROR_INODE(inode, "unexpected allocated == 0, m_len = %u",
4036: map->m_len);
4037: err = -EFSCORRUPTED;
4038: goto errout;
4039: }
4040:
4041: map->m_flags |= EXT4_MAP_NEW;
4042: map_out:
4043: map->m_flags |= EXT4_MAP_MAPPED;
4044: out1:
4045: map->m_pblk = newblock;
4046: if (*allocated > map->m_len)
4047: *allocated = map->m_len;
4048: map->m_len = *allocated;
4049: ext4_ext_show_leaf(inode, path);
4050: return path;
4051:
4052: errout:
4053: ext4_free_ext_path(path);
4054: return ERR_PTR(err);
4055: }
SourceFile:fs/ext4/extents.c]
|
| 54/2 |
2026/06/01 10:54 |
llm |
expert |
0m
Model:
Tokens:
input: 85308
output: 43
thoughts: 6934
Thoughts: **Unraveling the Mystery of Uninitialized Memory in ext4 Writes**
Okay, I've been wrestling with this ext4 code and the KMSAN report, trying to understand how uninitialized memory is creeping into encrypted block writes. It seems to be linked to a writeback scenario where the kernel ends up encrypting a block that's not fully initialized.
My initial assumption was that uninitialized memory was somehow persisting in partially written blocks. I looked at the interplay between `ext4_block_write_begin`, `ext4_da_get_block_prep`, and the `buffer_new(bh)` and `buffer_uptodate(bh)` flags. The goal of `ext4_block_write_begin` is to make sure that these buffers are either initialized with valid data (by reading from disk) or are completely zeroed to ensure data integrity.
I thought that the code was not zeroing the right blocks. But, the code should ALWAYS zero partial blocks during writes. If `buffer_new(bh)` is true, `ext4_block_write_begin` should zero the block, and the subsequent write operation should populate the rest. I saw the checks in `ext4_block_write_begin`, which should clear the `buffer_new(bh)` before calling `get_block`. `folio_zero_new_buffers` should zero the buffer if `copy_from_user` fails and make the buffer uptodate in `block_commit_write` if all bytes are copied. So this means blocks should be zeroed.
I looked at the code paths with `ext4_da_write_begin` and `ext4_write_begin`. In all these cases, `buffer_new(bh)` should always be set to TRUE. In ALL cases, it should be cleared and the buffer should be uptodate.
But the KMSAN report points to the encryption layer (`fscrypt_encrypt_pagecache_blocks`). This happens during writeback, meaning the buffer is already in the page cache. And the code is using the flags `buffer_uptodate(bh)` to control if we skip or call the crypto routine.
My breakthrough came when I realized that `fscrypt_encrypt_pagecache_blocks` encrypts blocks ONLY if `buffer_uptodate(bh)` is TRUE, meaning that the data should be safe! So why is this happening?
I believe that a block might have been partially initialized in a *previous* write. In this case, `buffer_new(bh)` may have been set and cleared, but the buffer may not have been fully zeroed or overwritten. The buffer is set to `uptodate` but still has uninitialized bytes. This would lead to a mix of initialized and uninitialized data. When `ext4_writepages` comes to write the pages, it calls `fscrypt_encrypt_pagecache_blocks`.
I need to confirm that `block_commit_write` and `folio_zero_new_buffers` are working as expected. Perhaps there's an edge case where these functions don't fully initialize and mark the buffer as up-to-date.
Perhaps the issue is related to delayed allocation blocks.
|
| 55/2 |
2026/06/01 10:55 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/ext4/inode.c Name:ext4_journalled_zero_new_buffers]
Results: map[SourceCode:1497: /*
1498: * This is a private version of folio_zero_new_buffers() which doesn't
1499: * set the buffer to be dirty, since in data=journalled mode we need
1500: * to call ext4_dirty_journalled_data() instead.
1501: */
1502: static void ext4_journalled_zero_new_buffers(handle_t *handle,
1503: struct inode *inode,
1504: struct folio *folio,
1505: unsigned from, unsigned to)
1506: {
1507: unsigned int block_start = 0, block_end;
1508: struct buffer_head *head, *bh;
1509:
1510: bh = head = folio_buffers(folio);
1511: do {
1512: block_end = block_start + bh->b_size;
1513: if (buffer_new(bh)) {
1514: if (block_end > from && block_start < to) {
1515: if (!folio_test_uptodate(folio)) {
1516: unsigned start, size;
1517:
1518: start = max(from, block_start);
1519: size = min(to, block_end) - start;
1520:
1521: folio_zero_range(folio, start, size);
1522: }
1523: clear_buffer_new(bh);
1524: write_end_fn(handle, inode, bh);
1525: }
1526: }
1527: block_start = block_end;
1528: bh = bh->b_this_page;
1529: } while (bh != head);
1530: }
SourceFile:fs/ext4/inode.c]
|
| 56/2 |
2026/06/01 10:55 |
llm |
expert |
0m
Model:
Tokens:
input: 93504
output: 41
thoughts: 6761
Thoughts: **Unraveling the Uninitialized Memory Mystery in ext4 Write Operations**
Okay, here's the deal, after some serious head-scratching, I think I've got a handle on the uninitialized memory issue. The core of the problem lies in *how* ext4 manages blocks within a folio when a write operation doesn't cover the entire thing. The code's got some clever optimizations, but it looks like they're leading to this vulnerability.
Initially, I was fixated on `ext4_journalled_zero_new_buffers` because I saw it zeroes parts of the buffer but, critically, *doesn't* set `buffer_uptodate(bh)`. I thought this might leave the rest of the block uninitialized. However, this is NOT the issue, because it is only used for data journaling which is NOT the case for the reproducer.
Then I dug into `ext4_block_write_begin`, which is key. The initial read path checks if `buffer_new(bh)` is set. If it is, this is an unwritten, new or delayed block. This path has the potential to leave part of the block uninitialized if the write is smaller than the block size. When it is less than a block size, `ext4_block_write_begin` zeroes the portion *within the write range*, but doesn't necessarily touch *all* the blocks in the folio. If the copy_from_user fails, `folio_zero_new_buffers` should then zero the rest, *and* set `buffer_uptodate`, to make sure all is well. If the copy succeeds it makes the part within the range uptodate and dirty.
But I began to notice a pattern where `generic_perform_write` may cause `ext4_block_write_begin` to be called with a smaller `len` than the *initial* request. This means, the check in `ext4_block_write_begin` `(block_end > from && block_start < to)` does not zero the partial blocks, and, if `folio_zero_new_buffers` doesn't clear `buffer_new(bh)` the next time `ext4_block_write_begin` is called, it might mean parts of the folio remain uninitialized.
The key insight is this: if the folio spans multiple blocks, and only *part* of a block is written by a specific write operation, those *other* blocks, not covered by `[from, to)`, are *not* automatically zeroed *and* are not explicitly marked dirty, especially if it returns an error. The blocks which were not touched will not be updated.
So, if we have a filesystem with a *smaller* block size than the page size (which is the usual setup), we write part of a block. The unwritten sections of *other* blocks within the folio are not zeroed, aren't marked dirty. This is the crux of the issue.
Finally, while looking at all of the blocks in the folio, if the test `(block_end <= from || block_start >= to)` returns true for any block, it is not initialized, nor is it marked dirty, and it is likely not written to disk. The only solution is if we call `ext4_block_write_begin` for any part of the block in the folio.
|
| 57/2 |
2026/06/01 10:56 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/crypto/crypto.c Name:fscrypt_encrypt_pagecache_blocks]
Results: map[SourceCode: 147: /**
148: * fscrypt_encrypt_pagecache_blocks() - Encrypt data from a pagecache folio
149: * @folio: the locked pagecache folio containing the data to encrypt
150: * @len: size of the data to encrypt, in bytes
151: * @offs: offset within @page of the data to encrypt, in bytes
152: * @gfp_flags: memory allocation flags; see details below
153: *
154: * This allocates a new bounce page and encrypts the given data into it. The
155: * length and offset of the data must be aligned to the file's crypto data unit
156: * size. Alignment to the filesystem block size fulfills this requirement, as
157: * the filesystem block size is always a multiple of the data unit size.
158: *
159: * In the bounce page, the ciphertext data will be located at the same offset at
160: * which the plaintext data was located in the source page. Any other parts of
161: * the bounce page will be left uninitialized.
162: *
163: * This is for use by the filesystem's ->writepages() method.
164: *
165: * The bounce page allocation is mempool-backed, so it will always succeed when
166: * @gfp_flags includes __GFP_DIRECT_RECLAIM, e.g. when it's GFP_NOFS. However,
167: * only the first page of each bio can be allocated this way. To prevent
168: * deadlocks, for any additional pages a mask like GFP_NOWAIT must be used.
169: *
170: * Return: the new encrypted bounce page on success; an ERR_PTR() on failure
171: */
172: struct page *fscrypt_encrypt_pagecache_blocks(struct folio *folio,
173: size_t len, size_t offs, gfp_t gfp_flags)
174: {
175: const struct inode *inode = folio->mapping->host;
176: const struct fscrypt_inode_info *ci = fscrypt_get_inode_info_raw(inode);
177: const unsigned int du_bits = ci->ci_data_unit_bits;
178: const unsigned int du_size = 1U << du_bits;
179: struct page *ciphertext_page;
180: u64 index = ((u64)folio->index << (PAGE_SHIFT - du_bits)) +
181: (offs >> du_bits);
182: unsigned int i;
183: int err;
184:
185: VM_BUG_ON_FOLIO(folio_test_large(folio), folio);
186: if (WARN_ON_ONCE(!folio_test_locked(folio)))
187: return ERR_PTR(-EINVAL);
188:
189: if (WARN_ON_ONCE(len <= 0 || !IS_ALIGNED(len | offs, du_size)))
190: return ERR_PTR(-EINVAL);
191:
192: ciphertext_page = fscrypt_alloc_bounce_page(gfp_flags);
193: if (!ciphertext_page)
194: return ERR_PTR(-ENOMEM);
195:
196: for (i = offs; i < offs + len; i += du_size, index++) {
197: err = fscrypt_crypt_data_unit(ci, FS_ENCRYPT, index,
198: &folio->page, ciphertext_page,
199: du_size, i);
200: if (err) {
201: fscrypt_free_bounce_page(ciphertext_page);
202: return ERR_PTR(err);
203: }
204: }
205: SetPagePrivate(ciphertext_page);
206: set_page_private(ciphertext_page, (unsigned long)folio);
207: return ciphertext_page;
208: }
SourceFile:fs/crypto/crypto.c]
|
| 58/2 |
2026/06/01 10:56 |
llm |
expert |
0m
Model:
Tokens:
input: 102192
output: 42
thoughts: 80
Thoughts: **Understanding Page Cache Block Encryption**
Okay, so I'm looking at this `fscrypt_encrypt_pagecache_blocks` function. Right, the parameters here are `len` and `offs`. Crucially, it only encrypts a portion of the data within a page cache block, starting at `offs` and going for a length of `len`. This is important β it's *not* encrypting the entire folio. That's a key distinction. Now, the natural next question is, who's actually calling this encryption routine? Let me trace back... Ah, it's `ext4_bio_write_folio`. That makes perfect sense within the file system context.
|
| 59/2 |
2026/06/01 10:56 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/ext4/page-io.c Name:ext4_bio_write_folio]
Results: map[SourceCode: 458: int ext4_bio_write_folio(struct ext4_io_submit *io, struct folio *folio,
459: size_t len)
460: {
461: struct folio *io_folio = folio;
462: struct inode *inode = folio->mapping->host;
463: unsigned block_start;
464: struct buffer_head *bh, *head;
465: int ret = 0;
466: int nr_to_submit = 0;
467: struct writeback_control *wbc = io->io_wbc;
468: bool keep_towrite = false;
469:
470: BUG_ON(!folio_test_locked(folio));
471: BUG_ON(folio_test_writeback(folio));
472:
473: /*
474: * Comments copied from block_write_full_folio:
475: *
476: * The folio straddles i_size. It must be zeroed out on each and every
477: * writepage invocation because it may be mmapped. "A file is mapped
478: * in multiples of the page size. For a file that is not a multiple of
479: * the page size, the remaining memory is zeroed when mapped, and
480: * writes to that region are not written out to the file."
481: */
482: if (len < folio_size(folio))
483: folio_zero_segment(folio, len, folio_size(folio));
484: /*
485: * In the first loop we prepare and mark buffers to submit. We have to
486: * mark all buffers in the folio before submitting so that
487: * folio_end_writeback() cannot be called from ext4_end_bio() when IO
488: * on the first buffer finishes and we are still working on submitting
489: * the second buffer.
490: */
491: bh = head = folio_buffers(folio);
492: do {
493: block_start = bh_offset(bh);
494: if (block_start >= len) {
495: clear_buffer_dirty(bh);
496: set_buffer_uptodate(bh);
497: continue;
498: }
499: if (!buffer_dirty(bh) || buffer_delay(bh) ||
500: !buffer_mapped(bh) || buffer_unwritten(bh)) {
501: /* A hole? We can safely clear the dirty bit */
502: if (!buffer_mapped(bh))
503: clear_buffer_dirty(bh);
504: /*
505: * Keeping dirty some buffer we cannot write? Make sure
506: * to redirty the folio and keep TOWRITE tag so that
507: * racing WB_SYNC_ALL writeback does not skip the folio.
508: * This happens e.g. when doing writeout for
509: * transaction commit or when journalled data is not
510: * yet committed.
511: */
512: if (buffer_dirty(bh) ||
513: (buffer_jbd(bh) && buffer_jbddirty(bh))) {
514: if (!folio_test_dirty(folio))
515: folio_redirty_for_writepage(wbc, folio);
516: keep_towrite = true;
517: }
518: continue;
519: }
520: if (buffer_new(bh))
521: clear_buffer_new(bh);
522: set_buffer_async_write(bh);
523: clear_buffer_dirty(bh);
524: nr_to_submit++;
525: } while ((bh = bh->b_this_page) != head);
526:
527: /* Nothing to submit? Just unlock the folio... */
528: if (!nr_to_submit)
529: return 0;
530:
531: bh = head = folio_buffers(folio);
532:
533: /*
534: * If any blocks are being written to an encrypted file, encrypt them
535: * into a bounce page. For simplicity, just encrypt until the last
536: * block which might be needed. This may cause some unneeded blocks
537: * (e.g. holes) to be unnecessarily encrypted, but this is rare and
538: * can't happen in the common case of blocksize == PAGE_SIZE.
539: */
540: if (fscrypt_inode_uses_fs_layer_crypto(inode)) {
541: gfp_t gfp_flags = GFP_NOFS;
542: unsigned int enc_bytes = round_up(len, i_blocksize(inode));
543: struct page *bounce_page;
544:
545: /*
546: * Since bounce page allocation uses a mempool, we can only use
547: * a waiting mask (i.e. request guaranteed allocation) on the
548: * first page of the bio. Otherwise it can deadlock.
549: */
550: if (io->io_bio)
551: gfp_flags = GFP_NOWAIT;
552: retry_encrypt:
553: bounce_page = fscrypt_encrypt_pagecache_blocks(folio,
554: enc_bytes, 0, gfp_flags);
555: if (IS_ERR(bounce_page)) {
556: ret = PTR_ERR(bounce_page);
557: if (ret == -ENOMEM &&
558: (io->io_bio || wbc->sync_mode == WB_SYNC_ALL)) {
559: gfp_t new_gfp_flags = GFP_NOFS;
560: if (io->io_bio)
561: ext4_io_submit(io);
562: else
563: new_gfp_flags |= __GFP_NOFAIL;
564: memalloc_retry_wait(gfp_flags);
565: gfp_flags = new_gfp_flags;
566: goto retry_encrypt;
567: }
568:
569: printk_ratelimited(KERN_ERR "%s: ret = %d\n", __func__, ret);
570: folio_redirty_for_writepage(wbc, folio);
571: do {
572: if (buffer_async_write(bh)) {
573: clear_buffer_async_write(bh);
574: set_buffer_dirty(bh);
575: }
576: bh = bh->b_this_page;
577: } while (bh != head);
578:
579: return ret;
580: }
581: io_folio = page_folio(bounce_page);
582: }
583:
584: __folio_start_writeback(folio, keep_towrite);
585:
586: /* Now submit buffers to write */
587: do {
588: if (!buffer_async_write(bh))
589: continue;
590: io_submit_add_bh(io, inode, folio, io_folio, bh);
591: } while ((bh = bh->b_this_page) != head);
592:
593: return 0;
594: }
SourceFile:fs/ext4/page-io.c]
|
| 60/2 |
2026/06/01 10:56 |
llm |
expert |
0m
Model:
Tokens:
input: 104658
output: 66
thoughts: 3253
Thoughts: **Analysis of the Uninitialized Memory Encryption in ext4 with fscrypt**
Okay, so here's the deal. I've been digging into this `ext4_bio_write_folio` function and how it interacts with fscrypt encryption, and I think I've got a handle on this "bug" that KMSAN is flagging. The core of it seems to be that `fscrypt_encrypt_pagecache_blocks` is encrypting more data than it should, leading to a read of uninitialized memory.
Specifically, it looks like when writing to a file in an encrypted directory, where you write to a block that follows a hole (e.g., writing to block 1 when block 0 is a hole), the system allocates a folio, but it **doesn't** initialize all of its blocks. `ext4_write_begin` is involved in creating the initial folio without zeroing all blocks, and only `ext4_block_write_begin` processes blocks that intersect the write range, leaving block 0 unmapped, uninitialized, and containing potentially sensitive data from whatever was there previously.
The problem lies with how `ext4_bio_write_folio` then calls `fscrypt_encrypt_pagecache_blocks`. It's passing in a length (`len`) that represents the whole file size (or folio size) to encrypt all blocks from offset `0` to that `len`. So, even though block 0 is unmapped and potentially uninitialized, it gets encrypted along with block 1. `enc_bytes` is rounded up to the block size, ensuring block 0 is included. This is where KMSAN kicks in, complaining about the read of potentially uninitialized memory.
However, and this is crucial, `ext4_bio_write_folio` *only* submits buffer heads to the block layer if they're marked for an async write (meaning they're dirty and mapped). Since block 0 isn't dirty or mapped because it's a hole, it's *not* submitted for write. The ciphertext of block 0 is put in the bounce page, but never makes it to the block layer.
Therefore, although this triggers a KMSAN warning during encryption, the uninitialized memory isn't actually written to disk. The sensitive data is read from the page and encrypted, but then discarded. There's *no* memory corruption, *no* data leak, and *no* denial of service in a standard production environment, assuming KMSAN isn't compiled in. In production, this would just be a slight performance hit from encrypting garbage data and wasting CPU cycles.
Essentially, it's a read of uninitialized memory that *doesn't* result in a security issue. It can be triggered by a user in an unprivileged manner when writing to a file that has a hole in a fscrypt enabled directory. But that doesn't mean it's exploitable.
|
| 61/2 |
2026/06/01 10:56 |
tool |
set-results |
0m
Args: map[DenialOfService:false Exploitable:false FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:false RemoteTrigger:false Unprivileged:true UserNamespace:true VMGuestTrigger:false VMHostTrigger:false]
Results: map[DenialOfService:false Exploitable:false FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:false RemoteTrigger:false Unprivileged:true UserNamespace:true VMGuestTrigger:false VMHostTrigger:false]
|
| 62/2 |
2026/06/01 10:56 |
llm |
expert |
0m
Model:
Tokens:
input: 108666
output: 616
thoughts: 339
Thoughts: **Finalizing the Analysis**
Okay, the analysis is complete, and the results are definitive. Time to synthesize this into a clear and concise explanation for the user. I need to articulate the root cause, dissect the mechanism of this particular bug, and, most importantly, explain *why* it poses no real threat.
The root cause, as I understand it, stems from the behavior of `ext4_bio_write_folio`. Essentially, this function encrypts the *entire* folio, up to `i_size` or the write `len`, even if portions of the folio haven't been properly initialized, or map to valid blocks.
The mechanism behind it is a bit more intricate. When a write occurs at an offset within a file, let's say to block 1, it leaves a "hole" at the beginning of the folio (block 0). Now, `ext4_write_begin` allocates a fresh folio for this write. Critically, `ext4_block_write_begin` *only* initializes the blocks that *intersect* with the write range. So our uninitialized block 0 persists. During the subsequent writeback process, `ext4_bio_write_folio` kicks in, and calls `fscrypt_encrypt_pagecache_blocks`, which then proceeds to encrypt the entire folio, including block 0. This is where the uninitialized memory within that initial block gets read, which, as we know, is what triggers the KMSAN.
However, and this is the crux of the matter, the security impact is, thankfully, negligible. The ciphertext derived from that uninitialized memory in block 0 ends up residing in the bounce page. However, because `ext4_bio_write_folio` is only submitting the buffer heads corresponding to the *mapped* and *dirty* blocks, the ciphertext for this uninitialized data never gets written to disk. It's never sent to the block layer, and it's never exposed to userspace. It's, as we determined, effectively a harmless, internal read of uninitialized memory.
This is all relatively straightforward to trigger: an unprivileged user can cause this by simply creating an encrypted file and writing to it with an offset that introduces that initial hole in the folio.
I think I have a clear and comprehensive summary now. Time to compose the final response.
|
| 63/1 |
2026/06/01 10:56 |
action |
format-explanation |
0m
Results: map[Explanation:Based on the analysis of the bug report and the kernel source code, here is the
assessment of the issue:
**Root Cause and Mechanism:**
The bug is a KMSAN report for the use of an uninitialized value during
filesystem encryption (`fscrypt`). It occurs when an unprivileged user writes to
an encrypted file at an offset that leaves a hole at the beginning of a page
cache folio (e.g., writing to block 1 while block 0 remains a hole).
1. When the write occurs, `ext4_write_begin` allocates a new folio for the page
cache. This folio is allocated without the `__GFP_ZERO` flag, meaning it
contains uninitialized memory (leftover data from previous uses).
2. `ext4_block_write_begin` processes the blocks within the folio. It only
initializes (reads from disk or zeroes) the blocks that intersect with the write
range. The blocks corresponding to the hole (e.g., block 0) are left unmapped
and uninitialized.
3. Later, during the writeback phase, `ext4_bio_write_folio` is called to write
the dirty folio to disk. It determines the length of the data to write (usually
up to `i_size`).
4. It then calls `fscrypt_encrypt_pagecache_blocks` to encrypt the data into a
newly allocated bounce page. However, `fscrypt_encrypt_pagecache_blocks`
encrypts the data starting from offset 0 up to the rounded-up length, regardless
of whether the underlying blocks are mapped or dirty.
5. This causes the kernel to read and encrypt the uninitialized memory in the
unmapped hole blocks, which triggers the KMSAN warning.
**Security Impact:**
Despite reading uninitialized memory, this bug has **no security impact** and is
**not exploitable**:
- After the encryption completes, `ext4_bio_write_folio` iterates over the
buffer heads of the folio to submit them to the block layer.
- It strictly checks each buffer head and only submits those that were marked
for asynchronous write (i.e., the blocks that were actually mapped and dirty).
- The ciphertext corresponding to the uninitialized hole blocks is placed in the
bounce page but is **never submitted to the block layer**.
- Consequently, the uninitialized memory (and its ciphertext) is immediately
discarded, never written to disk, and never exposed to userspace. It is a benign
read of uninitialized memory that only trips debugging tools like KMSAN.
- In production builds (where KMSAN is disabled), this will silently encrypt
garbage and discard it without causing any memory corruption, crashes, or
information leaks.
**Trigger:**
The bug can be triggered by any unprivileged user who has the ability to create
and write to an encrypted directory/file (which is standard on systems utilizing
`fscrypt`, like Android or typical Linux desktops). No special capabilities or
namespaces are required.]
|