| 0/0 |
2026/05/21 16:04 |
flow |
assessment-security |
52m
Results: map[DenialOfService:true Explanation:Based on the analysis of the stack traces and the XFS source code, here is the
assessment of the bug:
**Bug Mechanism:**
The bug is a classic AB-BA deadlock in the XFS filesystem involving buffer locks
and log forcing during a filesystem shutdown.
1. **Task 2** executes `ioctl(FS_IOC_SETFSLABEL)`, which calls
`xfs_ioc_setlabel()` -> `xfs_sync_sb_buf()`. This function locks the superblock
buffer, commits a synchronous transaction, and waits for the log to be written
to disk (`xlog_wait_on_iclog`) **while still holding the superblock buffer
lock**.
2. **Task 1** encounters an IO error or metadata corruption (in the reproducer,
this is caused by reading a corrupted btree block from a malicious image during
a `truncate` operation). This triggers a forced filesystem shutdown
(`xfs_do_force_shutdown()`).
3. The shutdown process calls `xlog_state_shutdown_callbacks()`, which processes
committed items in the CIL to abort them. This involves unpinning buffers
(`xfs_buf_item_unpin()`), which requires acquiring the buffer lock
(`xfs_buf_lock()`).
4. **Deadlock:** Task 1 blocks trying to acquire the superblock buffer lock held
by Task 2. Task 2 is blocked waiting for the log to force, but the log is shut
down. Task 1 is responsible for waking up the log waiters, but it only does so
*after* unpinning the buffers. Both tasks wait on each other indefinitely.
**Security Impact:**
- **Exploitable:** No. This is a pure deadlock issue. It does not involve memory
corruption, use-after-free, or out-of-bounds accesses, so it cannot be exploited
for privilege escalation or arbitrary code execution.
- **Denial of Service:** Yes. The deadlock hangs the involved tasks in the `D`
(uninterruptible) state, holding critical XFS locks that will eventually hang
any other processes attempting to access the filesystem, leading to a denial of
service.
- **Unprivileged / User Namespace:** No. The only path in the kernel that holds
a buffer lock across a synchronous log commit is `xfs_sync_sb_buf()`, which is
exclusively called by `xfs_ioc_setlabel()`. This ioctl explicitly enforces a
capability check: `if (!capable(CAP_SYS_ADMIN)) return -EPERM;`. Because it uses
`capable()` rather than `ns_capable()`, it strictly requires `CAP_SYS_ADMIN` in
the **initial** user namespace. Furthermore, XFS filesystems cannot be mounted
inside user namespaces (`FS_USERNS_MOUNT` is not set).
- **Filesystem Trigger:** Yes. A malicious filesystem image is used to reliably
trigger the metadata corruption that initiates the shutdown sequence. However,
because triggering the deadlock also requires the highly privileged
`FS_IOC_SETFSLABEL` ioctl to be called concurrently, the attack surface is
extremely limited in practice. Exploitable:false FilesystemTrigger:true NetworkTrigger:false PeripheralTrigger:false RemoteTrigger:false Unprivileged:false UserNamespace:false VMGuestTrigger:false VMHostTrigger:false]
|
| 1/1 |
2026/05/21 16: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
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$xfs arguments: [
// fs: ptr[in, buffer] {
// buffer: {78 66 73 00} (length 0x4)
// }
// dir: ptr[in, buffer] {
// buffer: {2e 2f 66 69 6c 65 30 00} (length 0x8)
// }
// flags: mount_flags = 0x0 (8 bytes)
// opts: ptr[in, fs_options[xfs_options]] {
// fs_options[xfs_options] {
// elems: array[fs_opt_elem[xfs_options]] {
// }
// common: array[fs_opt_elem[fs_options_common]] {
// }
// null: const = 0x0 (1 bytes)
// }
// }
// chdir: int8 = 0x1 (1 bytes)
// size: len = 0x96a4 (8 bytes)
// img: ptr[in, buffer] {
// buffer: (compressed buffer with length 0x96a7)
// }
// ]
// returns fd_dir
memcpy((void*)0x200000009680, "xfs\000", 4);
memcpy((void*)0x2000000096c0, "./file0\000", 8);
*(uint8_t*)0x2000000000c0 = 0;
memcpy((void*)0x200000012d80, "... [truncated large byte array] ...", 38567);
syz_mount_image(/*fs=*/0x200000009680, /*dir=*/0x2000000096c0, /*flags=*/0, /*opts=*/0x2000000000c0, /*chdir=*/1, /*size=*/0x96a4, /*img=*/0x200000012d80);
// openat arguments: [
// fd: fd_dir (resource)
// file: ptr[in, buffer] {
// buffer: {2e 2f 66 69 6c 65 31 00} (length 0x8)
// }
// flags: open_flags = 0x441 (4 bytes)
// mode: open_mode = 0x14a (2 bytes)
// ]
// returns fd
memcpy((void*)0x200000000080, "./file1\000", 8);
res = syscall(__NR_openat, /*fd=*/0xffffff9c, /*file=*/0x200000000080ul, /*flags=O_CREAT|O_APPEND|O_WRONLY*/0x441, /*mode=S_IWOTH|S_IXGRP|S_IXUSR|S_IRUSR*/0x14a);
if (res != -1)
r[0] = res;
// openat arguments: [
// fd: fd_dir (resource)
// file: ptr[in, buffer] {
// buffer: {2e 2f 66 69 6c 65 31 00} (length 0x8)
// }
// flags: open_flags = 0x183341 (4 bytes)
// mode: open_mode = 0x0 (2 bytes)
// ]
// returns fd
memcpy((void*)0x200000000080, "./file1\000", 8);
syscall(__NR_openat, /*fd=*/0xffffff9c, /*file=*/0x200000000080ul, /*flags=O_TRUNC|O_SYNC|O_NOCTTY|O_CREAT|O_CLOEXEC|FASYNC|0x1*/0x183341, /*mode=*/0);
// ioctl$FS_IOC_SETFSLABEL arguments: [
// fd: fd (resource)
// cmd: const = 0x41009432 (4 bytes)
// arg: ptr[in, buffer] {
// buffer: {13 44 35 78 ef 2f e3 37 b6 43 e9 1c 00 62 15 10 13 f2 7c 57 bf ee ef d6 1b 67 aa 48 35 56 f7 d3 d5 23 3c 1e d2 31 7b 0a 5a 71 f0 24 b9 e3 af fc e3 86 c6 99 ec 39 aa c2 37 86 c7 23 5a 39 1d 8a aa 1f 81 1c 38 33 f1 ad 7b b3 af 99 40 a8 b6 97 82 62 23 30 63 71 be db 30 32 71 5d f9 84 5a b0 4c 6b 1d 93 d4 5d af 9e 67 05 9e c9 aa 56 92 23 81 ae 41 b8 13 3a 4e 44 6b 4a 5e 02 f5 51 82 3f 13 e6 64 7c c9 2e ee f7 a8 2c ff 69 6c 9f 18 40 f5 85 73 93 dc f7 f4 5e 8b a4 d3 7d ce ca 49 33 0f e3 15 b6 a0 03 86 1c ec 01 82 45 ad f5 ab c1 7f 9e 1d 1d ac d7 db 3d c7 15 ed 21 0e 64 37 c4 8a 97 fc 67 28 0f 31 9f da 25 4c 41 a3 3e 27 3d e3 a0 bb 42 66 3c 46 2e b1 a9 89 d0 2a 91 3d e8 4f aa 83 f0 ca 7b ed 3e 88 c0 40 a7 67 d1 d0 a6 f0 55 9d 9f ce 60 83 e6 ca 62 11 a7 02 b8 03 05} (length 0x100)
// }
// ]
memcpy((void*)0x200000000180, "... [truncated large byte array] ...", 256);
syscall(__NR_ioctl, /*fd=*/r[0], /*cmd=*/0x41009432, /*arg=*/0x200000000180ul);
return 0;
}
]
|
| 2/1 |
2026/05/21 16:04 |
action |
kernel-checkouter |
1m
Results: map[KernelSrc:/app/workdir/cache/src/2d90bd8e7d30ecf76b87994ed0f62b9229dfbbf8]
|
| 3/1 |
2026/05/21 16:05 |
action |
kernel-builder |
24m
Results: map[KernelObj:/app/workdir/cache/build/cee87d7e4c06c6ccd0b8277c178ff6c82aaa65a4]
|
| 4/1 |
2026/05/21 16:30 |
action |
codesearch-prepare |
21m
Results: map[Index:codesearch-index]
|
| 5/1 |
2026/05/21 16:51 |
agent |
expert |
5m
Model:
Results: map[DenialOfService:true Exploitable:false FilesystemTrigger:true NetworkTrigger:false PeripheralTrigger:false RemoteTrigger:false Unprivileged:false UserNamespace:false 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 greeping
".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).
Don't make assumptions; verify them with source code access. 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 completly 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 tranfers, that's 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 exploitabability 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 Confidetial 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.
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:
INFO: task syz.0.42:6230 blocked for more than 143 seconds.
Not tainted syzkaller #0
"echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.
task:syz.0.42 state:D stack:22312 pid:6230 tgid:6229 ppid:5930 task_flags:0x440140 flags:0x00080002
Call Trace:
<TASK>
context_switch kernel/sched/core.c:5295 [inline]
__schedule+0x14fb/0x52c0 kernel/sched/core.c:6907
__schedule_loop kernel/sched/core.c:6989 [inline]
schedule+0x164/0x360 kernel/sched/core.c:7004
schedule_timeout+0xc3/0x2c0 kernel/time/sleep_timeout.c:75
___down_common kernel/locking/semaphore.c:268 [inline]
__down_common+0x321/0x730 kernel/locking/semaphore.c:293
down+0x80/0xd0 kernel/locking/semaphore.c:100
xfs_buf_lock+0x14d/0x520 fs/xfs/xfs_buf.c:993
xfs_buf_item_unpin+0x1c4/0x770 fs/xfs/xfs_buf_item.c:551
xlog_cil_ail_insert fs/xfs/xfs_log_cil.c:-1 [inline]
xlog_cil_committed+0x9f4/0x1170 fs/xfs/xfs_log_cil.c:995
xlog_cil_process_committed+0x15c/0x1b0 fs/xfs/xfs_log_cil.c:1025
xlog_state_shutdown_callbacks+0x277/0x380 fs/xfs/xfs_log.c:438
xlog_force_shutdown+0x332/0x400 fs/xfs/xfs_log.c:3406
xfs_do_force_shutdown+0x2ab/0x700 fs/xfs/xfs_fsops.c:507
xfs_trans_read_buf_map+0x518/0x950 fs/xfs/xfs_trans_buf.c:311
xfs_trans_read_buf fs/xfs/xfs_trans.h:212 [inline]
xfs_btree_read_buf_block+0x2b0/0x490 fs/xfs/libxfs/xfs_btree.c:1402
xfs_btree_lookup_get_block+0x297/0x510 fs/xfs/libxfs/xfs_btree.c:1907
xfs_btree_lookup+0x45a/0x1350 fs/xfs/libxfs/xfs_btree.c:2018
xfs_alloc_lookup fs/xfs/libxfs/xfs_alloc.c:166 [inline]
xfs_alloc_lookup_le fs/xfs/libxfs/xfs_alloc.c:212 [inline]
xfs_free_ag_extent+0x277/0x17d0 fs/xfs/libxfs/xfs_alloc.c:2080
__xfs_free_extent+0x36e/0x4f0 fs/xfs/libxfs/xfs_alloc.c:4047
xfs_extent_free_finish_item+0x292/0x640 fs/xfs/xfs_extfree_item.c:553
xfs_defer_finish_one+0x5d7/0xd80 fs/xfs/libxfs/xfs_defer.c:595
xfs_defer_finish_noroll+0x940/0x13b0 fs/xfs/libxfs/xfs_defer.c:707
xfs_defer_finish+0x1c/0x180 fs/xfs/libxfs/xfs_defer.c:741
xfs_bunmapi_range+0xc4/0x140 fs/xfs/libxfs/xfs_bmap.c:6169
xfs_itruncate_extents_flags+0x2f9/0xa10 fs/xfs/xfs_inode.c:1077
xfs_itruncate_extents fs/xfs/xfs_inode.h:604 [inline]
xfs_setattr_size+0x980/0xf30 fs/xfs/xfs_iops.c:1095
xfs_vn_setattr+0x261/0x310 fs/xfs/xfs_iops.c:1171
notify_change+0xc18/0xf60 fs/attr.c:556
do_truncate+0x1c2/0x250 fs/open.c:68
handle_truncate fs/namei.c:4279 [inline]
do_open fs/namei.c:4675 [inline]
path_openat+0x2fc4/0x38a0 fs/namei.c:4830
do_file_open+0x23e/0x4a0 fs/namei.c:4859
do_sys_openat2+0x113/0x200 fs/open.c:1366
do_sys_open fs/open.c:1372 [inline]
__do_sys_openat fs/open.c:1388 [inline]
__se_sys_openat fs/open.c:1383 [inline]
__x64_sys_openat+0x138/0x170 fs/open.c:1383
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0x14d/0xf80 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f6e9a90c799
RSP: 002b:00007f6e99f66028 EFLAGS: 00000246 ORIG_RAX: 0000000000000101
RAX: ffffffffffffffda RBX: 00007f6e9ab85fa0 RCX: 00007f6e9a90c799
RDX: 0000000000183341 RSI: 0000200000000080 RDI: ffffffffffffff9c
RBP: 00007f6e9a9a2bd9 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 00007f6e9ab86038 R14: 00007f6e9ab85fa0 R15: 00007ffc54605238
</TASK>
INFO: task syz.0.42:6239 blocked for more than 143 seconds.
Not tainted syzkaller #0
"echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.
task:syz.0.42 state:D stack:26504 pid:6239 tgid:6229 ppid:5930 task_flags:0x400140 flags:0x00080002
Call Trace:
<TASK>
context_switch kernel/sched/core.c:5295 [inline]
__schedule+0x14fb/0x52c0 kernel/sched/core.c:6907
__schedule_loop kernel/sched/core.c:6989 [inline]
schedule+0x164/0x360 kernel/sched/core.c:7004
xlog_wait fs/xfs/xfs_log_priv.h:604 [inline]
xlog_wait_on_iclog+0x487/0x710 fs/xfs/xfs_log.c:791
xlog_force_lsn+0x511/0x9b0 fs/xfs/xfs_log.c:2949
__xfs_trans_commit+0x7d3/0xc20 fs/xfs/xfs_trans.c:877
xfs_trans_commit+0x13e/0x1c0 fs/xfs/xfs_trans.c:926
xfs_sync_sb_buf+0x13f/0x230 fs/xfs/libxfs/xfs_sb.c:1490
xfs_ioc_setlabel+0x1de/0x340 fs/xfs/xfs_ioctl.c:1041
xfs_file_ioctl+0x9c5/0x1710 fs/xfs/xfs_ioctl.c:1198
vfs_ioctl fs/ioctl.c:51 [inline]
__do_sys_ioctl fs/ioctl.c:597 [inline]
__se_sys_ioctl+0xff/0x170 fs/ioctl.c:583
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0x14d/0xf80 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f6e9a90c799
RSP: 002b:00007f6e99f45028 EFLAGS: 00000246 ORIG_RAX: 0000000000000010
RAX: ffffffffffffffda RBX: 00007f6e9ab86090 RCX: 00007f6e9a90c799
RDX: 0000200000000180 RSI: 0000000041009432 RDI: 0000000000000004
RBP: 00007f6e9a9a2bd9 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 00007f6e9ab86128 R14: 00007f6e9ab86090 R15: 00007ffc54605238
</TASK>
Showing all locks held in the system:
4 locks held by pr/legacy/17:
1 lock held by khungtaskd/37:
#0: ffffffff8ddcd780 (rcu_read_lock){....}-{1:3}, at: rcu_lock_acquire include/linux/rcupdate.h:312 [inline]
#0: ffffffff8ddcd780 (rcu_read_lock){....}-{1:3}, at: rcu_read_lock include/linux/rcupdate.h:850 [inline]
#0: ffffffff8ddcd780 (rcu_read_lock){....}-{1:3}, at: debug_show_all_locks+0x2e/0x180 kernel/locking/lockdep.c:6775
2 locks held by kworker/u8:8/985:
2 locks held by getty/5555:
#0: ffff88802649c0a0 (&tty->ldisc_sem){++++}-{0:0}, at: tty_ldisc_ref_wait+0x25/0x70 drivers/tty/tty_ldisc.c:243
#1: ffffc90003e8b2e0 (&ldata->atomic_read_lock){+.+.}-{4:4}, at: n_tty_read+0x462/0x13c0 drivers/tty/n_tty.c:2211
5 locks held by syz.0.42/6230:
#0: ffff88802d650480 (sb_writers#12){.+.+}-{0:0}, at: mnt_want_write+0x41/0x90 fs/namespace.c:493
#1: ffff88804505bf10 (&sb->s_type->i_mutex_key#24){+.+.}-{4:4}, at: inode_lock_killable include/linux/fs.h:1033 [inline]
#1: ffff88804505bf10 (&sb->s_type->i_mutex_key#24){+.+.}-{4:4}, at: do_truncate+0x18f/0x250 fs/open.c:63
#2: ffff88804505c0e0 (mapping.invalidate_lock#3){+.+.}-{4:4}, at: xfs_ilock+0x16d/0x3b0 fs/xfs/xfs_inode.c:157
#3: ffff88802d650770 (sb_internal#2){.+.+}-{0:0}, at: xfs_trans_alloc+0xd7/0x9b0 fs/xfs/xfs_trans.c:254
#4: ffff88804505bc88 (&xfs_nondir_ilock_class){++++}-{4:4}, at: xfs_setattr_size+0x7f1/0xf30 fs/xfs/xfs_iops.c:1059
1 lock held by syz.0.42/6239:
#0: ffff88802d650480 (sb_writers#12){.+.+}-{0:0}, at: mnt_want_write_file+0x63/0x210 fs/namespace.c:537
5 locks held by syz.1.158/7436:
#0: ffff888023c94480 (sb_writers#12){.+.+}-{0:0}, at: mnt_want_write+0x41/0x90 fs/namespace.c:493
#1: ffff888059d7c790 (&sb->s_type->i_mutex_key#24){+.+.}-{4:4}, at: inode_lock_killable include/linux/fs.h:1033 [inline]
#1: ffff888059d7c790 (&sb->s_type->i_mutex_key#24){+.+.}-{4:4}, at: do_truncate+0x18f/0x250 fs/open.c:63
#2: ffff888059d7c960 (mapping.invalidate_lock#3){+.+.}-{4:4}, at: xfs_ilock+0x16d/0x3b0 fs/xfs/xfs_inode.c:157
#3: ffff888023c94770 (sb_internal#2){.+.+}-{0:0}, at: xfs_trans_alloc+0xd7/0x9b0 fs/xfs/xfs_trans.c:254
#4: ffff888059d7c508 (&xfs_nondir_ilock_class){++++}-{4:4}, at: xfs_setattr_size+0x7f1/0xf30 fs/xfs/xfs_iops.c:1059
1 lock held by syz.1.158/7447:
#0: ffff888023c94480 (sb_writers#12){.+.+}-{0:0}, at: mnt_want_write_file+0x63/0x210 fs/namespace.c:537
2 locks held by kworker/u8:2/7663:
#0: ffff888029373938 ((wq_completion)xfs-cil/loop2){+.+.}-{0:0}, at: process_one_work kernel/workqueue.c:3250 [inline]
#0: ffff888029373938 ((wq_completion)xfs-cil/loop2){+.+.}-{0:0}, at: process_scheduled_works+0x9ea/0x1830 kernel/workqueue.c:3358
#1: ffffc9000ee97c40 ((work_completion)(&ctx->push_work)){+.+.}-{0:0}, at: process_one_work kernel/workqueue.c:3251 [inline]
#1: ffffc9000ee97c40 ((work_completion)(&ctx->push_work)){+.+.}-{0:0}, at: process_scheduled_works+0xa25/0x1830 kernel/workqueue.c:3358
1 lock held by syz.2.184/7735:
#0: ffff88802a002480 (sb_writers#12){.+.+}-{0:0}, at: mnt_want_write_file+0x63/0x210 fs/namespace.c:537
1 lock held by udevd/7740:
5 locks held by syz.3.196/7871:
#0: ffff8880246a4480 (sb_writers#12){.+.+}-{0:0}, at: mnt_want_write+0x41/0x90 fs/namespace.c:493
#1: ffff888045111d10 (&sb->s_type->i_mutex_key#24){+.+.}-{4:4}, at: inode_lock_killable include/linux/fs.h:1033 [inline]
#1: ffff888045111d10 (&sb->s_type->i_mutex_key#24){+.+.}-{4:4}, at: do_truncate+0x18f/0x250 fs/open.c:63
#2: ffff888045111ee0 (mapping.invalidate_lock#3){+.+.}-{4:4}, at: xfs_ilock+0x16d/0x3b0 fs/xfs/xfs_inode.c:157
#3: ffff8880246a4770 (sb_internal#2){.+.+}-{0:0}, at: xfs_trans_alloc+0xd7/0x9b0 fs/xfs/xfs_trans.c:254
#4: ffff888045111a88 (&xfs_nondir_ilock_class){++++}-{4:4}, at: xfs_setattr_size+0x7f1/0xf30 fs/xfs/xfs_iops.c:1059
=============================================
NMI backtrace for cpu 0
CPU: 0 UID: 0 PID: 37 Comm: khungtaskd Not tainted syzkaller #0 PREEMPT_{RT,(full)}
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 02/12/2026
Call Trace:
<TASK>
dump_stack_lvl+0xe8/0x150 lib/dump_stack.c:120
nmi_cpu_backtrace+0x274/0x2d0 lib/nmi_backtrace.c:113
nmi_trigger_cpumask_backtrace+0x17a/0x300 lib/nmi_backtrace.c:62
trigger_all_cpu_backtrace include/linux/nmi.h:161 [inline]
__sys_info lib/sys_info.c:157 [inline]
sys_info+0x135/0x170 lib/sys_info.c:165
check_hung_uninterruptible_tasks kernel/hung_task.c:346 [inline]
watchdog+0xfd9/0x1030 kernel/hung_task.c:515
kthread+0x388/0x470 kernel/kthread.c:467
ret_from_fork+0x51e/0xb90 arch/x86/kernel/process.c:158
ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245
</TASK>
Sending NMI from CPU 0 to CPUs 1:
NMI backtrace for cpu 1
CPU: 1 UID: 0 PID: 17 Comm: pr/legacy Not tainted syzkaller #0 PREEMPT_{RT,(full)}
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 02/12/2026
RIP: 0010:io_serial_in+0x77/0xc0 drivers/tty/serial/8250/8250_port.c:400
Code: e8 8e 16 95 fc 44 89 f9 d3 e3 49 83 ee 80 4c 89 f0 48 c1 e8 03 42 80 3c 20 00 74 08 4c 89 f7 e8 bf 24 fb fc 41 03 1e 89 da ec <0f> b6 c0 5b 41 5c 41 5e 41 5f e9 4a 86 f6 05 cc 44 89 f9 80 e1 07
RSP: 0018:ffffc900001679d0 EFLAGS: 00000202
RAX: 1ffffffff3329e00 RBX: 00000000000003fd RCX: 0000000000000000
RDX: 00000000000003fd RSI: 0000000000000000 RDI: 0000000000000000
RBP: ffffffff9994f730 R08: 0000000000000000 R09: 0000000000000000
R10: dffffc0000000000 R11: ffffffff852f3c50 R12: dffffc0000000000
R13: 0000000000000000 R14: ffffffff9994f4a0 R15: 0000000000000000
FS: 0000000000000000(0000) GS:ffff888126440000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007fc3b7002000 CR3: 000000003a0e6000 CR4: 00000000003526f0
Call Trace:
<TASK>
serial_in drivers/tty/serial/8250/8250.h:128 [inline]
serial_lsr_in drivers/tty/serial/8250/8250.h:150 [inline]
wait_for_lsr+0x1aa/0x2f0 drivers/tty/serial/8250/8250_port.c:1961
fifo_wait_for_lsr drivers/tty/serial/8250/8250_port.c:3234 [inline]
serial8250_console_fifo_write drivers/tty/serial/8250/8250_port.c:3257 [inline]
serial8250_console_write+0x120d/0x1b90 drivers/tty/serial/8250/8250_port.c:3342
console_emit_next_record kernel/printk/printk.c:3163 [inline]
console_flush_one_record+0x68b/0xb90 kernel/printk/printk.c:3269
legacy_kthread_func+0x1b6/0x250 kernel/printk/printk.c:3712
kthread+0x388/0x470 kernel/kthread.c:467
ret_from_fork+0x51e/0xb90 arch/x86/kernel/process.c:158
ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245
</TASK>
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
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$xfs arguments: [
// fs: ptr[in, buffer] {
// buffer: {78 66 73 00} (length 0x4)
// }
// dir: ptr[in, buffer] {
// buffer: {2e 2f 66 69 6c 65 30 00} (length 0x8)
// }
// flags: mount_flags = 0x0 (8 bytes)
// opts: ptr[in, fs_options[xfs_options]] {
// fs_options[xfs_options] {
// elems: array[fs_opt_elem[xfs_options]] {
// }
// common: array[fs_opt_elem[fs_options_common]] {
// }
// null: const = 0x0 (1 bytes)
// }
// }
// chdir: int8 = 0x1 (1 bytes)
// size: len = 0x96a4 (8 bytes)
// img: ptr[in, buffer] {
// buffer: (compressed buffer with length 0x96a7)
// }
// ]
// returns fd_dir
memcpy((void*)0x200000009680, "xfs\000", 4);
memcpy((void*)0x2000000096c0, "./file0\000", 8);
*(uint8_t*)0x2000000000c0 = 0;
memcpy((void*)0x200000012d80, "... [truncated large byte array] ...", 38567);
syz_mount_image(/*fs=*/0x200000009680, /*dir=*/0x2000000096c0, /*flags=*/0, /*opts=*/0x2000000000c0, /*chdir=*/1, /*size=*/0x96a4, /*img=*/0x200000012d80);
// openat arguments: [
// fd: fd_dir (resource)
// file: ptr[in, buffer] {
// buffer: {2e 2f 66 69 6c 65 31 00} (length 0x8)
// }
// flags: open_flags = 0x441 (4 bytes)
// mode: open_mode = 0x14a (2 bytes)
// ]
// returns fd
memcpy((void*)0x200000000080, "./file1\000", 8);
res = syscall(__NR_openat, /*fd=*/0xffffff9c, /*file=*/0x200000000080ul, /*flags=O_CREAT|O_APPEND|O_WRONLY*/0x441, /*mode=S_IWOTH|S_IXGRP|S_IXUSR|S_IRUSR*/0x14a);
if (res != -1)
r[0] = res;
// openat arguments: [
// fd: fd_dir (resource)
// file: ptr[in, buffer] {
// buffer: {2e 2f 66 69 6c 65 31 00} (length 0x8)
// }
// flags: open_flags = 0x183341 (4 bytes)
// mode: open_mode = 0x0 (2 bytes)
// ]
// returns fd
memcpy((void*)0x200000000080, "./file1\000", 8);
syscall(__NR_openat, /*fd=*/0xffffff9c, /*file=*/0x200000000080ul, /*flags=O_TRUNC|O_SYNC|O_NOCTTY|O_CREAT|O_CLOEXEC|FASYNC|0x1*/0x183341, /*mode=*/0);
// ioctl$FS_IOC_SETFSLABEL arguments: [
// fd: fd (resource)
// cmd: const = 0x41009432 (4 bytes)
// arg: ptr[in, buffer] {
// buffer: {13 44 35 78 ef 2f e3 37 b6 43 e9 1c 00 62 15 10 13 f2 7c 57 bf ee ef d6 1b 67 aa 48 35 56 f7 d3 d5 23 3c 1e d2 31 7b 0a 5a 71 f0 24 b9 e3 af fc e3 86 c6 99 ec 39 aa c2 37 86 c7 23 5a 39 1d 8a aa 1f 81 1c 38 33 f1 ad 7b b3 af 99 40 a8 b6 97 82 62 23 30 63 71 be db 30 32 71 5d f9 84 5a b0 4c 6b 1d 93 d4 5d af 9e 67 05 9e c9 aa 56 92 23 81 ae 41 b8 13 3a 4e 44 6b 4a 5e 02 f5 51 82 3f 13 e6 64 7c c9 2e ee f7 a8 2c ff 69 6c 9f 18 40 f5 85 73 93 dc f7 f4 5e 8b a4 d3 7d ce ca 49 33 0f e3 15 b6 a0 03 86 1c ec 01 82 45 ad f5 ab c1 7f 9e 1d 1d ac d7 db 3d c7 15 ed 21 0e 64 37 c4 8a 97 fc 67 28 0f 31 9f da 25 4c 41 a3 3e 27 3d e3 a0 bb 42 66 3c 46 2e b1 a9 89 d0 2a 91 3d e8 4f aa 83 f0 ca 7b ed 3e 88 c0 40 a7 67 d1 d0 a6 f0 55 9d 9f ce 60 83 e6 ca 62 11 a7 02 b8 03 05} (length 0x100)
// }
// ]
memcpy((void*)0x200000000180, "... [truncated large byte array] ...", 256);
syscall(__NR_ioctl, /*fd=*/r[0], /*cmd=*/0x41009432, /*arg=*/0x200000000180ul);
return 0;
}
Reply: Based on the analysis of the stack traces and the XFS source code, here is the assessment of the bug:
**Bug Mechanism:**
The bug is a classic AB-BA deadlock in the XFS filesystem involving buffer locks and log forcing during a filesystem shutdown.
1. **Task 2** executes `ioctl(FS_IOC_SETFSLABEL)`, which calls `xfs_ioc_setlabel()` -> `xfs_sync_sb_buf()`. This function locks the superblock buffer, commits a synchronous transaction, and waits for the log to be written to disk (`xlog_wait_on_iclog`) **while still holding the superblock buffer lock**.
2. **Task 1** encounters an IO error or metadata corruption (in the reproducer, this is caused by reading a corrupted btree block from a malicious image during a `truncate` operation). This triggers a forced filesystem shutdown (`xfs_do_force_shutdown()`).
3. The shutdown process calls `xlog_state_shutdown_callbacks()`, which processes committed items in the CIL to abort them. This involves unpinning buffers (`xfs_buf_item_unpin()`), which requires acquiring the buffer lock (`xfs_buf_lock()`).
4. **Deadlock:** Task 1 blocks trying to acquire the superblock buffer lock held by Task 2. Task 2 is blocked waiting for the log to force, but the log is shut down. Task 1 is responsible for waking up the log waiters, but it only does so *after* unpinning the buffers. Both tasks wait on each other indefinitely.
**Security Impact:**
- **Exploitable:** No. This is a pure deadlock issue. It does not involve memory corruption, use-after-free, or out-of-bounds accesses, so it cannot be exploited for privilege escalation or arbitrary code execution.
- **Denial of Service:** Yes. The deadlock hangs the involved tasks in the `D` (uninterruptible) state, holding critical XFS locks that will eventually hang any other processes attempting to access the filesystem, leading to a denial of service.
- **Unprivileged / User Namespace:** No. The only path in the kernel that holds a buffer lock across a synchronous log commit is `xfs_sync_sb_buf()`, which is exclusively called by `xfs_ioc_setlabel()`. This ioctl explicitly enforces a capability check: `if (!capable(CAP_SYS_ADMIN)) return -EPERM;`. Because it uses `capable()` rather than `ns_capable()`, it strictly requires `CAP_SYS_ADMIN` in the **initial** user namespace. Furthermore, XFS filesystems cannot be mounted inside user namespaces (`FS_USERNS_MOUNT` is not set).
- **Filesystem Trigger:** Yes. A malicious filesystem image is used to reliably trigger the metadata corruption that initiates the shutdown sequence. However, because triggering the deadlock also requires the highly privileged `FS_IOC_SETFSLABEL` ioctl to be called concurrently, the attack surface is extremely limited in practice.
|
| 6/2 |
2026/05/21 16:51 |
llm |
expert |
0m
Model:
Tokens:
input: 18863
output: 21
thoughts: 1529
Thoughts: **Analyzing the XFS Hung Task Issue**
Okay, so I've got this bug report β an XFS hung task issue. Seems like tasks are getting stuck in `xfs_buf_lock` and `xlog_wait_on_iclog`, which immediately screams potential data corruption or a deadlock within the XFS logging subsystem. The reproducer involves a malicious XFS image and some operations β an `openat` with `O_TRUNC` and an `ioctl(FS_IOC_SETFSLABEL)`. Truncate and setting a label can trigger a lot of XFS behavior. I know those operations can be tricky, especially with potentially corrupted metadata.
Let's dive into these stack traces to get a clearer picture.
Task 1 is deeply involved in what looks like a cascading failure: it starts in `xfs_buf_lock`, which is a low-level lock, and moves through transaction commit and cleanup, calling `xfs_setattr_size`, and ultimately `do_truncate`. That sequence suggests that we are changing a file size, which might explain the `O_TRUNC`. It appears to be deep inside the extent free path. This hints at a buffer being held and not released in the context of an extended operation which is attempting to be finalized. The stack trace shows what appears to be a forced shutdown during the truncation process.
Task 2, in contrast, is stuck waiting on `xlog_wait_on_iclog`. This signals that it's waiting for something related to the in-core log. This means there's a problem with log flushing or commitment. It's calling `xfs_ioc_setlabel`, which leads me to suspect that a write to the filesystem label is at the center of this problem, and it's being blocked by whatever Task 1 is doing.
This is a pretty classic scenario β one task holding a critical resource (perhaps a buffer or log entry) while another is waiting on it. Since the reproducer involves a crafted image, I'm already thinking about potential metadata corruption or inconsistencies that the crafted image might introduce.
Now, a key point: this involves mounting an XFS image. That requires `CAP_SYS_ADMIN` in the initial user namespace, or in a user namespace if XFS is allowed to be mounted in user namespaces. XFS isn't *normally* user-namespace mountable (the `FS_USERNS_MOUNT` flag is usually not set), so there might be something specific in the setup allowing it, or maybe a privileged user is involved. I'll need to confirm that XFS isn't meant to be mounted in a user namespace, which will help narrow down how the crafted image is being accessed.
So, where do I go from here? I need to analyze the crafted image itself to understand what it's doing. I'll look at the specific data structures and blocks involved in these functions. Is the image crafted to make XFS's logging mechanism go wrong? I'll also have to understand how the truncation and set label functions are cooperating or conflicting here. Time to dig in!
|
| 7/2 |
2026/05/21 16:51 |
tool |
grepper |
0m
Args: map[Expression:FS_USERNS_MOUNT]
Results: map[Output:drivers/android/binder/rust_binderfs.c=753=static struct file_system_type binder_fs_type = {
--
drivers/android/binder/rust_binderfs.c-757- .kill_sb = binderfs_kill_super,
drivers/android/binder/rust_binderfs.c:758: .fs_flags = FS_USERNS_MOUNT,
drivers/android/binder/rust_binderfs.c-759-};
--
drivers/android/binderfs.c=749=static struct file_system_type binder_fs_type = {
--
drivers/android/binderfs.c-753- .kill_sb = binderfs_kill_super,
drivers/android/binderfs.c:754: .fs_flags = FS_USERNS_MOUNT,
drivers/android/binderfs.c-755-};
--
fs/binfmt_misc.c=1021=static struct file_system_type bm_fs_type = {
--
fs/binfmt_misc.c-1024- .init_fs_context = bm_init_fs_context,
fs/binfmt_misc.c:1025: .fs_flags = FS_USERNS_MOUNT,
fs/binfmt_misc.c-1026- .kill_sb = kill_anon_super,
--
fs/devpts/inode.c=453=static struct file_system_type devpts_fs_type = {
--
fs/devpts/inode.c-457- .kill_sb = devpts_kill_sb,
fs/devpts/inode.c:458: .fs_flags = FS_USERNS_MOUNT,
fs/devpts/inode.c-459-};
--
fs/fuse/inode.c=2130=static struct file_system_type fuse_fs_type = {
--
fs/fuse/inode.c-2132- .name = "fuse",
fs/fuse/inode.c:2133: .fs_flags = FS_HAS_SUBTYPE | FS_USERNS_MOUNT | FS_ALLOW_IDMAP,
fs/fuse/inode.c-2134- .init_fs_context = fuse_init_fs_context,
--
fs/overlayfs/params.c=760=static const struct fs_context_operations ovl_context_ops = {
--
fs/overlayfs/params.c-769- * This is called during fsopen() and will record the user namespace of
fs/overlayfs/params.c:770: * the caller in fc->user_ns since we've raised FS_USERNS_MOUNT. We'll
fs/overlayfs/params.c-771- * need it when we actually create the superblock to verify that the
--
fs/overlayfs/super.c=1575=struct file_system_type ovl_fs_type = {
--
fs/overlayfs/super.c-1579- .parameters = ovl_parameter_spec,
fs/overlayfs/super.c:1580: .fs_flags = FS_USERNS_MOUNT,
fs/overlayfs/super.c-1581- .kill_sb = kill_anon_super,
--
fs/proc/root.c=357=static struct file_system_type proc_fs_type = {
--
fs/proc/root.c-361- .kill_sb = proc_kill_sb,
fs/proc/root.c:362: .fs_flags = FS_USERNS_MOUNT | FS_DISALLOW_NOTIFY_PERM,
fs/proc/root.c-363-};
--
fs/ramfs/inode.c=317=static struct file_system_type ramfs_fs_type = {
--
fs/ramfs/inode.c-321- .kill_sb = ramfs_kill_sb,
fs/ramfs/inode.c:322: .fs_flags = FS_USERNS_MOUNT,
fs/ramfs/inode.c-323-};
--
fs/super.c=694=bool mount_capable(struct fs_context *fc)
fs/super.c-695-{
fs/super.c:696: if (!(fc->fs_type->fs_flags & FS_USERNS_MOUNT))
fs/super.c-697- return capable(CAP_SYS_ADMIN);
--
fs/super.c=734=struct super_block *sget_fc(struct fs_context *fc,
--
fs/super.c-743- /*
fs/super.c:744: * Never allow s_user_ns != &init_user_ns when FS_USERNS_MOUNT is
fs/super.c-745- * not set, as the filesystem is likely unprepared to handle it.
--
fs/super.c-748- */
fs/super.c:749: if (user_ns != &init_user_ns && !(fc->fs_type->fs_flags & FS_USERNS_MOUNT)) {
fs/super.c-750- errorfc(fc, "VFS: Mounting from non-initial user namespace is not allowed");
--
fs/sysfs/mount.c=90=static struct file_system_type sysfs_fs_type = {
--
fs/sysfs/mount.c-93- .kill_sb = sysfs_kill_sb,
fs/sysfs/mount.c:94: .fs_flags = FS_USERNS_MOUNT,
fs/sysfs/mount.c-95-};
--
include/linux/fs.h=2271=struct file_system_type {
--
include/linux/fs.h-2276-#define FS_HAS_SUBTYPE 4
include/linux/fs.h:2277:#define FS_USERNS_MOUNT 8 /* Can be mounted by userns root */
include/linux/fs.h-2278-#define FS_DISALLOW_NOTIFY_PERM 16 /* Disable fanotify permission events */
--
ipc/mqueue.c=1613=static struct file_system_type mqueue_fs_type = {
--
ipc/mqueue.c-1616- .kill_sb = kill_anon_super,
ipc/mqueue.c:1617: .fs_flags = FS_USERNS_MOUNT,
ipc/mqueue.c-1618-};
--
kernel/bpf/inode.c=1074=static struct file_system_type bpf_fs_type = {
--
kernel/bpf/inode.c-1079- .kill_sb = bpf_kill_super,
kernel/bpf/inode.c:1080: .fs_flags = FS_USERNS_MOUNT,
kernel/bpf/inode.c-1081-};
--
kernel/cgroup/cgroup.c=2392=struct file_system_type cgroup_fs_type = {
--
kernel/cgroup/cgroup.c-2396- .kill_sb = cgroup_kill_sb,
kernel/cgroup/cgroup.c:2397: .fs_flags = FS_USERNS_MOUNT,
kernel/cgroup/cgroup.c-2398-};
--
kernel/cgroup/cgroup.c=2400=static struct file_system_type cgroup2_fs_type = {
--
kernel/cgroup/cgroup.c-2404- .kill_sb = cgroup_kill_sb,
kernel/cgroup/cgroup.c:2405: .fs_flags = FS_USERNS_MOUNT,
kernel/cgroup/cgroup.c-2406-};
--
kernel/cgroup/cgroup.c=2473=static struct file_system_type cpuset_fs_type = {
--
kernel/cgroup/cgroup.c-2476- .parameters = cpuset_fs_parameters,
kernel/cgroup/cgroup.c:2477: .fs_flags = FS_USERNS_MOUNT,
kernel/cgroup/cgroup.c-2478-};
--
mm/shmem.c=5351=static struct file_system_type shmem_fs_type = {
--
mm/shmem.c-5358- .kill_sb = kill_anon_super,
mm/shmem.c:5359: .fs_flags = FS_USERNS_MOUNT | FS_ALLOW_IDMAP | FS_MGTIME,
mm/shmem.c-5360-};
--
mm/shmem.c=5761=static struct file_system_type shmem_fs_type = {
--
mm/shmem.c-5765- .kill_sb = ramfs_kill_sb,
mm/shmem.c:5766: .fs_flags = FS_USERNS_MOUNT,
mm/shmem.c-5767-};
]
|
| 8/2 |
2026/05/21 16:51 |
llm |
expert |
0m
Model:
Tokens:
input: 23391
output: 47
thoughts: 1789
Thoughts: **Analyzing a Potential XFS Deadlock**
Okay, so XFS isn't mountable in user namespaces, which at least restricts the initial exploitation vector. This likely means we need `CAP_SYS_ADMIN` in the initial user namespace to even trigger a malicious image mount, if we are thinking of malicious image scenario. But hold on... can this deadlock be triggered without a malicious image, or does the file system have to be compromised?
Let's dive into these stack traces. Task 1 shows `do_truncate` initiating a cascade that eventually calls `xfs_setattr_size`, which is, as we know, responsible for truncating extents and freeing them. The critical point seems to be within `xfs_trans_read_buf`, where an error is encountered β likely a corrupted B-tree block. This error triggers a forced shutdown sequence via `xfs_do_force_shutdown`. The shutdown then calls `xlog_state_shutdown_callbacks`, which includes processing committed items in the CIL (`xlog_cil_process_committed`). This then unpins buffer items (`xfs_buf_item_unpin`), which attempts to lock the buffer in question, calling `xfs_buf_lock`.
Meanwhile, Task 2 is busy with `xfs_ioc_setlabel`, which, from memory, modifies the superblock, syncs it, and commits a transaction. It's waiting on the iclog (`xlog_wait_on_iclog`).
The crucial observation is a potential deadlock arising between `xfs_buf_lock` within `xfs_buf_item_unpin` and some other process. The key is that `xfs_buf_item_unpin` is part of the shutdown procedure. Therefore, if a task is holding a buffer lock and waiting on the log to commit, and simultaneously the shutdown process is also triggered, the shutdown process then tries to lock the same buffer to unpin it, and we have a deadlock. This screams classic XFS shutdown-deadlock issue, a known scenario where a buffer can get locked by a process which is waiting for the log to commit, which then cannot because the system is shutting down.
Now, the important question: Can this occur on a "clean" filesystem? Consider IO errors during `xfs_trans_read_buf`. Any IO errors, whether it be disk failures or something more exotic, can force a shutdown. This scenario could happen on a perfectly normal filesystem, such as a disk failing while `do_truncate` is running, could initiate this, causing a shutdown.
Could it be that we don't need a malicious image? Could this also then deadlock if there is a task simultaneously running `xfs_ioc_setlabel`, which modifies the superblock? But wait, doesn't `xfs_ioc_setlabel` require `CAP_SYS_ADMIN`? Let me double-check that part.
|
| 9/2 |
2026/05/21 16:52 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/xfs/xfs_ioctl.c IncludeLines:true Name:xfs_ioc_setlabel]
Results: map[SourceCode: 998: static int
999: xfs_ioc_setlabel(
1000: struct file *filp,
1001: struct xfs_mount *mp,
1002: char __user *newlabel)
1003: {
1004: struct xfs_sb *sbp = &mp->m_sb;
1005: char label[XFSLABEL_MAX + 1];
1006: size_t len;
1007: int error;
1008:
1009: if (!capable(CAP_SYS_ADMIN))
1010: return -EPERM;
1011: /*
1012: * The generic ioctl allows up to FSLABEL_MAX chars, but XFS is much
1013: * smaller, at 12 bytes. We copy one more to be sure we find the
1014: * (required) NULL character to test the incoming label length.
1015: * NB: The on disk label doesn't need to be null terminated.
1016: */
1017: if (copy_from_user(label, newlabel, XFSLABEL_MAX + 1))
1018: return -EFAULT;
1019: len = strnlen(label, XFSLABEL_MAX + 1);
1020: if (len > sizeof(sbp->sb_fname))
1021: return -EINVAL;
1022:
1023: error = mnt_want_write_file(filp);
1024: if (error)
1025: return error;
1026:
1027: spin_lock(&mp->m_sb_lock);
1028: memset(sbp->sb_fname, 0, sizeof(sbp->sb_fname));
1029: memcpy(sbp->sb_fname, label, len);
1030: spin_unlock(&mp->m_sb_lock);
1031:
1032: /*
1033: * Now we do several things to satisfy userspace.
1034: * In addition to normal logging of the primary superblock, we also
1035: * immediately write these changes to sector zero for the primary, then
1036: * update all backup supers (as xfs_db does for a label change), then
1037: * invalidate the block device page cache. This is so that any prior
1038: * buffered reads from userspace (i.e. from blkid) are invalidated,
1039: * and userspace will see the newly-written label.
1040: */
1041: error = xfs_sync_sb_buf(mp, true);
1042: if (error)
1043: goto out;
1044: /*
1045: * growfs also updates backup supers so lock against that.
1046: */
1047: mutex_lock(&mp->m_growlock);
1048: error = xfs_update_secondary_sbs(mp);
1049: mutex_unlock(&mp->m_growlock);
1050:
1051: invalidate_bdev(mp->m_ddev_targp->bt_bdev);
1052: if (xfs_has_rtsb(mp) && mp->m_rtdev_targp)
1053: invalidate_bdev(mp->m_rtdev_targp->bt_bdev);
1054:
1055: out:
1056: mnt_drop_write_file(filp);
1057: return error;
1058: }
SourceFile:fs/xfs/xfs_ioctl.c]
|
| 10/2 |
2026/05/21 16:52 |
llm |
expert |
0m
Model:
Tokens:
input: 26868
output: 49
thoughts: 170
Thoughts: **Analyzing the xfs_ioc_setlabel Deadlock**
Okay, so I'm looking at this `xfs_ioc_setlabel` function, and it's immediately clear that it's going to be a problem. The code explicitly uses `capable()` with `CAP_SYS_ADMIN`, which is a classic red flag. That implies this function, and therefore, the deadlock involving it, requires that the process running it is root in the *initial* user namespace, not just any user namespace. It's not using `ns_capable()`, which would be much more flexible.
So, to trigger this particular deadlock scenario, we absolutely *need* that `CAP_SYS_ADMIN` capability in the root namespace. That narrows down the potential triggers significantly.
My next thought is: Is `xfs_ioc_setlabel` the *only* way to trigger this? Is there another code path that could lead to the same deadlock without this particular system call? I need to think outside the box.
I'm also seeing that Task 2 is doing an `xfs_sync_sb_buf`, which is going to be waiting for a transaction commit to hit disk. That's a good clue as to what's going on. I wonder if there are other calls to that same function? It could give me another vector to think about the problem. I need to trace this call chain and see if there are alternatives that share that dependency.
|
| 11/2 |
2026/05/21 16:52 |
tool |
codesearch-find-references |
0m
Args: map[ContextFile:fs/xfs/xfs_ioctl.c IncludeSnippetLines:0 Name:xfs_sync_sb_buf]
Results: map[References:[map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:xfs_ioc_setlabel SourceFile:fs/xfs/xfs_ioctl.c SourceLine:1041]] TruncatedOutput:false]
|
| 12/2 |
2026/05/21 16:52 |
llm |
expert |
0m
Model:
Tokens:
input: 27475
output: 52
thoughts: 41
Thoughts: Okay, here's my take on those thoughts, framed as an expert's internal monologue:
**Investigating `xfs_sync_sb_buf` Calls**
Hmm, interesting. It seems like `xfs_sync_sb_buf` is *only* called from `xfs_ioc_setlabel`? That'sβ¦ unexpected, honestly. I'd typically expect a super block synchronization function to be called from a wider range of contexts, especially given the criticality of super block updates. I better double-check the definition of `xfs_sync_sb_buf` to make sure there isn't something subtle going on that I'm overlooking or that I need to be made aware of. I need to understand why it's so tightly coupled with the ioctl for setting the file system label. Is it inherently specific to label changes, or is there a bigger picture here? I need more context. I'm going to quickly refresh my memory of that function's implementationβ¦
|
| 13/2 |
2026/05/21 16:52 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/xfs/libxfs/xfs_sb.c IncludeLines:true Name:xfs_sync_sb_buf]
Results: map[SourceCode:1463: /*
1464: * Same behavior as xfs_sync_sb, except that it is always synchronous and it
1465: * also writes the superblock buffer to disk sector 0 immediately.
1466: */
1467: int
1468: xfs_sync_sb_buf(
1469: struct xfs_mount *mp,
1470: bool update_rtsb)
1471: {
1472: struct xfs_trans *tp;
1473: struct xfs_buf *bp;
1474: struct xfs_buf *rtsb_bp = NULL;
1475: int error;
1476:
1477: error = xfs_trans_alloc(mp, &M_RES(mp)->tr_sb, 0, 0, 0, &tp);
1478: if (error)
1479: return error;
1480:
1481: bp = xfs_trans_getsb(tp);
1482: xfs_log_sb(tp);
1483: xfs_trans_bhold(tp, bp);
1484: if (update_rtsb) {
1485: rtsb_bp = xfs_log_rtsb(tp, bp);
1486: if (rtsb_bp)
1487: xfs_trans_bhold(tp, rtsb_bp);
1488: }
1489: xfs_trans_set_sync(tp);
1490: error = xfs_trans_commit(tp);
1491: if (error)
1492: goto out;
1493: /*
1494: * write out the sb buffer to get the changes to disk
1495: */
1496: error = xfs_bwrite(bp);
1497: if (!error && rtsb_bp)
1498: error = xfs_bwrite(rtsb_bp);
1499: out:
1500: if (rtsb_bp)
1501: xfs_buf_relse(rtsb_bp);
1502: xfs_buf_relse(bp);
1503: return error;
1504: }
SourceFile:fs/xfs/libxfs/xfs_sb.c]
|
| 14/2 |
2026/05/21 16:52 |
llm |
expert |
0m
Model:
Tokens:
input: 28450
output: 22
thoughts: 24
Thoughts: Okay, here's my summary, taking the perspective of someone knowledgeable in kernel internals:
**Investigating Call Sites of `xfs_sync_sb_buf`**
Alright, I need to get a clear picture of how `xfs_sync_sb_buf` is being used within the XFS filesystem code. My first instinct is to see where else in the kernel this function is being called. Understanding the calling context is key to understanding its purpose and potential side effects. I need to map the code paths that lead to `xfs_sync_sb_buf` to get the lay of the land. Knowing the caller context helps me understand the purpose of this call. Where is it used, when is it used, and why is it used? I suspect I'll uncover some interesting interactions. It's time to start digging through the call graph. Let's see what we can find.
|
| 15/2 |
2026/05/21 16:52 |
tool |
grepper |
0m
Args: map[Expression:xfs_sync_sb_buf]
Results: map[Output:fs/xfs/libxfs/xfs_sb.c=1467=int
fs/xfs/libxfs/xfs_sb.c:1468:xfs_sync_sb_buf(
fs/xfs/libxfs/xfs_sb.c-1469- struct xfs_mount *mp,
--
fs/xfs/libxfs/xfs_sb.h=17=extern int xfs_sync_sb(struct xfs_mount *mp, bool wait);
fs/xfs/libxfs/xfs_sb.h:18:extern int xfs_sync_sb_buf(struct xfs_mount *mp, bool update_rtsb);
fs/xfs/libxfs/xfs_sb.h-19-extern void xfs_sb_mount_common(struct xfs_mount *mp, struct xfs_sb *sbp);
--
fs/xfs/xfs_ioctl.c=999=xfs_ioc_setlabel(
--
fs/xfs/xfs_ioctl.c-1040- */
fs/xfs/xfs_ioctl.c:1041: error = xfs_sync_sb_buf(mp, true);
fs/xfs/xfs_ioctl.c-1042- if (error)
]
|
| 16/2 |
2026/05/21 16:52 |
llm |
expert |
0m
Model:
Tokens:
input: 29028
output: 49
thoughts: 587
Thoughts: **Deadlock Analysis: A Potential Scenario**
Okay, so I've been digging into this potential deadlock. Initially, I saw that `xfs_sync_sb_buf` is called solely from `xfs_ioc_setlabel`, which, of course, needs `CAP_SYS_ADMIN` in the initial user namespace. That narrows down the trigger, at least initially.
But the real question is, is this the only path? I can't just be satisfied with one possibility. This deadlock is caused by a lock contention between `xfs_buf_lock` in `xfs_buf_item_unpin` and `xlog_wait_on_iclog`. The tricky bit is that `xfs_buf_item_unpin` is called during the shutdown process, which is the crux of the problem.
So, here's my line of thinking: If a task is blocked on `xlog_wait_on_iclog` *while* holding a buffer lock and then a shutdown happens, we could have a nasty deadlock situation. The trick here is to think about the states in which `xlog_wait_on_iclog` can be called. I wonder, what is task 2 doing?
I dove into the `xfs_sync_sb_buf` code. It's doing: `xfs_trans_getsb`, `xfs_log_sb`, `xfs_trans_bhold`. The important part is `xfs_trans_bhold`, because it *keeps the buffer locked after the transaction commits*. Right there, that's where things get interesting. So `xfs_trans_commit` is called while the superblock buffer (`bp`) is held. Inside the commit, we call `xfs_trans_set_sync`, which in turn waits for the log to be written to disk with `xlog_wait_on_iclog`.
Here's the problem: if a shutdown occurs while it's waiting, that shutdown process will attempt to unpin the buffer `bp`. To do that unpinning, `xfs_buf_item_unpin` tries to lock the buffer `bp`. But the superblock buffer `bp` is *already* locked by task 2! So, the shutdown process (task 1) is blocked on `xfs_buf_lock(bp)`. Simultaneously, task 2 is blocked in `xlog_wait_on_iclog`, waiting for the log to write.
Now, wait a minute... If the log is shut down, `xlog_wait_on_iclog` *should* be woken up and return an error, shouldn't it? I need to check the code there because a timeout should prevent the deadlock.
|
| 17/2 |
2026/05/21 16:52 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/xfs/xfs_log.c IncludeLines:true Name:xlog_wait_on_iclog]
Results: map[SourceCode: 773: /*
774: * Wait for the iclog and all prior iclogs to be written disk as required by the
775: * log force state machine. Waiting on ic_force_wait ensures iclog completions
776: * have been ordered and callbacks run before we are woken here, hence
777: * guaranteeing that all the iclogs up to this one are on stable storage.
778: */
779: int
780: xlog_wait_on_iclog(
781: struct xlog_in_core *iclog)
782: __releases(iclog->ic_log->l_icloglock)
783: {
784: struct xlog *log = iclog->ic_log;
785:
786: trace_xlog_iclog_wait_on(iclog, _RET_IP_);
787: if (!xlog_is_shutdown(log) &&
788: iclog->ic_state != XLOG_STATE_ACTIVE &&
789: iclog->ic_state != XLOG_STATE_DIRTY) {
790: XFS_STATS_INC(log->l_mp, xs_log_force_sleep);
791: xlog_wait(&iclog->ic_force_wait, &log->l_icloglock);
792: } else {
793: spin_unlock(&log->l_icloglock);
794: }
795:
796: if (xlog_is_shutdown(log))
797: return -EIO;
798: return 0;
799: }
SourceFile:fs/xfs/xfs_log.c]
|
| 18/2 |
2026/05/21 16:52 |
llm |
expert |
0m
Model:
Tokens:
input: 30745
output: 48
thoughts: 66
Thoughts: Okay, let me think this through.
**Analyzing the Shutdown Sequence**
Right, I'm tracing this `xlog_wait_on_iclog` function. Seems straightforward enough at first glance, but I need to be careful with the shutdown logic. So, `xlog_wait_on_iclog` specifically checks `xlog_is_shutdown(log)`. Now, if the shutdown flag is set, it triggers `xlog_state_shutdown_callbacks`. The critical question is whether those shutdown callbacks are designed to also awaken any processes currently stalled in the `ic_force_wait` function, or if this shutdown flow is leaving them hanging. It's a critical point for ensuring data integrity and a clean shutdown. If `ic_force_wait` isn't woken, we could have lingering processes, potentially leading to lost data or corruption. I need to dig deeper into the relationship between these two, verify the interaction and ensure `ic_force_wait` is properly handled during shutdown.
|
| 19/2 |
2026/05/21 16:52 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/xfs/xfs_log.c IncludeLines:true Name:xlog_state_shutdown_callbacks]
Results: map[SourceCode: 408: /*
409: * Run all the pending iclog callbacks and wake log force waiters and iclog
410: * space waiters so they can process the newly set shutdown state. We really
411: * don't care what order we process callbacks here because the log is shut down
412: * and so state cannot change on disk anymore. However, we cannot wake waiters
413: * until the callbacks have been processed because we may be in unmount and
414: * we must ensure that all AIL operations the callbacks perform have completed
415: * before we tear down the AIL.
416: *
417: * We avoid processing actively referenced iclogs so that we don't run callbacks
418: * while the iclog owner might still be preparing the iclog for IO submssion.
419: * These will be caught by xlog_state_iclog_release() and call this function
420: * again to process any callbacks that may have been added to that iclog.
421: */
422: static void
423: xlog_state_shutdown_callbacks(
424: struct xlog *log)
425: {
426: struct xlog_in_core *iclog;
427: LIST_HEAD(cb_list);
428:
429: iclog = log->l_iclog;
430: do {
431: if (atomic_read(&iclog->ic_refcnt)) {
432: /* Reference holder will re-run iclog callbacks. */
433: continue;
434: }
435: list_splice_init(&iclog->ic_callbacks, &cb_list);
436: spin_unlock(&log->l_icloglock);
437:
438: xlog_cil_process_committed(&cb_list);
439:
440: spin_lock(&log->l_icloglock);
441: wake_up_all(&iclog->ic_write_wait);
442: wake_up_all(&iclog->ic_force_wait);
443: } while ((iclog = iclog->ic_next) != log->l_iclog);
444:
445: wake_up_all(&log->l_flush_wait);
446: }
SourceFile:fs/xfs/xfs_log.c]
|
| 20/2 |
2026/05/21 16:52 |
llm |
expert |
0m
Model:
Tokens:
input: 31756
output: 50
thoughts: 311
Thoughts: **Deadlock Discovery in XFS Shutdown**
Okay, here's the issue I've just identified: `xlog_state_shutdown_callbacks` calls `xlog_cil_process_committed(&cb_list)` *before* waking up `ic_force_wait`. That's the critical sequence. `xlog_cil_process_committed` then goes and unpins buffers, which, in turn, attempts to acquire a lock on the buffer itself.
The problem is, if that buffer is *already* locked by a task that's waiting on `ic_force_wait`, we have a classic deadlock situation. Let me break it down:
Imagine Task 1, which is the shutdown process, is currently in `xlog_state_shutdown_callbacks`. It's calling `xlog_cil_process_committed`, and this call is now blocked trying to acquire a buffer lock with `xfs_buf_lock(bp)`.
Meanwhile, we have Task 2, which is waiting in `xlog_wait_on_iclog` on `ic_force_wait`. Importantly, this task *holds* the lock on the same buffer, `bp`.
Here's the rub: Task 1 will *never* wake up `ic_force_wait` because it's stuck on `xfs_buf_lock(bp)`. Conversely, Task 2 will *never* release the lock on `bp` because it's waiting indefinitely on `ic_force_wait`. Bang! Deadlock.
Now, a very pertinent question arises: can an unprivileged user trigger this? Task 2 is executing `xfs_ioc_setlabel`, which I know requires `CAP_SYS_ADMIN` in the initial user namespace. This makes it a bit more difficult, but not impossible to exploit in certain contexts.
The real question is: Is there any other path, other than `xfs_ioc_setlabel`, that holds a buffer lock and waits on `ic_force_wait`? We need to thoroughly check all callers of `xfs_trans_bhold` to be certain.
|
| 21/2 |
2026/05/21 16:52 |
tool |
codesearch-find-references |
0m
Args: map[ContextFile:fs/xfs/xfs_trans_buf.c IncludeSnippetLines:0 Name:xfs_trans_bhold]
Results: map[References:[map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:xfs_ag_shrink_space SourceFile:fs/xfs/libxfs/xfs_ag.c SourceLine:814] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:xfs_ag_shrink_space SourceFile:fs/xfs/libxfs/xfs_ag.c SourceLine:815] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:xfs_defer_restore_resources SourceFile:fs/xfs/libxfs/xfs_defer.c SourceLine:454] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:xfs_dialloc_roll SourceFile:fs/xfs/libxfs/xfs_ialloc.c SourceLine:1696] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:xfs_dquot_disk_alloc SourceFile:fs/xfs/xfs_dquot.c SourceLine:434] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:xfs_sync_sb_buf SourceFile:fs/xfs/libxfs/xfs_sb.c SourceLine:1483] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:xfs_sync_sb_buf SourceFile:fs/xfs/libxfs/xfs_sb.c SourceLine:1487]] TruncatedOutput:false]
|
| 22/2 |
2026/05/21 16:52 |
llm |
expert |
0m
Model:
Tokens:
input: 33012
output: 52
thoughts: 13
Thoughts: Okay, here's my interpretation of that thought process, assuming I'm an expert in this field, presented as a first-person summary:
**XFS Allocation Strategy Review**
Alright, I'm thinking, let's just quickly check on `xfs_dialloc_roll`. That function is key to the allocation strategies XFS employs, especially around dialing in new allocation targets and rolling through potential block allocations. It's often where you'll find the logic that impacts fragmentation, performance under load, and how efficiently the filesystem can lay out new data. Just seeing the name sparks thoughts of things like the allocation groups and free space bitmaps, and how this particular function interacts with them. I'm wondering if there's a specific issue I'm thinking about, or if it is just a general performance concern that is prompting me to think about it. Itβs likely a critical piece, and it's always good to refresh my understanding of how it's behaving, especially if I'm troubleshooting some disk IO issue.
|
| 23/2 |
2026/05/21 16:52 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/xfs/libxfs/xfs_ialloc.c IncludeLines:true Name:xfs_dialloc_roll]
Results: map[SourceCode:1683: static int
1684: xfs_dialloc_roll(
1685: struct xfs_trans **tpp,
1686: struct xfs_buf *agibp)
1687: {
1688: struct xfs_trans *tp = *tpp;
1689: struct xfs_dquot_acct *dqinfo;
1690: int error;
1691:
1692: /*
1693: * Hold to on to the agibp across the commit so no other allocation can
1694: * come in and take the free inodes we just allocated for our caller.
1695: */
1696: xfs_trans_bhold(tp, agibp);
1697:
1698: /*
1699: * We want the quota changes to be associated with the next transaction,
1700: * NOT this one. So, detach the dqinfo from this and attach it to the
1701: * next transaction.
1702: */
1703: dqinfo = tp->t_dqinfo;
1704: tp->t_dqinfo = NULL;
1705:
1706: error = xfs_trans_roll(&tp);
1707:
1708: /* Re-attach the quota info that we detached from prev trx. */
1709: tp->t_dqinfo = dqinfo;
1710:
1711: /*
1712: * Join the buffer even on commit error so that the buffer is released
1713: * when the caller cancels the transaction and doesn't have to handle
1714: * this error case specially.
1715: */
1716: xfs_trans_bjoin(tp, agibp);
1717: *tpp = tp;
1718: return error;
1719: }
SourceFile:fs/xfs/libxfs/xfs_ialloc.c]
|
| 24/2 |
2026/05/21 16:52 |
llm |
expert |
0m
Model:
Tokens:
input: 33855
output: 49
thoughts: 124
Thoughts: **Transaction Rolling and Log Flushing**
Okay, so `xfs_dialloc_roll` is the function that initiates a transaction commit and a new transaction. My immediate question is, does `xfs_trans_roll` *block* β does it wait for the transaction log to be physically written to disk before proceeding? That's critical for understanding the consistency implications here.
My general understanding is that `xfs_trans_roll` usually *doesn't* wait for the log to be written. However, there's a caveat: if `xfs_trans_set_sync` has been called on the transaction prior to the roll, *then* it will. So, the key to understanding the blocking behavior of `xfs_dialloc_roll` is whether `xfs_trans_set_sync` is involved.
Therefore, my next step is clear. I need to determine if `xfs_trans_set_sync` is actually called *before* the `xfs_dialloc_roll` call in the relevant code path. The best way to do that is to examine the call sites of `xfs_trans_set_sync`. Let's see what we find there.
|
| 25/2 |
2026/05/21 16:53 |
tool |
codesearch-find-references |
0m
Error:
Args: map[ContextFile:fs/xfs/xfs_trans.c IncludeSnippetLines:0 Name:xfs_trans_set_sync]
Results: map[References:<nil> TruncatedOutput:false]
|
| 26/2 |
2026/05/21 16:53 |
llm |
expert |
0m
Model:
Tokens:
input: 34305
output: 22
thoughts: 19
Thoughts: Okay, here's my attempt at summarizing that thought process, keeping in mind I'm speaking to a fellow expert:
**Understanding `xfs_trans_set_sync`**
Right, so I'm looking at `xfs_trans_set_sync` here. My immediate thought is, "Okay, this is either an inline function, or more likely, a macro." Knowing the XFS code base, and the performance-critical nature of transaction handling, it's pretty much a given. That choice, to be inline or a macro, typically points toward micro-optimization, likely a compile-time substitution that avoids the overhead of a function call in the hottest paths. I'll need to dig deeper to confirm exactly how it's implemented and where it's used to fully understand its implications, but this initial assumption is pretty solid. Itβs definitely a building block within the overall transaction synchronization strategy.
|
| 27/2 |
2026/05/21 16:53 |
tool |
grepper |
0m
Args: map[Expression:xfs_trans_set_sync]
Results: map[Output:fs/xfs/libxfs/xfs_attr.c=352=xfs_attr_try_sf_addname(
--
fs/xfs/libxfs/xfs_attr.c-374- if (xfs_has_wsync(args->dp->i_mount))
fs/xfs/libxfs/xfs_attr.c:375: xfs_trans_set_sync(args->trans);
fs/xfs/libxfs/xfs_attr.c-376-
--
fs/xfs/libxfs/xfs_attr.c=1131=xfs_attr_set(
--
fs/xfs/libxfs/xfs_attr.c-1235- if (xfs_has_wsync(mp))
fs/xfs/libxfs/xfs_attr.c:1236: xfs_trans_set_sync(args->trans);
fs/xfs/libxfs/xfs_attr.c-1237-
--
fs/xfs/libxfs/xfs_sb.c=1376=xfs_sync_sb(
--
fs/xfs/libxfs/xfs_sb.c-1389- if (wait)
fs/xfs/libxfs/xfs_sb.c:1390: xfs_trans_set_sync(tp);
fs/xfs/libxfs/xfs_sb.c-1391- return xfs_trans_commit(tp);
--
fs/xfs/libxfs/xfs_sb.c=1468=xfs_sync_sb_buf(
--
fs/xfs/libxfs/xfs_sb.c-1488- }
fs/xfs/libxfs/xfs_sb.c:1489: xfs_trans_set_sync(tp);
fs/xfs/libxfs/xfs_sb.c-1490- error = xfs_trans_commit(tp);
--
fs/xfs/scrub/orphanage.c=50=xrep_chown_orphanage(
--
fs/xfs/scrub/orphanage.c-103- if (xfs_has_wsync(mp))
fs/xfs/scrub/orphanage.c:104: xfs_trans_set_sync(tp);
fs/xfs/scrub/orphanage.c-105- error = xfs_trans_commit(tp);
--
fs/xfs/xfs_acl.c=221=xfs_acl_set_mode(
--
fs/xfs/xfs_acl.c-240- if (xfs_has_wsync(mp))
fs/xfs/xfs_acl.c:241: xfs_trans_set_sync(tp);
fs/xfs/xfs_acl.c-242- return xfs_trans_commit(tp);
--
fs/xfs/xfs_bmap_util.c=1507=xfs_swap_extents(
--
fs/xfs/xfs_bmap_util.c-1726- if (xfs_has_wsync(mp))
fs/xfs/xfs_bmap_util.c:1727: xfs_trans_set_sync(tp);
fs/xfs/xfs_bmap_util.c-1728-
--
fs/xfs/xfs_exchrange.c=192=xfs_exchrange_mappings(
--
fs/xfs/xfs_exchrange.c-281- if (xfs_has_wsync(mp) || (fxr->flags & XFS_EXCHANGE_RANGE_DSYNC))
fs/xfs/xfs_exchrange.c:282: xfs_trans_set_sync(tp);
fs/xfs/xfs_exchrange.c-283-
--
fs/xfs/xfs_fsops.c=93=xfs_growfs_data_private(
--
fs/xfs/xfs_fsops.c-191-
fs/xfs/xfs_fsops.c:192: xfs_trans_set_sync(tp);
fs/xfs/xfs_fsops.c-193- error = xfs_trans_commit(tp);
--
fs/xfs/xfs_fsops.c=262=xfs_growfs_imaxpct(
--
fs/xfs/xfs_fsops.c-279- xfs_trans_mod_sb(tp, XFS_TRANS_SB_IMAXPCT, dpct);
fs/xfs/xfs_fsops.c:280: xfs_trans_set_sync(tp);
fs/xfs/xfs_fsops.c-281- return xfs_trans_commit(tp);
--
fs/xfs/xfs_inode.c=648=xfs_create(
--
fs/xfs/xfs_inode.c-743- if (xfs_has_wsync(mp) || xfs_has_dirsync(mp))
fs/xfs/xfs_inode.c:744: xfs_trans_set_sync(tp);
fs/xfs/xfs_inode.c-745-
--
fs/xfs/xfs_inode.c=793=xfs_create_tmpfile(
--
fs/xfs/xfs_inode.c-833- if (xfs_has_wsync(mp))
fs/xfs/xfs_inode.c:834: xfs_trans_set_sync(tp);
fs/xfs/xfs_inode.c-835-
--
fs/xfs/xfs_inode.c=910=xfs_link(
--
fs/xfs/xfs_inode.c-975- if (xfs_has_wsync(mp) || xfs_has_dirsync(mp))
fs/xfs/xfs_inode.c:976: xfs_trans_set_sync(tp);
fs/xfs/xfs_inode.c-977-
--
fs/xfs/xfs_inode.c=1904=xfs_remove(
--
fs/xfs/xfs_inode.c-1968- if (xfs_has_wsync(mp) || xfs_has_dirsync(mp))
fs/xfs/xfs_inode.c:1969: xfs_trans_set_sync(tp);
fs/xfs/xfs_inode.c-1970-
--
fs/xfs/xfs_inode.c=2124=xfs_rename(
--
fs/xfs/xfs_inode.c-2341- if (xfs_has_wsync(tp->t_mountp) || xfs_has_dirsync(tp->t_mountp))
fs/xfs/xfs_inode.c:2342: xfs_trans_set_sync(tp);
fs/xfs/xfs_inode.c-2343-
--
fs/xfs/xfs_ioctl.c=609=xfs_ioctl_setattr_get_trans(
--
fs/xfs/xfs_ioctl.c-628- if (xfs_has_wsync(mp))
fs/xfs/xfs_ioctl.c:629: xfs_trans_set_sync(tp);
fs/xfs/xfs_ioctl.c-630-
--
fs/xfs/xfs_iops.c=780=xfs_setattr_nonsize(
--
fs/xfs/xfs_iops.c-866- if (xfs_has_wsync(mp))
fs/xfs/xfs_iops.c:867: xfs_trans_set_sync(tp);
fs/xfs/xfs_iops.c-868- error = xfs_trans_commit(tp);
--
fs/xfs/xfs_iops.c=909=xfs_setattr_size(
--
fs/xfs/xfs_iops.c-1118- if (xfs_has_wsync(mp))
fs/xfs/xfs_iops.c:1119: xfs_trans_set_sync(tp);
fs/xfs/xfs_iops.c-1120-
--
fs/xfs/xfs_pnfs.c=256=xfs_fs_commit_blocks(
--
fs/xfs/xfs_pnfs.c-327-
fs/xfs/xfs_pnfs.c:328: xfs_trans_set_sync(tp);
fs/xfs/xfs_pnfs.c-329- error = xfs_trans_commit(tp);
--
fs/xfs/xfs_symlink.c=84=xfs_symlink(
--
fs/xfs/xfs_symlink.c-208- if (xfs_has_wsync(mp) || xfs_has_dirsync(mp))
fs/xfs/xfs_symlink.c:209: xfs_trans_set_sync(tp);
fs/xfs/xfs_symlink.c-210-
--
fs/xfs/xfs_trans.h=125=typedef struct xfs_trans {
--
fs/xfs/xfs_trans.h-161- */
fs/xfs/xfs_trans.h:162:#define xfs_trans_set_sync(tp) ((tp)->t_flags |= XFS_TRANS_SYNC)
fs/xfs/xfs_trans.h-163-
]
|
| 28/2 |
2026/05/21 16:53 |
llm |
expert |
0m
Model:
Tokens:
input: 37044
output: 44
thoughts: 301
Thoughts: **Analyzing XFS Transaction Synchronization**
Okay, so I'm seeing that `xfs_trans_set_sync` gets called all over the place, specifically when either `wsync` or `dirsync` mount options are enabled on the filesystem. This is pretty much triggered by `xfs_has_wsync` or `xfs_has_dirsync`, meaning that if `wsync` is set β either with the `-o wsync` or just `-o sync` mount option β nearly every metadata operation will trigger this call. So, create, link, remove, rename, attribute setting β they're all in play.
The main question that jumps out is whether any of these operations are holding a buffer lock across the `xfs_trans_commit` call. That's the critical point, so I need to re-examine how those are handled. Let's dig back into `xfs_trans_bhold`.
Right, `xfs_trans_bhold` is called in `xfs_ag_shrink_space`, `xfs_defer_restore_resources`, `xfs_dialloc_roll`, `xfs_dquot_disk_alloc`, and `xfs_sync_sb_buf`. I need to figure out which of these are relevant. Let's see... what about `xfs_dialloc_roll`? Hmm, it's called during inode allocation.
Now, recall that `xfs_create` calls `xfs_trans_set_sync(tp)` when `wsync` is enabled. Wait a second... I remember this pattern. This `xfs_create` call happens *after* the inode allocation. This is important. Let's go back and examine `xfs_create` closely.
|
| 29/2 |
2026/05/21 16:53 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/xfs/xfs_inode.c IncludeLines:true Name:xfs_create]
Results: map[SourceCode: 647: int
648: xfs_create(
649: const struct xfs_icreate_args *args,
650: struct xfs_name *name,
651: struct xfs_inode **ipp)
652: {
653: struct xfs_inode *dp = args->pip;
654: struct xfs_dir_update du = {
655: .dp = dp,
656: .name = name,
657: };
658: struct xfs_mount *mp = dp->i_mount;
659: struct xfs_trans *tp = NULL;
660: struct xfs_dquot *udqp;
661: struct xfs_dquot *gdqp;
662: struct xfs_dquot *pdqp;
663: struct xfs_trans_res *tres;
664: xfs_ino_t ino;
665: bool unlock_dp_on_error = false;
666: bool is_dir = S_ISDIR(args->mode);
667: uint resblks;
668: int error;
669:
670: trace_xfs_create(dp, name);
671:
672: if (xfs_is_shutdown(mp))
673: return -EIO;
674: if (xfs_ifork_zapped(dp, XFS_DATA_FORK))
675: return -EIO;
676:
677: /* Make sure that we have allocated dquot(s) on disk. */
678: error = xfs_icreate_dqalloc(args, &udqp, &gdqp, &pdqp);
679: if (error)
680: return error;
681:
682: if (is_dir) {
683: resblks = xfs_mkdir_space_res(mp, name->len);
684: tres = &M_RES(mp)->tr_mkdir;
685: } else {
686: resblks = xfs_create_space_res(mp, name->len);
687: tres = &M_RES(mp)->tr_create;
688: }
689:
690: error = xfs_parent_start(mp, &du.ppargs);
691: if (error)
692: goto out_release_dquots;
693:
694: /*
695: * Initially assume that the file does not exist and
696: * reserve the resources for that case. If that is not
697: * the case we'll drop the one we have and get a more
698: * appropriate transaction later.
699: */
700: error = xfs_trans_alloc_icreate(mp, tres, udqp, gdqp, pdqp, resblks,
701: &tp);
702: if (error == -ENOSPC) {
703: /* flush outstanding delalloc blocks and retry */
704: xfs_flush_inodes(mp);
705: error = xfs_trans_alloc_icreate(mp, tres, udqp, gdqp, pdqp,
706: resblks, &tp);
707: }
708: if (error)
709: goto out_parent;
710:
711: xfs_ilock(dp, XFS_ILOCK_EXCL | XFS_ILOCK_PARENT);
712: unlock_dp_on_error = true;
713:
714: /*
715: * A newly created regular or special file just has one directory
716: * entry pointing to them, but a directory also the "." entry
717: * pointing to itself.
718: */
719: error = xfs_dialloc(&tp, args, &ino);
720: if (!error)
721: error = xfs_icreate(tp, ino, args, &du.ip);
722: if (error)
723: goto out_trans_cancel;
724:
725: /*
726: * Now we join the directory inode to the transaction. We do not do it
727: * earlier because xfs_dialloc might commit the previous transaction
728: * (and release all the locks). An error from here on will result in
729: * the transaction cancel unlocking dp so don't do it explicitly in the
730: * error path.
731: */
732: xfs_trans_ijoin(tp, dp, 0);
733:
734: error = xfs_dir_create_child(tp, resblks, &du);
735: if (error)
736: goto out_trans_cancel;
737:
738: /*
739: * If this is a synchronous mount, make sure that the
740: * create transaction goes to disk before returning to
741: * the user.
742: */
743: if (xfs_has_wsync(mp) || xfs_has_dirsync(mp))
744: xfs_trans_set_sync(tp);
745:
746: /*
747: * Attach the dquot(s) to the inodes and modify them incore.
748: * These ids of the inode couldn't have changed since the new
749: * inode has been locked ever since it was created.
750: */
751: xfs_qm_vop_create_dqattach(tp, du.ip, udqp, gdqp, pdqp);
752:
753: error = xfs_trans_commit(tp);
754: if (error)
755: goto out_release_inode;
756:
757: xfs_qm_dqrele(udqp);
758: xfs_qm_dqrele(gdqp);
759: xfs_qm_dqrele(pdqp);
760:
761: *ipp = du.ip;
762: xfs_iunlock(du.ip, XFS_ILOCK_EXCL);
763: xfs_iunlock(dp, XFS_ILOCK_EXCL);
764: xfs_parent_finish(mp, du.ppargs);
765: return 0;
766:
767: out_trans_cancel:
768: xfs_trans_cancel(tp);
769: out_release_inode:
770: /*
771: * Wait until after the current transaction is aborted to finish the
772: * setup of the inode and release the inode. This prevents recursive
773: * transactions and deadlocks from xfs_inactive.
774: */
775: if (du.ip) {
776: xfs_iunlock(du.ip, XFS_ILOCK_EXCL);
777: xfs_finish_inode_setup(du.ip);
778: xfs_irele(du.ip);
779: }
780: out_parent:
781: xfs_parent_finish(mp, du.ppargs);
782: out_release_dquots:
783: xfs_qm_dqrele(udqp);
784: xfs_qm_dqrele(gdqp);
785: xfs_qm_dqrele(pdqp);
786:
787: if (unlock_dp_on_error)
788: xfs_iunlock(dp, XFS_ILOCK_EXCL);
789: return error;
790: }
SourceFile:fs/xfs/xfs_inode.c]
|
| 30/2 |
2026/05/21 16:53 |
llm |
expert |
0m
Model:
Tokens:
input: 40038
output: 52
thoughts: 171
Thoughts: **My Analysis of XFS Transaction Synchronization**
Okay, let me break down this XFS code path. I'm focusing on the interaction between allocation and transaction handling during file creation, specifically around `xfs_create`. My thinking is: within `xfs_create`, we have `xfs_dialloc` being called, which might trigger `xfs_dialloc_roll`, which in turn calls `xfs_trans_roll`. The critical point here is what `xfs_trans_roll` does. It *commits* the current transaction and *starts* a new one.
But, and this is the crux of the issue, `xfs_trans_set_sync` hasn't been called *yet* at this point! It's happening later, all the way down at line 744, which is *after* `xfs_dialloc` has been completed. This means that when `xfs_dialloc_roll` is invoked, it's NOT committing a synchronous transaction. Consequently, it's *not* waiting on that `ic_force_wait` variable while it's holding the buffer lock. That's a fundamental difference in behavior I need to keep in mind.
I'm starting to understand this area, but now, what about `xfs_ag_shrink_space`? This needs to be considered in the overall picture, given this new insight into transaction synchronization.
|
| 31/2 |
2026/05/21 16:53 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/xfs/libxfs/xfs_ag.c IncludeLines:true Name:xfs_ag_shrink_space]
Results: map[SourceCode: 738: int
739: xfs_ag_shrink_space(
740: struct xfs_perag *pag,
741: struct xfs_trans **tpp,
742: xfs_extlen_t delta)
743: {
744: struct xfs_mount *mp = pag_mount(pag);
745: struct xfs_alloc_arg args = {
746: .tp = *tpp,
747: .mp = mp,
748: .pag = pag,
749: .minlen = delta,
750: .maxlen = delta,
751: .oinfo = XFS_RMAP_OINFO_SKIP_UPDATE,
752: .resv = XFS_AG_RESV_NONE,
753: .prod = 1
754: };
755: struct xfs_buf *agibp, *agfbp;
756: struct xfs_agi *agi;
757: struct xfs_agf *agf;
758: xfs_agblock_t aglen;
759: int error, err2;
760:
761: ASSERT(pag_agno(pag) == mp->m_sb.sb_agcount - 1);
762: error = xfs_ialloc_read_agi(pag, *tpp, 0, &agibp);
763: if (error)
764: return error;
765:
766: agi = agibp->b_addr;
767:
768: error = xfs_alloc_read_agf(pag, *tpp, 0, &agfbp);
769: if (error)
770: return error;
771:
772: agf = agfbp->b_addr;
773: aglen = be32_to_cpu(agi->agi_length);
774: /* some extra paranoid checks before we shrink the ag */
775: if (XFS_IS_CORRUPT(mp, agf->agf_length != agi->agi_length)) {
776: xfs_ag_mark_sick(pag, XFS_SICK_AG_AGF);
777: return -EFSCORRUPTED;
778: }
779: if (delta >= aglen)
780: return -EINVAL;
781:
782: /*
783: * Make sure that the last inode cluster cannot overlap with the new
784: * end of the AG, even if it's sparse.
785: */
786: error = xfs_ialloc_check_shrink(pag, *tpp, agibp, aglen - delta);
787: if (error)
788: return error;
789:
790: /*
791: * Disable perag reservations so it doesn't cause the allocation request
792: * to fail. We'll reestablish reservation before we return.
793: */
794: xfs_ag_resv_free(pag);
795:
796: /* internal log shouldn't also show up in the free space btrees */
797: error = xfs_alloc_vextent_exact_bno(&args,
798: xfs_agbno_to_fsb(pag, aglen - delta));
799: if (!error && args.agbno == NULLAGBLOCK)
800: error = -ENOSPC;
801:
802: if (error) {
803: /*
804: * If extent allocation fails, need to roll the transaction to
805: * ensure that the AGFL fixup has been committed anyway.
806: *
807: * We need to hold the AGF across the roll to ensure nothing can
808: * access the AG for allocation until the shrink is fully
809: * cleaned up. And due to the resetting of the AG block
810: * reservation space needing to lock the AGI, we also have to
811: * hold that so we don't get AGI/AGF lock order inversions in
812: * the error handling path.
813: */
814: xfs_trans_bhold(*tpp, agfbp);
815: xfs_trans_bhold(*tpp, agibp);
816: err2 = xfs_trans_roll(tpp);
817: if (err2)
818: return err2;
819: xfs_trans_bjoin(*tpp, agfbp);
820: xfs_trans_bjoin(*tpp, agibp);
821: goto resv_init_out;
822: }
823:
824: /*
825: * if successfully deleted from freespace btrees, need to confirm
826: * per-AG reservation works as expected.
827: */
828: be32_add_cpu(&agi->agi_length, -delta);
829: be32_add_cpu(&agf->agf_length, -delta);
830:
831: err2 = xfs_ag_resv_init(pag, *tpp);
832: if (err2) {
833: be32_add_cpu(&agi->agi_length, delta);
834: be32_add_cpu(&agf->agf_length, delta);
835: if (err2 != -ENOSPC)
836: goto resv_err;
837:
838: err2 = xfs_free_extent_later(*tpp, args.fsbno, delta, NULL,
839: XFS_AG_RESV_NONE, XFS_FREE_EXTENT_SKIP_DISCARD);
840: if (err2)
841: goto resv_err;
842:
843: /*
844: * Roll the transaction before trying to re-init the per-ag
845: * reservation. The new transaction is clean so it will cancel
846: * without any side effects.
847: */
848: error = xfs_defer_finish(tpp);
849: if (error)
850: return error;
851:
852: error = -ENOSPC;
853: goto resv_init_out;
854: }
855:
856: /* Update perag geometry */
857: pag_group(pag)->xg_block_count -= delta;
858: __xfs_agino_range(mp, pag_group(pag)->xg_block_count, &pag->agino_min,
859: &pag->agino_max);
860:
861: xfs_ialloc_log_agi(*tpp, agibp, XFS_AGI_LENGTH);
862: xfs_alloc_log_agf(*tpp, agfbp, XFS_AGF_LENGTH);
863: return 0;
864:
865: resv_init_out:
866: err2 = xfs_ag_resv_init(pag, *tpp);
867: if (!err2)
868: return error;
869: resv_err:
870: xfs_warn(mp, "Error %d reserving per-AG metadata reserve pool.", err2);
871: xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE);
872: return err2;
873: }
SourceFile:fs/xfs/libxfs/xfs_ag.c]
|
| 32/2 |
2026/05/21 16:53 |
llm |
expert |
0m
Model:
Tokens:
input: 42799
output: 52
thoughts: 62
Thoughts: Okay, let's see, my mind is working on some XFS filesystem stuff here.
**Thinking About Filesystem Shrinking Privileges**
Right, so `xfs_ag_shrink_space` gets invoked during `xfs_growfs` when we're trying to *shrink* the filesystem. That's good to know, that the shrinking function is a child of the growing function. And the context around the root of that call is `xfs_growfs`, which we all know requires `CAP_SYS_ADMIN` privileges. Hmm, so that suggests this `xfs_ag_shrink_space` function, by inheritance, also needs those administrative privileges. Makes sense to me, we're doing some pretty serious reconfiguration work at a low level in the block device, so that's expected. Good to keep in mind, and important to document when thinking about security implications of this code. What about... hmm, the `xfs_defer_restore_resources` call? Does that require the same?
|
| 33/2 |
2026/05/21 16:53 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/xfs/libxfs/xfs_defer.c IncludeLines:true Name:xfs_defer_restore_resources]
Results: map[SourceCode: 437: /* Attach the held resources to the transaction. */
438: static void
439: xfs_defer_restore_resources(
440: struct xfs_trans *tp,
441: struct xfs_defer_resources *dres)
442: {
443: unsigned short i;
444:
445: /* Rejoin the joined inodes. */
446: for (i = 0; i < dres->dr_inos; i++)
447: xfs_trans_ijoin(tp, dres->dr_ip[i], 0);
448:
449: /* Rejoin the buffers and dirty them so the log moves forward. */
450: for (i = 0; i < dres->dr_bufs; i++) {
451: xfs_trans_bjoin(tp, dres->dr_bp[i]);
452: if (dres->dr_ordered & (1U << i))
453: xfs_trans_ordered_buf(tp, dres->dr_bp[i]);
454: xfs_trans_bhold(tp, dres->dr_bp[i]);
455: }
456: }
SourceFile:fs/xfs/libxfs/xfs_defer.c]
|
| 34/2 |
2026/05/21 16:53 |
llm |
expert |
0m
Model:
Tokens:
input: 43512
output: 53
thoughts: 52
Thoughts: Here's my understanding of the situation, given my expertise:
**Diving into the XFS Deferred Resource Handling**
Okay, so I'm looking at how XFS handles deferred resources and their restoration. The code flow seems to be that `xfs_defer_restore_resources` is the critical function here. I see it's making a call to `xfs_trans_bhold`, which makes perfect sense; it needs to hold a buffer for this operation. Now, to understand the trigger, I need to understand when this restoration is initiated. It appears to be called from `xfs_defer_finish_noroll`. Let's take a closer look at `xfs_defer_finish_noroll` to get the context. This is where the magic happens, and I want to see *why* and *when* `xfs_defer_restore_resources` gets called from there. I need the larger picture to appreciate the logic.
|
| 35/2 |
2026/05/21 16:53 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/xfs/libxfs/xfs_defer.c IncludeLines:true Name:xfs_defer_finish_noroll]
Results: map[SourceCode: 645: /*
646: * Finish all the pending work. This involves logging intent items for
647: * any work items that wandered in since the last transaction roll (if
648: * one has even happened), rolling the transaction, and finishing the
649: * work items in the first item on the logged-and-pending list.
650: *
651: * If an inode is provided, relog it to the new transaction.
652: */
653: int
654: xfs_defer_finish_noroll(
655: struct xfs_trans **tp)
656: {
657: struct xfs_defer_pending *dfp = NULL;
658: int error = 0;
659: LIST_HEAD(dop_pending);
660: LIST_HEAD(dop_paused);
661:
662: ASSERT((*tp)->t_flags & XFS_TRANS_PERM_LOG_RES);
663:
664: trace_xfs_defer_finish(*tp, _RET_IP_);
665:
666: /* Until we run out of pending work to finish... */
667: while (!list_empty(&dop_pending) || !list_empty(&(*tp)->t_dfops)) {
668: /*
669: * Deferred items that are created in the process of finishing
670: * other deferred work items should be queued at the head of
671: * the pending list, which puts them ahead of the deferred work
672: * that was created by the caller. This keeps the number of
673: * pending work items to a minimum, which decreases the amount
674: * of time that any one intent item can stick around in memory,
675: * pinning the log tail.
676: */
677: int has_intents = xfs_defer_create_intents(*tp);
678:
679: xfs_defer_isolate_paused(*tp, &dop_paused);
680:
681: list_splice_init(&(*tp)->t_dfops, &dop_pending);
682:
683: if (has_intents < 0) {
684: error = has_intents;
685: goto out_shutdown;
686: }
687: if (has_intents || dfp) {
688: error = xfs_defer_trans_roll(tp);
689: if (error)
690: goto out_shutdown;
691:
692: /* Relog intent items to keep the log moving. */
693: xfs_defer_relog(tp, &dop_pending);
694: xfs_defer_relog(tp, &dop_paused);
695:
696: if ((*tp)->t_flags & XFS_TRANS_DIRTY) {
697: error = xfs_defer_trans_roll(tp);
698: if (error)
699: goto out_shutdown;
700: }
701: }
702:
703: dfp = list_first_entry_or_null(&dop_pending,
704: struct xfs_defer_pending, dfp_list);
705: if (!dfp)
706: break;
707: error = xfs_defer_finish_one(*tp, dfp);
708: if (error && error != -EAGAIN)
709: goto out_shutdown;
710: }
711:
712: /* Requeue the paused items in the outgoing transaction. */
713: list_splice_tail_init(&dop_paused, &(*tp)->t_dfops);
714:
715: trace_xfs_defer_finish_done(*tp, _RET_IP_);
716: return 0;
717:
718: out_shutdown:
719: list_splice_tail_init(&dop_paused, &dop_pending);
720: xfs_defer_trans_abort(*tp, &dop_pending);
721: xfs_force_shutdown((*tp)->t_mountp, SHUTDOWN_CORRUPT_INCORE);
722: trace_xfs_defer_finish_error(*tp, error);
723: xfs_defer_cancel_list((*tp)->t_mountp, &dop_pending);
724: xfs_defer_cancel(*tp);
725: return error;
726: }
SourceFile:fs/xfs/libxfs/xfs_defer.c]
|
| 36/2 |
2026/05/21 16:53 |
llm |
expert |
0m
Model:
Tokens:
input: 45162
output: 52
thoughts: 23
Thoughts: Okay, here's my interpretation of that.
**Analyzing the Call Hierarchy in XFS Restoration**
Right, so I'm looking at this `xfs_defer_restore_resources` function. My initial thought is to understand where it fits within the larger picture of an XFS file system restore operation. The text tells me it's called from `xfs_defer_trans_roll`. This immediately tells me something significant. It's not a standalone function triggered directly, but rather, it's a component in a chained process related to deferred transaction handling. This likely means we're dealing with either a delayed commitment or a resource reclamation phase following a failure or some state change. I need to dig deeper into `xfs_defer_trans_roll` to see the context in which it calls `xfs_defer_restore_resources`. The fact that it's "deferred" implies that this isn't the primary immediate action, but a delayed clean-up step perhaps? I need to understand what "resources" are being restored and in what sense. Are we talking about inodes, blocks, or journal entries? Understanding the nature of the resources is the key to appreciating the purpose of this operation. Knowing this call order gives me a clear starting point for tracing the code flow and figuring out how XFS ensures data consistency during restore and recovery. This is good; I can start narrowing my investigation now.
|
| 37/2 |
2026/05/21 16:53 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/xfs/libxfs/xfs_defer.c IncludeLines:true Name:xfs_defer_trans_roll]
Results: map[SourceCode: 458: /* Roll a transaction so we can do some deferred op processing. */
459: STATIC int
460: xfs_defer_trans_roll(
461: struct xfs_trans **tpp)
462: {
463: struct xfs_defer_resources dres = { };
464: int error;
465:
466: error = xfs_defer_save_resources(&dres, *tpp);
467: if (error)
468: return error;
469:
470: trace_xfs_defer_trans_roll(*tpp, _RET_IP_);
471:
472: /*
473: * Roll the transaction. Rolling always given a new transaction (even
474: * if committing the old one fails!) to hand back to the caller, so we
475: * join the held resources to the new transaction so that we always
476: * return with the held resources joined to @tpp, no matter what
477: * happened.
478: */
479: error = xfs_trans_roll(tpp);
480:
481: xfs_defer_restore_resources(*tpp, &dres);
482:
483: if (error)
484: trace_xfs_defer_trans_roll_error(*tpp, error);
485: return error;
486: }
SourceFile:fs/xfs/libxfs/xfs_defer.c]
|
| 38/2 |
2026/05/21 16:53 |
llm |
expert |
0m
Model:
Tokens:
input: 45987
output: 46
thoughts: 157
Thoughts: **Analyzing the xfs_defer_trans_roll Sequence**
Okay, so `xfs_defer_trans_roll` seems to kick off this rather interesting transaction management sequence. It calls `xfs_trans_roll`, which then hands off to `xfs_defer_restore_resources`. The critical point here is that `xfs_defer_restore_resources` then calls `xfs_trans_bhold` on the *new* transaction. This tells me that the buffer's going to be held across the *next* commit, which is a bit unusual, but potentially efficient for certain workloads.
My immediate question is: does `xfs_defer_trans_roll` introduce a wait state for log writing? `xfs_trans_roll` commits the *current* transaction. If that transaction happens to have `XFS_TRANS_SYNC` set, it *will* wait for the log to be written before proceeding, which would be expected behavior to maintain data integrity.
However, here's where it gets interesting... or possibly problematic. I recall that `xfs_trans_roll` explicitly *clears* `XFS_TRANS_SYNC` on the new transaction. This could have performance implications if the new transaction is then allowed to proceed without a prior log flush. I need to refresh my memory on the rationale for that, so I'm going to double check the code of `xfs_trans_roll` to ensure I have all the facts.
|
| 39/2 |
2026/05/21 16:53 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/xfs/xfs_trans.c IncludeLines:true Name:xfs_trans_roll]
Results: map[SourceCode: 998: /*
999: * Roll from one trans in the sequence of PERMANENT transactions to the next:
1000: * permanent transactions are only flushed out when committed with
1001: * xfs_trans_commit(), but we still want as soon as possible to let chunks of it
1002: * go to the log. So we commit the chunk we've been working on and get a new
1003: * transaction to continue.
1004: */
1005: int
1006: xfs_trans_roll(
1007: struct xfs_trans **tpp)
1008: {
1009: struct xfs_trans *tp = *tpp;
1010: unsigned int log_res = tp->t_log_res;
1011: unsigned int log_count = tp->t_log_count;
1012: int error;
1013:
1014: trace_xfs_trans_roll(tp, _RET_IP_);
1015:
1016: ASSERT(log_res > 0);
1017:
1018: /*
1019: * Copy the critical parameters from one trans to the next.
1020: */
1021: *tpp = xfs_trans_dup(tp);
1022:
1023: /*
1024: * Commit the current transaction.
1025: *
1026: * If this commit failed, then it'd just unlock those items that are not
1027: * marked ihold. That also means that a filesystem shutdown is in
1028: * progress. The caller takes the responsibility to cancel the
1029: * duplicate transaction that gets returned.
1030: */
1031: error = __xfs_trans_commit(tp, true);
1032: if (error)
1033: return error;
1034:
1035: /*
1036: * Reserve space in the log for the next transaction.
1037: *
1038: * This also pushes items in the AIL out to disk if they are taking up
1039: * space at the tail of the log that we want to use. This requires that
1040: * either nothing be locked across this call, or that anything that is
1041: * locked be logged in the prior and the next transactions.
1042: */
1043: tp = *tpp;
1044: /*
1045: * __xfs_trans_commit cleared the NOFS flag by calling into
1046: * xfs_trans_free. Set it again here before doing memory
1047: * allocations.
1048: */
1049: xfs_trans_set_context(tp);
1050: error = xfs_log_regrant(tp->t_mountp, tp->t_ticket);
1051: if (error)
1052: return error;
1053: tp->t_log_res = log_res;
1054: tp->t_log_count = log_count;
1055: return 0;
1056: }
SourceFile:fs/xfs/xfs_trans.c]
|
| 40/2 |
2026/05/21 16:53 |
llm |
expert |
0m
Model:
Tokens:
input: 47413
output: 46
thoughts: 24
Thoughts: Okay, here's my interpretation of that thought process, assuming I'm an XFS kernel expert:
**Transaction Duplication Deep Dive**
Alright, let's see... `xfs_trans_dup`. Right, that's the function for duplicating a transaction. The core question I'm immediately asking myself is: does that duplication process preserve all the original transaction's attributes? Specifically, does the duplication also copy over the `XFS_TRANS_SYNC` flag? That's a crucial detail. Preserving that flag is critical for ensuring data integrity and consistency, especially when dealing with crash recovery scenarios. If it *doesn't* copy the sync flag, we could introduce subtle, and potentially disastrous, data corruption issues down the line. I need to know how the flag behaves in the duplication process. So, how's this flag handled on duplicate?
|
| 41/2 |
2026/05/21 16:53 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/xfs/xfs_trans.c IncludeLines:true Name:xfs_trans_dup]
Results: map[SourceCode: 82: /*
83: * This is called to create a new transaction which will share the
84: * permanent log reservation of the given transaction. The remaining
85: * unused block and rt extent reservations are also inherited. This
86: * implies that the original transaction is no longer allowed to allocate
87: * blocks. Locks and log items, however, are no inherited. They must
88: * be added to the new transaction explicitly.
89: */
90: STATIC struct xfs_trans *
91: xfs_trans_dup(
92: struct xfs_trans *tp)
93: {
94: struct xfs_trans *ntp;
95:
96: trace_xfs_trans_dup(tp, _RET_IP_);
97:
98: ntp = kmem_cache_zalloc(xfs_trans_cache, GFP_KERNEL | __GFP_NOFAIL);
99:
100: /*
101: * Initialize the new transaction structure.
102: */
103: ntp->t_mountp = tp->t_mountp;
104: INIT_LIST_HEAD(&ntp->t_items);
105: INIT_LIST_HEAD(&ntp->t_busy);
106: INIT_LIST_HEAD(&ntp->t_dfops);
107: ntp->t_highest_agno = NULLAGNUMBER;
108:
109: ASSERT(tp->t_flags & XFS_TRANS_PERM_LOG_RES);
110: ASSERT(tp->t_ticket != NULL);
111:
112: ntp->t_flags = XFS_TRANS_PERM_LOG_RES |
113: (tp->t_flags & XFS_TRANS_RESERVE) |
114: (tp->t_flags & XFS_TRANS_NO_WRITECOUNT) |
115: (tp->t_flags & XFS_TRANS_RES_FDBLKS);
116: /* We gave our writer reference to the new transaction */
117: tp->t_flags |= XFS_TRANS_NO_WRITECOUNT;
118: ntp->t_ticket = xfs_log_ticket_get(tp->t_ticket);
119:
120: ASSERT(tp->t_blk_res >= tp->t_blk_res_used);
121: ntp->t_blk_res = tp->t_blk_res - tp->t_blk_res_used;
122: tp->t_blk_res = tp->t_blk_res_used;
123:
124: ntp->t_rtx_res = tp->t_rtx_res - tp->t_rtx_res_used;
125: tp->t_rtx_res = tp->t_rtx_res_used;
126:
127: /* move deferred ops over to the new tp */
128: xfs_defer_move(ntp, tp);
129:
130: xfs_trans_dup_dqinfo(tp, ntp);
131: return ntp;
132: }
SourceFile:fs/xfs/xfs_trans.c]
|
| 42/2 |
2026/05/21 16:53 |
llm |
expert |
0m
Model:
Tokens:
input: 48584
output: 47
thoughts: 117
Thoughts: **Transaction Duplication and Synchronization: A Deep Dive**
Okay, so `xfs_trans_dup` doesn't replicate the `XFS_TRANS_SYNC` flag. That's a key observation. This means the new transaction I'm creating won't inherently be synchronous. But what about the *original* transaction? That's the critical question here. If the original transaction *does* have the sync flag set, then when I commit it via `__xfs_trans_commit(tp, true)`, I'm going to be forced to wait for the log. Now, I need to check something: The call to `__xfs_trans_commit` includes `regrant = true`. I need to understand that fully. Time to dive into the `__xfs_trans_commit` function itself and see what's going on with that `regrant` parameter.
|
| 43/2 |
2026/05/21 16:53 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/xfs/xfs_trans.c IncludeLines:true Name:__xfs_trans_commit]
Results: map[SourceCode: 808: /*
809: * Commit the given transaction to the log.
810: *
811: * XFS disk error handling mechanism is not based on a typical
812: * transaction abort mechanism. Logically after the filesystem
813: * gets marked 'SHUTDOWN', we can't let any new transactions
814: * be durable - ie. committed to disk - because some metadata might
815: * be inconsistent. In such cases, this returns an error, and the
816: * caller may assume that all locked objects joined to the transaction
817: * have already been unlocked as if the commit had succeeded.
818: * Do not reference the transaction structure after this call.
819: */
820: static int
821: __xfs_trans_commit(
822: struct xfs_trans *tp,
823: bool regrant)
824: {
825: struct xfs_mount *mp = tp->t_mountp;
826: struct xlog *log = mp->m_log;
827: xfs_csn_t commit_seq = 0;
828: int error = 0;
829: int sync = tp->t_flags & XFS_TRANS_SYNC;
830:
831: trace_xfs_trans_commit(tp, _RET_IP_);
832:
833: /*
834: * Commit per-transaction changes that are not already tracked through
835: * log items. This can add dirty log items to the transaction.
836: */
837: if (tp->t_flags & XFS_TRANS_SB_DIRTY)
838: xfs_trans_apply_sb_deltas(tp);
839: xfs_trans_apply_dquot_deltas(tp);
840:
841: error = xfs_trans_run_precommits(tp);
842: if (error)
843: goto out_unreserve;
844:
845: /*
846: * If there is nothing to be logged by the transaction,
847: * then unlock all of the items associated with the
848: * transaction and free the transaction structure.
849: * Also make sure to return any reserved blocks to
850: * the free pool.
851: */
852: if (!(tp->t_flags & XFS_TRANS_DIRTY))
853: goto out_unreserve;
854:
855: /*
856: * We must check against log shutdown here because we cannot abort log
857: * items and leave them dirty, inconsistent and unpinned in memory while
858: * the log is active. This leaves them open to being written back to
859: * disk, and that will lead to on-disk corruption.
860: */
861: if (xlog_is_shutdown(log)) {
862: error = -EIO;
863: goto out_unreserve;
864: }
865:
866: ASSERT(tp->t_ticket != NULL);
867:
868: xlog_cil_commit(log, tp, &commit_seq, regrant);
869:
870: xfs_trans_free(tp);
871:
872: /*
873: * If the transaction needs to be synchronous, then force the
874: * log out now and wait for it.
875: */
876: if (sync) {
877: error = xfs_log_force_seq(mp, commit_seq, XFS_LOG_SYNC, NULL);
878: XFS_STATS_INC(mp, xs_trans_sync);
879: } else {
880: XFS_STATS_INC(mp, xs_trans_async);
881: }
882:
883: return error;
884:
885: out_unreserve:
886: xfs_trans_unreserve_and_mod_sb(tp);
887:
888: /*
889: * It is indeed possible for the transaction to be not dirty but
890: * the dqinfo portion to be. All that means is that we have some
891: * (non-persistent) quota reservations that need to be unreserved.
892: */
893: xfs_trans_unreserve_and_mod_dquots(tp, true);
894: if (tp->t_ticket) {
895: if (regrant && !xlog_is_shutdown(log))
896: xfs_log_ticket_regrant(log, tp->t_ticket);
897: else
898: xfs_log_ticket_ungrant(log, tp->t_ticket);
899: tp->t_ticket = NULL;
900: }
901: xfs_trans_free_items(tp, !!error);
902: xfs_trans_free(tp);
903:
904: XFS_STATS_INC(mp, xs_trans_empty);
905: return error;
906: }
SourceFile:fs/xfs/xfs_trans.c]
|
| 44/2 |
2026/05/21 16:53 |
llm |
expert |
0m
Model:
Tokens:
input: 50468
output: 52
thoughts: 460
Thoughts: **Analyzing Transaction Synchronization in XFS**
Okay, let me break this down. If the `sync` flag is true, we call `xfs_log_force_seq`. Now, the important question is whether that call actually waits for the log to flush. The code says it does β `XFS_LOG_SYNC` indicates a wait. So, if `XFS_TRANS_SYNC` is set on an *old* transaction, then `xfs_trans_roll` will indeed wait for the log to complete.
But there's a wrinkle here. I need to consider `xfs_defer_trans_roll`, which is called from `xfs_defer_finish_noroll`. The critical point is: Does the transaction passed to `xfs_defer_finish_noroll` have `XFS_TRANS_SYNC` enabled? If it does, then the subsequent `xfs_defer_trans_roll` will also wait for the log.
Now, here's where it gets interesting. `xfs_defer_trans_roll` calls `xfs_defer_save_resources` *before* it calls `xfs_trans_roll`. The question that springs to mind immediately is, does `xfs_defer_save_resources` actually hold the buffers? I am pretty sure it does not, I believe it only records them, making them available later. That makes sense. `xfs_trans_roll` handles the real commit of the transaction.
Alright, so the commit involves `__xfs_trans_commit`, which then calls `xlog_cil_commit`, and I am immediately thinking about buffer unpinning at this point. Does `xlog_cil_commit` unpin the buffers? No, it just *adds* the items to the CIL; the buffers are still pinned at this point. The next question is, what unpins the buffers? `__xfs_trans_commit` calls `xfs_trans_free(tp)`, which then calls `xfs_trans_free_items(tp, false)`.
But wait. `xlog_cil_commit` is the point where the transaction's items are moved to the CIL. So, are the buffers unlocked by `xlog_cil_commit`? No, it unlocks the items that are not marked `ihold` or `bhold`. That's the important distinction. Items with `bhold` are not unlocked by `xlog_cil_commit`. So, does `xfs_defer_save_resources` set `bhold`? No, I am pretty sure it does not.
To confirm this, I need to check the implementation of `xfs_defer_save_resources` very carefully. This seems to be the critical point where the buffer pinning/unpinning behavior is determined in this deferred transaction scenario. I need to be sure on this.
|
| 45/2 |
2026/05/21 16:53 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/xfs/libxfs/xfs_defer.c IncludeLines:true Name:xfs_defer_save_resources]
Results: map[SourceCode: 383: /*
384: * Capture resources that the caller said not to release ("held") when the
385: * transaction commits. Caller is responsible for zero-initializing @dres.
386: */
387: static int
388: xfs_defer_save_resources(
389: struct xfs_defer_resources *dres,
390: struct xfs_trans *tp)
391: {
392: struct xfs_buf_log_item *bli;
393: struct xfs_inode_log_item *ili;
394: struct xfs_log_item *lip;
395:
396: BUILD_BUG_ON(NBBY * sizeof(dres->dr_ordered) < XFS_DEFER_OPS_NR_BUFS);
397:
398: list_for_each_entry(lip, &tp->t_items, li_trans) {
399: switch (lip->li_type) {
400: case XFS_LI_BUF:
401: bli = container_of(lip, struct xfs_buf_log_item,
402: bli_item);
403: if (bli->bli_flags & XFS_BLI_HOLD) {
404: if (dres->dr_bufs >= XFS_DEFER_OPS_NR_BUFS) {
405: ASSERT(0);
406: return -EFSCORRUPTED;
407: }
408: if (bli->bli_flags & XFS_BLI_ORDERED)
409: dres->dr_ordered |=
410: (1U << dres->dr_bufs);
411: else
412: xfs_trans_dirty_buf(tp, bli->bli_buf);
413: dres->dr_bp[dres->dr_bufs++] = bli->bli_buf;
414: }
415: break;
416: case XFS_LI_INODE:
417: ili = container_of(lip, struct xfs_inode_log_item,
418: ili_item);
419: if (ili->ili_lock_flags == 0) {
420: if (dres->dr_inos >= XFS_DEFER_OPS_NR_INODES) {
421: ASSERT(0);
422: return -EFSCORRUPTED;
423: }
424: xfs_trans_log_inode(tp, ili->ili_inode,
425: XFS_ILOG_CORE);
426: dres->dr_ip[dres->dr_inos++] = ili->ili_inode;
427: }
428: break;
429: default:
430: break;
431: }
432: }
433:
434: return 0;
435: }
SourceFile:fs/xfs/libxfs/xfs_defer.c]
|
| 46/2 |
2026/05/21 16:53 |
llm |
expert |
0m
Model:
Tokens:
input: 52476
output: 48
thoughts: 383
Thoughts: **Deadlock Detected: XFS Transactional Logic Analysis**
Okay, here's what's hitting me. I'm seeing a potential deadlock condition within the XFS filesystem code, and I'm tracing the likely sequence. It starts with `xfs_defer_save_resources` checking for `XFS_BLI_HOLD`. If that flag is set, it holds the buffer. Fine. Then, `xfs_trans_roll` commits the transaction. The critical point is that because `XFS_BLI_HOLD` is set, the usual `xlog_cil_commit` isn't going to unlock the buffer immediately.
Next, `__xfs_trans_commit` comes into play and, if `XFS_TRANS_SYNC` is active, it calls `xfs_log_force_seq`. This call, in turn, blocks and waits for the log to actually be written to disk. And that's where the problem crystallizes: a transaction with `XFS_TRANS_SYNC` and a buffer *also* held with `XFS_BLI_HOLD` will block waiting for the log *while still holding the buffer lock*. Bingo! That's the textbook deadlock scenario.
So, the next question becomes: when do we see transactions with both `XFS_TRANS_SYNC` and a held buffer? I need to find the specific code path. Let's start by looking at the callers of `xfs_defer_finish_noroll`, since it's involved in this buffer hold. Okay, it's called from `xfs_defer_finish`, which, as I suspected, has a number of callers. Hmmm, digging deeper here. I see `xfs_itruncate_extents_flags` calls `xfs_defer_finish`. Thatβs interesting. And I'm starting to think about whether the flags set in `xfs_itruncate_extents_flags` could cause that scenario.
Aha! `xfs_setattr_size` calls `xfs_itruncate_extents_flags`. My next point to investigate now is whether `xfs_setattr_size` sets `XFS_TRANS_SYNC`. If so, we may have the smoking gun. I need to examine the implementation of `xfs_setattr_size`.
|
| 47/2 |
2026/05/21 16:54 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/xfs/xfs_iops.c IncludeLines:true Name:xfs_setattr_size]
Results: map[SourceCode: 902: /*
903: * Truncate file. Must have write permission and not be a directory.
904: *
905: * Caution: The caller of this function is responsible for calling
906: * setattr_prepare() or otherwise verifying the change is fine.
907: */
908: STATIC int
909: xfs_setattr_size(
910: struct mnt_idmap *idmap,
911: struct dentry *dentry,
912: struct xfs_inode *ip,
913: struct iattr *iattr)
914: {
915: struct xfs_mount *mp = ip->i_mount;
916: struct inode *inode = VFS_I(ip);
917: xfs_off_t oldsize, newsize;
918: struct xfs_trans *tp;
919: int error;
920: uint lock_flags = 0;
921: uint resblks = 0;
922: bool did_zeroing = false;
923: struct xfs_zone_alloc_ctx ac = { };
924:
925: xfs_assert_ilocked(ip, XFS_IOLOCK_EXCL | XFS_MMAPLOCK_EXCL);
926: ASSERT(S_ISREG(inode->i_mode));
927: ASSERT((iattr->ia_valid & (ATTR_UID|ATTR_GID|ATTR_ATIME|ATTR_ATIME_SET|
928: ATTR_MTIME_SET|ATTR_TIMES_SET)) == 0);
929:
930: oldsize = inode->i_size;
931: newsize = iattr->ia_size;
932:
933: /*
934: * Short circuit the truncate case for zero length files.
935: */
936: if (newsize == 0 && oldsize == 0 && ip->i_df.if_nextents == 0) {
937: if (!(iattr->ia_valid & (ATTR_CTIME|ATTR_MTIME)))
938: return 0;
939:
940: /*
941: * Use the regular setattr path to update the timestamps.
942: */
943: iattr->ia_valid &= ~ATTR_SIZE;
944: return xfs_setattr_nonsize(idmap, dentry, ip, iattr);
945: }
946:
947: /*
948: * Make sure that the dquots are attached to the inode.
949: */
950: error = xfs_qm_dqattach(ip);
951: if (error)
952: return error;
953:
954: /*
955: * Wait for all direct I/O to complete.
956: */
957: inode_dio_wait(inode);
958:
959: /*
960: * Normally xfs_zoned_space_reserve is supposed to be called outside the
961: * IOLOCK. For truncate we can't do that since ->setattr is called with
962: * it already held by the VFS. So for now chicken out and try to
963: * allocate space under it.
964: *
965: * To avoid deadlocks this means we can't block waiting for space, which
966: * can lead to spurious -ENOSPC if there are no directly available
967: * blocks. We mitigate this a bit by allowing zeroing to dip into the
968: * reserved pool, but eventually the VFS calling convention needs to
969: * change.
970: */
971: if (xfs_is_zoned_inode(ip)) {
972: error = xfs_zoned_space_reserve(mp, 1,
973: XFS_ZR_NOWAIT | XFS_ZR_RESERVED, &ac);
974: if (error) {
975: if (error == -EAGAIN)
976: return -ENOSPC;
977: return error;
978: }
979: }
980:
981: /*
982: * File data changes must be complete before we start the transaction to
983: * modify the inode. This needs to be done before joining the inode to
984: * the transaction because the inode cannot be unlocked once it is a
985: * part of the transaction.
986: *
987: * Start with zeroing any data beyond EOF that we may expose on file
988: * extension, or zeroing out the rest of the block on a downward
989: * truncate.
990: */
991: if (newsize > oldsize) {
992: trace_xfs_zero_eof(ip, oldsize, newsize - oldsize);
993: error = xfs_zero_range(ip, oldsize, newsize - oldsize,
994: &ac, &did_zeroing);
995: } else {
996: error = xfs_truncate_page(ip, newsize, &ac, &did_zeroing);
997: }
998:
999: if (xfs_is_zoned_inode(ip))
1000: xfs_zoned_space_unreserve(mp, &ac);
1001:
1002: if (error)
1003: return error;
1004:
1005: /*
1006: * We've already locked out new page faults, so now we can safely remove
1007: * pages from the page cache knowing they won't get refaulted until we
1008: * drop the XFS_MMAP_EXCL lock after the extent manipulations are
1009: * complete. The truncate_setsize() call also cleans partial EOF page
1010: * PTEs on extending truncates and hence ensures sub-page block size
1011: * filesystems are correctly handled, too.
1012: *
1013: * We have to do all the page cache truncate work outside the
1014: * transaction context as the "lock" order is page lock->log space
1015: * reservation as defined by extent allocation in the writeback path.
1016: * Hence a truncate can fail with ENOMEM from xfs_trans_alloc(), but
1017: * having already truncated the in-memory version of the file (i.e. made
1018: * user visible changes). There's not much we can do about this, except
1019: * to hope that the caller sees ENOMEM and retries the truncate
1020: * operation.
1021: *
1022: * And we update in-core i_size and truncate page cache beyond newsize
1023: * before writeback the [i_disk_size, newsize] range, so we're
1024: * guaranteed not to write stale data past the new EOF on truncate down.
1025: */
1026: truncate_setsize(inode, newsize);
1027:
1028: /*
1029: * We are going to log the inode size change in this transaction so
1030: * any previous writes that are beyond the on disk EOF and the new
1031: * EOF that have not been written out need to be written here. If we
1032: * do not write the data out, we expose ourselves to the null files
1033: * problem. Note that this includes any block zeroing we did above;
1034: * otherwise those blocks may not be zeroed after a crash.
1035: */
1036: if (did_zeroing ||
1037: (newsize > ip->i_disk_size && oldsize != ip->i_disk_size)) {
1038: error = filemap_write_and_wait_range(VFS_I(ip)->i_mapping,
1039: ip->i_disk_size, newsize - 1);
1040: if (error)
1041: return error;
1042: }
1043:
1044: /*
1045: * For realtime inode with more than one block rtextsize, we need the
1046: * block reservation for bmap btree block allocations/splits that can
1047: * happen since it could split the tail written extent and convert the
1048: * right beyond EOF one to unwritten.
1049: */
1050: if (xfs_inode_has_bigrtalloc(ip))
1051: resblks = XFS_DIOSTRAT_SPACE_RES(mp, 0);
1052:
1053: error = xfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate, resblks,
1054: 0, 0, &tp);
1055: if (error)
1056: return error;
1057:
1058: lock_flags |= XFS_ILOCK_EXCL;
1059: xfs_ilock(ip, XFS_ILOCK_EXCL);
1060: xfs_trans_ijoin(tp, ip, 0);
1061:
1062: /*
1063: * Only change the c/mtime if we are changing the size or we are
1064: * explicitly asked to change it. This handles the semantic difference
1065: * between truncate() and ftruncate() as implemented in the VFS.
1066: *
1067: * The regular truncate() case without ATTR_CTIME and ATTR_MTIME is a
1068: * special case where we need to update the times despite not having
1069: * these flags set. For all other operations the VFS set these flags
1070: * explicitly if it wants a timestamp update.
1071: */
1072: if (newsize != oldsize &&
1073: !(iattr->ia_valid & (ATTR_CTIME | ATTR_MTIME))) {
1074: iattr->ia_ctime = iattr->ia_mtime =
1075: current_time(inode);
1076: iattr->ia_valid |= ATTR_CTIME | ATTR_MTIME;
1077: }
1078:
1079: /*
1080: * The first thing we do is set the size to new_size permanently on
1081: * disk. This way we don't have to worry about anyone ever being able
1082: * to look at the data being freed even in the face of a crash.
1083: * What we're getting around here is the case where we free a block, it
1084: * is allocated to another file, it is written to, and then we crash.
1085: * If the new data gets written to the file but the log buffers
1086: * containing the free and reallocation don't, then we'd end up with
1087: * garbage in the blocks being freed. As long as we make the new size
1088: * permanent before actually freeing any blocks it doesn't matter if
1089: * they get written to.
1090: */
1091: ip->i_disk_size = newsize;
1092: xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
1093:
1094: if (newsize <= oldsize) {
1095: error = xfs_itruncate_extents(&tp, ip, XFS_DATA_FORK, newsize);
1096: if (error)
1097: goto out_trans_cancel;
1098:
1099: /*
1100: * Truncated "down", so we're removing references to old data
1101: * here - if we delay flushing for a long time, we expose
1102: * ourselves unduly to the notorious NULL files problem. So,
1103: * we mark this inode and flush it when the file is closed,
1104: * and do not wait the usual (long) time for writeout.
1105: */
1106: xfs_iflags_set(ip, XFS_ITRUNCATED);
1107:
1108: /* A truncate down always removes post-EOF blocks. */
1109: xfs_inode_clear_eofblocks_tag(ip);
1110: }
1111:
1112: ASSERT(!(iattr->ia_valid & (ATTR_UID | ATTR_GID)));
1113: setattr_copy(idmap, inode, iattr);
1114: xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
1115:
1116: XFS_STATS_INC(mp, xs_ig_attrchg);
1117:
1118: if (xfs_has_wsync(mp))
1119: xfs_trans_set_sync(tp);
1120:
1121: error = xfs_trans_commit(tp);
1122: out_unlock:
1123: if (lock_flags)
1124: xfs_iunlock(ip, lock_flags);
1125: return error;
1126:
1127: out_trans_cancel:
1128: xfs_trans_cancel(tp);
1129: goto out_unlock;
1130: }
SourceFile:fs/xfs/xfs_iops.c]
|
| 48/2 |
2026/05/21 16:54 |
llm |
expert |
0m
Model:
Tokens:
input: 57214
output: 50
thoughts: 2008
Thoughts: **Analyzing the XFS Deadlock: A Deep Dive**
Okay, let's break this down. My initial thought process was centered around `xfs_setattr_size` and whether it might be the culprit. I saw that it calls `xfs_itruncate_extents`, which, in turn, goes through `xfs_defer_finish`. My concern was that `xfs_trans_set_sync` is called *after* `xfs_itruncate_extents`, meaning that the transaction isn't forced to the log. This seemed like it *could* bypass the deadlock since the deferred transactions don't wait for the log. But I know `xfs_defer_finish` calls `xfs_defer_finish_noroll`, which loops, and that rolls the transaction which does wait for the log. So I didn't think `xfs_setattr_size` was the direct cause.
Then I examined the stack trace from the bug report for Task 1, which clearly shows the shutdown being triggered. Task 1 is deep inside `xfs_trans_read_buf_map`, which fails, likely due to a corrupted block in the malicious image, and calls `xfs_do_force_shutdown`. The critical path here is in `xfs_do_force_shutdown`, which then calls `xlog_state_shutdown_callbacks`. This is the point where things get interesting. `xlog_state_shutdown_callbacks` calls `xlog_cil_process_committed`, which tries to unpin a buffer, causing it to call `xfs_buf_lock`.
The problem is the buffer is already held by Task 2, which is in `xfs_sync_sb_buf`, called from `xfs_ioc_setlabel`. Task 2 holds the superblock buffer lock and is waiting in `xlog_wait_on_iclog`. Task 1 wants that same superblock buffer to unpin it as part of the shutdown process. The superblock buffer is in the CIL because it was modified and committed in a previous transaction, and now during shutdown, all committed items in the CIL are processed to abort them, which requires unpinning them.
The crux of the deadlock is now exposed. Task 1, performing the shutdown, needs to unpin the superblock buffer, which is in the CIL. To unpin it, `xfs_buf_lock` must be acquired. Meanwhile, Task 2 holds the lock on the superblock buffer while waiting for `ic_force_wait`. A deadlock occurs! Task 2 is blocked on `ic_force_wait`, waiting to be woken up, while Task 1 is blocked on `xfs_buf_lock`, waiting for Task 2 to release the buffer lock.
Why doesn't Task 2 wake up if the log is shut down? `xlog_state_shutdown_callbacks` executes in Task 1. But Task 1 holds the lock! No, it drops it before calling `xlog_cil_process_committed`, but it hasn't woken up `ic_force_wait` yet, so Task 2 is stuck waiting. Deadlock!
So, the deadlock conditions are clear:
1. Task 2 must hold a buffer lock and wait on `ic_force_wait`.
2. Another Task 1 triggers a shutdown while Task 2 is waiting.
3. The buffer held by Task 2 *must* be in the CIL, so Task 1 attempts to unpin it.
Task 2 is performing `xfs_sync_sb_buf`, which holds the superblock buffer lock and is waiting on `ic_force_wait`. Are there other ways to hold a buffer lock and wait on `ic_force_wait`? I recalled the callers of `xfs_trans_bhold`:
* `xfs_ag_shrink_space` (requires CAP_SYS_ADMIN)
* `xfs_defer_restore_resources` (uses deferred ops)
* `xfs_dialloc_roll` (doesn't wait on `ic_force_wait` because `XFS_TRANS_SYNC` is set later).
* `xfs_dquot_disk_alloc` (this is a good one to check).
* `xfs_sync_sb_buf` (requires CAP_SYS_ADMIN)
So, I need to check `xfs_dquot_disk_alloc` too.
|
| 49/2 |
2026/05/21 16:54 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/xfs/xfs_dquot.c IncludeLines:true Name:xfs_dquot_disk_alloc]
Results: map[SourceCode: 337: /*
338: * Ensure that the given in-core dquot has a buffer on disk backing it, and
339: * return the buffer locked and held. This is called when the bmapi finds a
340: * hole.
341: */
342: STATIC int
343: xfs_dquot_disk_alloc(
344: struct xfs_dquot *dqp,
345: struct xfs_buf **bpp)
346: {
347: struct xfs_bmbt_irec map;
348: struct xfs_trans *tp;
349: struct xfs_mount *mp = dqp->q_mount;
350: struct xfs_buf *bp;
351: xfs_dqtype_t qtype = xfs_dquot_type(dqp);
352: struct xfs_inode *quotip = xfs_quota_inode(mp, qtype);
353: int nmaps = 1;
354: int error;
355:
356: trace_xfs_dqalloc(dqp);
357:
358: error = xfs_trans_alloc(mp, &M_RES(mp)->tr_qm_dqalloc,
359: XFS_QM_DQALLOC_SPACE_RES(mp), 0, 0, &tp);
360: if (error)
361: return error;
362:
363: xfs_ilock(quotip, XFS_ILOCK_EXCL);
364: xfs_trans_ijoin(tp, quotip, 0);
365:
366: if (!xfs_this_quota_on(dqp->q_mount, qtype)) {
367: /*
368: * Return if this type of quotas is turned off while we didn't
369: * have an inode lock
370: */
371: error = -ESRCH;
372: goto err_cancel;
373: }
374:
375: error = xfs_iext_count_extend(tp, quotip, XFS_DATA_FORK,
376: XFS_IEXT_ADD_NOSPLIT_CNT);
377: if (error)
378: goto err_cancel;
379:
380: /* Create the block mapping. */
381: error = xfs_bmapi_write(tp, quotip, dqp->q_fileoffset,
382: XFS_DQUOT_CLUSTER_SIZE_FSB, XFS_BMAPI_METADATA, 0, &map,
383: &nmaps);
384: if (error)
385: goto err_cancel;
386:
387: ASSERT(map.br_blockcount == XFS_DQUOT_CLUSTER_SIZE_FSB);
388: ASSERT((map.br_startblock != DELAYSTARTBLOCK) &&
389: (map.br_startblock != HOLESTARTBLOCK));
390:
391: /*
392: * Keep track of the blkno to save a lookup later
393: */
394: dqp->q_blkno = XFS_FSB_TO_DADDR(mp, map.br_startblock);
395:
396: /* now we can just get the buffer (there's nothing to read yet) */
397: error = xfs_trans_get_buf(tp, mp->m_ddev_targp, dqp->q_blkno,
398: mp->m_quotainfo->qi_dqchunklen, 0, &bp);
399: if (error)
400: goto err_cancel;
401: bp->b_ops = &xfs_dquot_buf_ops;
402:
403: /*
404: * Make a chunk of dquots out of this buffer and log
405: * the entire thing.
406: */
407: xfs_qm_init_dquot_blk(tp, dqp->q_id, qtype, bp);
408: xfs_buf_set_ref(bp, XFS_DQUOT_REF);
409:
410: /*
411: * Hold the buffer and join it to the dfops so that we'll still own
412: * the buffer when we return to the caller. The buffer disposal on
413: * error must be paid attention to very carefully, as it has been
414: * broken since commit efa092f3d4c6 "[XFS] Fixes a bug in the quota
415: * code when allocating a new dquot record" in 2005, and the later
416: * conversion to xfs_defer_ops in commit 310a75a3c6c747 failed to keep
417: * the buffer locked across the _defer_finish call. We can now do
418: * this correctly with xfs_defer_bjoin.
419: *
420: * Above, we allocated a disk block for the dquot information and used
421: * get_buf to initialize the dquot. If the _defer_finish fails, the old
422: * transaction is gone but the new buffer is not joined or held to any
423: * transaction, so we must _buf_relse it.
424: *
425: * If everything succeeds, the caller of this function is returned a
426: * buffer that is locked and held to the transaction. The caller
427: * is responsible for unlocking any buffer passed back, either
428: * manually or by committing the transaction. On error, the buffer is
429: * released and not passed back.
430: *
431: * Keep the quota inode ILOCKed until after the transaction commit to
432: * maintain the atomicity of bmap/rmap updates.
433: */
434: xfs_trans_bhold(tp, bp);
435: error = xfs_trans_commit(tp);
436: xfs_iunlock(quotip, XFS_ILOCK_EXCL);
437: if (error) {
438: xfs_buf_relse(bp);
439: return error;
440: }
441:
442: *bpp = bp;
443: return 0;
444:
445: err_cancel:
446: xfs_trans_cancel(tp);
447: xfs_iunlock(quotip, XFS_ILOCK_EXCL);
448: return error;
449: }
SourceFile:fs/xfs/xfs_dquot.c]
|
| 50/2 |
2026/05/21 16:54 |
llm |
expert |
0m
Model:
Tokens:
input: 62184
output: 50
thoughts: 1256
Thoughts: **Analyzing a Potential XFS Deadlock**
Okay, let's break this down. My initial thought was to understand the transaction synchronization in `xfs_dquot_disk_alloc`. It seems like it calls `xfs_trans_bhold` and then `xfs_trans_commit`, which is the typical pattern. The question then is whether `XFS_TRANS_SYNC` is set, meaning waiting for the log. It turns out, no, `xfs_dquot_disk_alloc` doesn't explicitly call `xfs_trans_set_sync`. It's not immediately waiting for the log.
But, hang on, what about the `wsync` mount option? If that's enabled, does it change the behavior? No, `xfs_dquot_disk_alloc` doesn't check `xfs_has_wsync`, so that's not the trigger.
Now, a critical point: `xfs_dquot_disk_alloc` is called from `xfs_qm_dqread`, which in turn is called from `xfs_qm_dqget`. This happens during inode allocation or chown operations. If `wsync` *is* enabled, `xfs_create` sets `XFS_TRANS_SYNC` *after* inode allocation. However, `xfs_dquot_disk_alloc` creates its own independent transaction. It allocates a new transaction `tp`, commits it, and returns the buffer. Importantly, this new transaction does *not* have `XFS_TRANS_SYNC` set. So it doesn't wait for the log.
So, where *does* a buffer lock and log wait happen? Looks like `xfs_sync_sb_buf` is the only place, as it's the only place holding the buffer lock and waiting for the log. And where is `xfs_sync_sb_buf` called from? It appears that `xfs_ioc_setlabel` is the only caller. But that requires `CAP_SYS_ADMIN` in the initial user namespace.
Alright, let's explore if there are any other ways `xfs_sync_sb_buf` could be triggered. We have to check its callers. Since we've already done that and only found `xfs_ioc_setlabel` this seems unlikely.
Okay, let's broaden the search a bit. Let's look for other places that hold a buffer lock and *then* wait for the log. Is it possible for a task to acquire a buffer lock for one reason, and then call a function that forces a log flush? For example, perhaps a task reads a buffer, locks it, and then calls `xfs_log_force`? I need to look for callers of `xfs_log_force` or `xfs_log_force_seq` while holding a buffer lock. This isn't easy to statically analyze.
Aha! The syzbot reproducer! The reproducer explicitly calls `ioctl(FS_IOC_SETFSLABEL)`. The reproducer does the following: it mounts a malicious image, then opens a file, truncates the open file (triggering IO error), and *concurrently* calls `ioctl(FS_IOC_SETFSLABEL)` on that same file. This triggers a specific sequence: `xfs_ioc_setlabel` is called, which calls `xfs_sync_sb_buf`, which calls `xlog_wait_on_iclog`. This sequence perfectly matches the deadlock scenario. It also explains the stack traces.
Given that `xfs_ioc_setlabel` requires `CAP_SYS_ADMIN` in the initial user namespace, this deadlock appears to be exploitable only by a privileged user. But, is `FS_IOC_SETFSLABEL` the *only* way? What about `xfs_sync_sb` being called? `xfs_sync_sb` is called from `xfs_log_sbcount` and `xfs_unmountfs`. Does `xfs_sync_sb` hold the buffer lock? We still need to examine those call paths more closely.
|
| 51/2 |
2026/05/21 16:54 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/xfs/libxfs/xfs_sb.c IncludeLines:true Name:xfs_sync_sb]
Results: map[SourceCode:1364: /*
1365: * xfs_sync_sb
1366: *
1367: * Sync the superblock to disk.
1368: *
1369: * Note that the caller is responsible for checking the frozen state of the
1370: * filesystem. This procedure uses the non-blocking transaction allocator and
1371: * thus will allow modifications to a frozen fs. This is required because this
1372: * code can be called during the process of freezing where use of the high-level
1373: * allocator would deadlock.
1374: */
1375: int
1376: xfs_sync_sb(
1377: struct xfs_mount *mp,
1378: bool wait)
1379: {
1380: struct xfs_trans *tp;
1381: int error;
1382:
1383: error = xfs_trans_alloc(mp, &M_RES(mp)->tr_sb, 0, 0,
1384: XFS_TRANS_NO_WRITECOUNT, &tp);
1385: if (error)
1386: return error;
1387:
1388: xfs_log_sb(tp);
1389: if (wait)
1390: xfs_trans_set_sync(tp);
1391: return xfs_trans_commit(tp);
1392: }
SourceFile:fs/xfs/libxfs/xfs_sb.c]
|
| 52/2 |
2026/05/21 16:54 |
llm |
expert |
0m
Model:
Tokens:
input: 64823
output: 50
thoughts: 127
Thoughts: **Analyzing a Potential Deadlock**
Okay, so I'm trying to trace down a potential deadlock, and the initial suspect was `xfs_sync_sb`. My understanding is that it's supposed to flush the superblock, but I need to make *absolutely* certain of the details here. Thinking it through, `xfs_sync_sb` *doesn't* call `xfs_trans_bhold`, which is good. It calls `xfs_log_sb(tp)` instead. That function definitely logs the superblock, but crucially, it doesn't hold that buffer lock across the commit. So, since it doesn't hold the lock across the commit, `xfs_sync_sb` *shouldn't* be the cause of this particular deadlock scenario. We can probably rule that one out.
Alright, moving on, if it's not `xfs_sync_sb`, I need to investigate other areas. What about `xfs_fsops.c`? That feels like a logical next step. Specifically, I need to check `xfs_growfs_data_private`. I know that function calls `xfs_trans_set_sync(tp)`. But does that function also hold buffers? The devil, as always, is in the details, so I really need to drill down and examine the code within `xfs_growfs_data_private` and look for any clues. Let's see...
|
| 53/2 |
2026/05/21 16:54 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/xfs/xfs_fsops.c IncludeLines:true Name:xfs_growfs_data_private]
Results: map[SourceCode: 89: /*
90: * growfs operations
91: */
92: static int
93: xfs_growfs_data_private(
94: struct xfs_mount *mp, /* mount point for filesystem */
95: struct xfs_growfs_data *in) /* growfs data input struct */
96: {
97: xfs_agnumber_t oagcount = mp->m_sb.sb_agcount;
98: xfs_rfsblock_t nb = in->newblocks;
99: struct xfs_buf *bp;
100: int error;
101: xfs_agnumber_t nagcount;
102: xfs_agnumber_t nagimax = 0;
103: int64_t delta;
104: bool lastag_extended = false;
105: struct xfs_trans *tp;
106: struct aghdr_init_data id = {};
107: struct xfs_perag *last_pag;
108:
109: error = xfs_sb_validate_fsb_count(&mp->m_sb, nb);
110: if (error)
111: return error;
112:
113: if (nb > mp->m_sb.sb_dblocks) {
114: error = xfs_buf_read_uncached(mp->m_ddev_targp,
115: XFS_FSB_TO_BB(mp, nb) - XFS_FSS_TO_BB(mp, 1),
116: XFS_FSS_TO_BB(mp, 1), &bp, NULL);
117: if (error)
118: return error;
119: xfs_buf_relse(bp);
120: }
121:
122: /* Make sure the new fs size won't cause problems with the log. */
123: error = xfs_growfs_check_rtgeom(mp, nb, mp->m_sb.sb_rblocks,
124: mp->m_sb.sb_rextsize);
125: if (error)
126: return error;
127: xfs_growfs_compute_deltas(mp, nb, &delta, &nagcount);
128:
129: /*
130: * Reject filesystems with a single AG because they are not
131: * supported, and reject a shrink operation that would cause a
132: * filesystem to become unsupported.
133: */
134: if (delta < 0 && nagcount < 2)
135: return -EINVAL;
136:
137: /* No work to do */
138: if (delta == 0)
139: return 0;
140:
141: /* TODO: shrinking the entire AGs hasn't yet completed */
142: if (nagcount < oagcount)
143: return -EINVAL;
144:
145: /* allocate the new per-ag structures */
146: error = xfs_initialize_perag(mp, oagcount, nagcount, nb, &nagimax);
147: if (error)
148: return error;
149:
150: if (delta > 0)
151: error = xfs_trans_alloc(mp, &M_RES(mp)->tr_growdata,
152: XFS_GROWFS_SPACE_RES(mp), 0, XFS_TRANS_RESERVE,
153: &tp);
154: else
155: error = xfs_trans_alloc(mp, &M_RES(mp)->tr_growdata, -delta, 0,
156: 0, &tp);
157: if (error)
158: goto out_free_unused_perag;
159:
160: last_pag = xfs_perag_get(mp, oagcount - 1);
161: if (delta > 0) {
162: error = xfs_resizefs_init_new_ags(tp, &id, oagcount, nagcount,
163: delta, last_pag, &lastag_extended);
164: } else {
165: xfs_warn_experimental(mp, XFS_EXPERIMENTAL_SHRINK);
166: error = xfs_ag_shrink_space(last_pag, &tp, -delta);
167: }
168: xfs_perag_put(last_pag);
169: if (error)
170: goto out_trans_cancel;
171:
172: /*
173: * Update changed superblock fields transactionally. These are not
174: * seen by the rest of the world until the transaction commit applies
175: * them atomically to the superblock.
176: */
177: if (nagcount > oagcount)
178: xfs_trans_mod_sb(tp, XFS_TRANS_SB_AGCOUNT, nagcount - oagcount);
179: if (delta)
180: xfs_trans_mod_sb(tp, XFS_TRANS_SB_DBLOCKS, delta);
181: if (id.nfree)
182: xfs_trans_mod_sb(tp, XFS_TRANS_SB_FDBLOCKS, id.nfree);
183:
184: /*
185: * Sync sb counters now to reflect the updated values. This is
186: * particularly important for shrink because the write verifier
187: * will fail if sb_fdblocks is ever larger than sb_dblocks.
188: */
189: if (xfs_has_lazysbcount(mp))
190: xfs_log_sb(tp);
191:
192: xfs_trans_set_sync(tp);
193: error = xfs_trans_commit(tp);
194: if (error)
195: return error;
196:
197: /* New allocation groups fully initialized, so update mount struct */
198: if (nagimax)
199: mp->m_maxagi = nagimax;
200: xfs_set_low_space_thresholds(mp);
201: mp->m_alloc_set_aside = xfs_alloc_set_aside(mp);
202:
203: if (delta > 0) {
204: /*
205: * If we expanded the last AG, free the per-AG reservation
206: * so we can reinitialize it with the new size.
207: */
208: if (lastag_extended) {
209: struct xfs_perag *pag;
210:
211: pag = xfs_perag_get(mp, id.agno);
212: xfs_ag_resv_free(pag);
213: xfs_perag_put(pag);
214: }
215: /*
216: * Reserve AG metadata blocks. ENOSPC here does not mean there
217: * was a growfs failure, just that there still isn't space for
218: * new user data after the grow has been run.
219: */
220: error = xfs_fs_reserve_ag_blocks(mp);
221: if (error == -ENOSPC)
222: error = 0;
223:
224: /* Compute new maxlevels for rt btrees. */
225: xfs_rtrmapbt_compute_maxlevels(mp);
226: xfs_rtrefcountbt_compute_maxlevels(mp);
227: }
228:
229: return error;
230:
231: out_trans_cancel:
232: xfs_trans_cancel(tp);
233: out_free_unused_perag:
234: if (nagcount > oagcount)
235: xfs_free_perag_range(mp, oagcount, nagcount);
236: return error;
237: }
SourceFile:fs/xfs/xfs_fsops.c]
|
| 54/2 |
2026/05/21 16:54 |
llm |
expert |
0m
Model:
Tokens:
input: 67707
output: 27
thoughts: 1731
Thoughts: **XFS Deadlock Analysis: A Deep Dive**
Okay, let's break this down. My initial thought process revolves around a potential deadlock within the XFS filesystem code. It seems like a sequence of function calls β `xfs_growfs_data_private` calling `xfs_ag_shrink_space` which in turn uses transaction management with `xfs_trans_bhold`, `xfs_trans_roll`, and `xfs_trans_bjoin` β is at the heart of this. Initially, I was concerned about buffer locks being held across a synchronous commit, but it turns out that isn't the case within this particular function flow.
The more significant path involves `xfs_ioc_setlabel` and `xfs_sync_sb_buf`. Aha! `xfs_ioc_setlabel` requires `CAP_SYS_ADMIN`, effectively preventing unprivileged users or those within a user namespace from triggering the issue directly. The check for `capable(CAP_SYS_ADMIN)` confirms this access restriction. Also, since mounting a malicious filesystem image also requires `CAP_SYS_ADMIN`, this significantly narrows the potential attack surface.
My mind then jumps to alternative triggers for `xfs_do_force_shutdown`. Could there be other ways to kick this off? Any IO error during metadata operations is a key suspect here. A simple write operation failing due to a disk error could shut down the system. But, to reach the deadlock specifically, a task needs to be stuck in `xlog_wait_on_iclog` while *holding* a buffer lock. The only path where I'm confident that this happens is the `xfs_ioc_setlabel` through `xfs_sync_sb_buf`, which is, again, guarded by `CAP_SYS_ADMIN`.
Okay, I'm thinking, is there any other caller of `xfs_sync_sb_buf`? Let's verify that. After checking the code, it's called *only* from `xfs_ioc_setlabel`. That means the deadlock _itself_ requires root privileges. So, no unprivileged access, no user namespace exploits. This is good news, if this were exploitable. It's essentially a Denial of Service. So to reproduce, I need a malicious filesystem, mounted with `CAP_SYS_ADMIN`, *and* then `CAP_SYS_ADMIN` to call `ioctl(FS_IOC_SETFSLABEL)`. Now, if a system automatically mounts USB drives, and *if* it then calls `ioctl`, it could happen. But that's unlikely. `blkid` just reads, it doesn't set. So a default auto-mounter is safe here.
But wait⦠is there any other path to the deadlock, bypassing `FS_IOC_SETFSLABEL`? I need to review other calls. Going back to `xfs_trans_bhold` callers, I check them:
- `xfs_ag_shrink_space` requires `CAP_SYS_ADMIN`.
- The others ( `xfs_defer_restore_resources`, `xfs_dialloc_roll`, `xfs_dquot_disk_alloc`) do *not* have `XFS_TRANS_SYNC` set.
- `xfs_sync_sb_buf` is the only one with `XFS_TRANS_SYNC` *and* holding the buffer.
The key here seems to be about *holding* a buffer across a synchronous commit. Is there another way a buffer could be held across a transaction commit?
Aha! `XFS_BLI_HOLD` is set by `xfs_trans_bhold`, and *only* by `xfs_trans_bhold`.
What if a task locks a buffer directly using `xfs_buf_lock` outside of a transaction, *then* starts a transaction and commits it synchronously? Is there any code that does this? I believe that if the buffer is locked outside a transaction, it will not be part of the transaction. If the task commits the synchronous transaction, it will wait on the log, but if a shutdown occurs, `xlog_state_shutdown_callbacks` should only unpin buffers in the CIL. If the buffer wasn't part of the CIL, a deadlock is possible if it was modified previously in a transaction. I need to know if there's any code that has this pattern: `xfs_buf_lock(bp)`, then `xfs_log_force(mp, XFS_LOG_SYNC)`. I need to check for this pattern.
|
| 55/2 |
2026/05/21 16:55 |
tool |
grepper |
0m
Error:
Args: map[Expression:xfs_buf_lock.*xfs_log_force]
Results:
|
| 56/2 |
2026/05/21 16:55 |
llm |
expert |
0m
Model:
Tokens:
input: 70462
output: 44
thoughts: 779
Thoughts: **Analyzing Potential Buffer Lock Issues with `xfs_log_force` and Synchronous Transactions**
Okay, let's break this down. My initial focus is on identifying any calls to `xfs_log_force` or `xfs_log_force_seq` that might be holding a buffer lock, because I suspect this is the root cause. `xfs_log_force` is called all over the place, which makes things a bit tricky, and just because a function waits for IO, doesn't mean it forces the log. For example `xfs_buf_iowait` is in the first category, but does not force the log.
Now, what about `xfs_buf_item_unpin`? Aha, it does lock the buffer. So, is `xfs_buf_item_unpin` is called by the AIL or CIL to unpin the buffer. If a task is holding that buffer lock, `xfs_buf_item_unpin` will block. Yes, this aligns perfectly with what we're seeing in Task 1.
Can an unprivileged user trigger this? I think not. `xfs_ioc_setlabel` requires `CAP_SYS_ADMIN`, so we don't have to worry about this. After checking other ioctl or syscall, we decided that `xfs_sync_sb_buf` is the only one holding the buffer across a sync commit. And `xfs_sync_sb_buf` is only called from `xfs_ioc_setlabel`.
Now, could `xfs_defer_finish` be called with `XFS_TRANS_SYNC` set? That's the next question. Let's look at the callers of `xfs_defer_finish`. If a transaction has `XFS_TRANS_SYNC` set, and calls `xfs_defer_finish`, does `xfs_defer_trans_roll` wait for the log? Let's trace it out: `xfs_defer_finish` -> `xfs_defer_finish_noroll` -> `xfs_defer_trans_roll` -> `xfs_trans_roll`. Ultimately, `xfs_trans_roll` calls `__xfs_trans_commit(tp, true)`. Bingo! If `tp->t_flags & XFS_TRANS_SYNC` is true, then `__xfs_trans_commit` will call `xfs_log_force_seq`. So, if `xfs_defer_finish` is called with a synchronous transaction, it WILL wait for the log while holding the buffers!
Hold on, didn't I say that `xfs_setattr_size` calls `xfs_trans_set_sync` AFTER `xfs_itruncate_extents` (which calls `xfs_defer_finish`)? That means in `xfs_setattr_size`, `XFS_TRANS_SYNC` is NOT set during `xfs_defer_finish`. We need to see if there are other callers of `xfs_defer_finish` that DO have `XFS_TRANS_SYNC` set.
Okay, let's check callers of `xfs_trans_set_sync`. Got it! Many callers, in fact: `xfs_attr_try_sf_addname`, `xfs_attr_set`, `xfs_acl_set_mode`, `xfs_swap_extents`, `xfs_exchrange_mappings`, `xfs_create`, `xfs_create_tmpfile`, `xfs_link`, `xfs_remove`, `xfs_rename`, `xfs_ioctl_setattr_get_trans`, `xfs_setattr_nonsize`, `xfs_setattr_size`, `xfs_fs_commit_blocks`, `xfs_symlink`. Now, let's go deeper on `xfs_rename`.
|
| 57/2 |
2026/05/21 16:55 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/xfs/xfs_inode.c IncludeLines:true Name:xfs_rename]
Results: map[SourceCode:2120: /*
2121: * xfs_rename
2122: */
2123: int
2124: xfs_rename(
2125: struct mnt_idmap *idmap,
2126: struct xfs_inode *src_dp,
2127: struct xfs_name *src_name,
2128: struct xfs_inode *src_ip,
2129: struct xfs_inode *target_dp,
2130: struct xfs_name *target_name,
2131: struct xfs_inode *target_ip,
2132: unsigned int flags)
2133: {
2134: struct xfs_dir_update du_src = {
2135: .dp = src_dp,
2136: .name = src_name,
2137: .ip = src_ip,
2138: };
2139: struct xfs_dir_update du_tgt = {
2140: .dp = target_dp,
2141: .name = target_name,
2142: .ip = target_ip,
2143: };
2144: struct xfs_dir_update du_wip = { };
2145: struct xfs_mount *mp = src_dp->i_mount;
2146: struct xfs_trans *tp;
2147: struct xfs_inode *inodes[__XFS_SORT_INODES];
2148: int i;
2149: int num_inodes = __XFS_SORT_INODES;
2150: bool new_parent = (src_dp != target_dp);
2151: bool src_is_directory = S_ISDIR(VFS_I(src_ip)->i_mode);
2152: int spaceres;
2153: bool retried = false;
2154: int error, nospace_error = 0;
2155:
2156: trace_xfs_rename(src_dp, target_dp, src_name, target_name);
2157:
2158: if ((flags & RENAME_EXCHANGE) && !target_ip)
2159: return -EINVAL;
2160:
2161: /*
2162: * If we are doing a whiteout operation, allocate the whiteout inode
2163: * we will be placing at the target and ensure the type is set
2164: * appropriately.
2165: */
2166: if (flags & RENAME_WHITEOUT) {
2167: error = xfs_rename_alloc_whiteout(idmap, src_name, target_dp,
2168: &du_wip.ip);
2169: if (error)
2170: return error;
2171:
2172: /* setup target dirent info as whiteout */
2173: src_name->type = XFS_DIR3_FT_CHRDEV;
2174: }
2175:
2176: xfs_sort_for_rename(src_dp, target_dp, src_ip, target_ip, du_wip.ip,
2177: inodes, &num_inodes);
2178:
2179: error = xfs_parent_start(mp, &du_src.ppargs);
2180: if (error)
2181: goto out_release_wip;
2182:
2183: if (du_wip.ip) {
2184: error = xfs_parent_start(mp, &du_wip.ppargs);
2185: if (error)
2186: goto out_src_ppargs;
2187: }
2188:
2189: if (target_ip) {
2190: error = xfs_parent_start(mp, &du_tgt.ppargs);
2191: if (error)
2192: goto out_wip_ppargs;
2193: }
2194:
2195: retry:
2196: nospace_error = 0;
2197: spaceres = xfs_rename_space_res(mp, src_name->len, target_ip != NULL,
2198: target_name->len, du_wip.ip != NULL);
2199: error = xfs_trans_alloc(mp, &M_RES(mp)->tr_rename, spaceres, 0, 0, &tp);
2200: if (error == -ENOSPC) {
2201: nospace_error = error;
2202: spaceres = 0;
2203: error = xfs_trans_alloc(mp, &M_RES(mp)->tr_rename, 0, 0, 0,
2204: &tp);
2205: }
2206: if (error)
2207: goto out_tgt_ppargs;
2208:
2209: /*
2210: * We don't allow reservationless renaming when parent pointers are
2211: * enabled because we can't back out if the xattrs must grow.
2212: */
2213: if (du_src.ppargs && nospace_error) {
2214: error = nospace_error;
2215: xfs_trans_cancel(tp);
2216: goto out_tgt_ppargs;
2217: }
2218:
2219: /*
2220: * Attach the dquots to the inodes
2221: */
2222: error = xfs_qm_vop_rename_dqattach(inodes);
2223: if (error) {
2224: xfs_trans_cancel(tp);
2225: goto out_tgt_ppargs;
2226: }
2227:
2228: /*
2229: * Lock all the participating inodes. Depending upon whether
2230: * the target_name exists in the target directory, and
2231: * whether the target directory is the same as the source
2232: * directory, we can lock from 2 to 5 inodes.
2233: */
2234: xfs_lock_inodes(inodes, num_inodes, XFS_ILOCK_EXCL);
2235:
2236: /*
2237: * Join all the inodes to the transaction.
2238: */
2239: xfs_trans_ijoin(tp, src_dp, 0);
2240: if (new_parent)
2241: xfs_trans_ijoin(tp, target_dp, 0);
2242: xfs_trans_ijoin(tp, src_ip, 0);
2243: if (target_ip)
2244: xfs_trans_ijoin(tp, target_ip, 0);
2245: if (du_wip.ip)
2246: xfs_trans_ijoin(tp, du_wip.ip, 0);
2247:
2248: error = xfs_projid_differ(target_dp, src_ip);
2249: if (error)
2250: goto out_trans_cancel;
2251:
2252: /* RENAME_EXCHANGE is unique from here on. */
2253: if (flags & RENAME_EXCHANGE) {
2254: error = xfs_dir_exchange_children(tp, &du_src, &du_tgt,
2255: spaceres);
2256: if (error)
2257: goto out_trans_cancel;
2258: goto out_commit;
2259: }
2260:
2261: /*
2262: * Try to reserve quota to handle an expansion of the target directory.
2263: * We'll allow the rename to continue in reservationless mode if we hit
2264: * a space usage constraint. If we trigger reservationless mode, save
2265: * the errno if there isn't any free space in the target directory.
2266: */
2267: if (spaceres != 0) {
2268: error = xfs_trans_reserve_quota_nblks(tp, target_dp, spaceres,
2269: 0, false);
2270: if (error == -EDQUOT || error == -ENOSPC) {
2271: if (!retried) {
2272: xfs_trans_cancel(tp);
2273: xfs_iunlock_rename(inodes, num_inodes);
2274: xfs_blockgc_free_quota(target_dp, 0);
2275: retried = true;
2276: goto retry;
2277: }
2278:
2279: nospace_error = error;
2280: spaceres = 0;
2281: error = 0;
2282: }
2283: if (error)
2284: goto out_trans_cancel;
2285: }
2286:
2287: /*
2288: * We don't allow quotaless renaming when parent pointers are enabled
2289: * because we can't back out if the xattrs must grow.
2290: */
2291: if (du_src.ppargs && nospace_error) {
2292: error = nospace_error;
2293: goto out_trans_cancel;
2294: }
2295:
2296: /*
2297: * Lock the AGI buffers we need to handle bumping the nlink of the
2298: * whiteout inode off the unlinked list and to handle dropping the
2299: * nlink of the target inode. Per locking order rules, do this in
2300: * increasing AG order and before directory block allocation tries to
2301: * grab AGFs because we grab AGIs before AGFs.
2302: *
2303: * The (vfs) caller must ensure that if src is a directory then
2304: * target_ip is either null or an empty directory.
2305: */
2306: for (i = 0; i < num_inodes && inodes[i] != NULL; i++) {
2307: if (inodes[i] == du_wip.ip ||
2308: (inodes[i] == target_ip &&
2309: (VFS_I(target_ip)->i_nlink == 1 || src_is_directory))) {
2310: struct xfs_perag *pag;
2311: struct xfs_buf *bp;
2312:
2313: pag = xfs_perag_get(mp,
2314: XFS_INO_TO_AGNO(mp, inodes[i]->i_ino));
2315: error = xfs_read_agi(pag, tp, 0, &bp);
2316: xfs_perag_put(pag);
2317: if (error)
2318: goto out_trans_cancel;
2319: }
2320: }
2321:
2322: error = xfs_dir_rename_children(tp, &du_src, &du_tgt, spaceres,
2323: &du_wip);
2324: if (error)
2325: goto out_trans_cancel;
2326:
2327: if (du_wip.ip) {
2328: /*
2329: * Now we have a real link, clear the "I'm a tmpfile" state
2330: * flag from the inode so it doesn't accidentally get misused in
2331: * future.
2332: */
2333: inode_state_clear_raw(VFS_I(du_wip.ip), I_LINKABLE);
2334: }
2335:
2336: out_commit:
2337: /*
2338: * If this is a synchronous mount, make sure that the rename
2339: * transaction goes to disk before returning to the user.
2340: */
2341: if (xfs_has_wsync(tp->t_mountp) || xfs_has_dirsync(tp->t_mountp))
2342: xfs_trans_set_sync(tp);
2343:
2344: error = xfs_trans_commit(tp);
2345: nospace_error = 0;
2346: goto out_unlock;
2347:
2348: out_trans_cancel:
2349: xfs_trans_cancel(tp);
2350: out_unlock:
2351: xfs_iunlock_rename(inodes, num_inodes);
2352: out_tgt_ppargs:
2353: xfs_parent_finish(mp, du_tgt.ppargs);
2354: out_wip_ppargs:
2355: xfs_parent_finish(mp, du_wip.ppargs);
2356: out_src_ppargs:
2357: xfs_parent_finish(mp, du_src.ppargs);
2358: out_release_wip:
2359: if (du_wip.ip)
2360: xfs_irele(du_wip.ip);
2361: if (error == -ENOSPC && nospace_error)
2362: error = nospace_error;
2363: return error;
2364: }
SourceFile:fs/xfs/xfs_inode.c]
|
| 58/2 |
2026/05/21 16:55 |
llm |
expert |
0m
Model:
Tokens:
input: 75983
output: 46
thoughts: 508
Thoughts: **XFS Rename Transaction and Deferred Operations: A Deep Dive**
Okay, so I'm digging into `xfs_rename` and trying to understand the lifecycle of deferred operations within the XFS filesystem. My initial thought was centered around how `xfs_dir_rename_children` interacts with `xfs_defer_finish`. I was initially thinking `xfs_dir_rename_children` might add deferred ops and also call `xfs_defer_finish`, but that's not it. It *can* add deferred operations, but it doesn't call `xfs_defer_finish` directly.
Then the key realization hit me: if `xfs_defer_finish` *isn't* called within `xfs_rename` itself, where are these deferred operations being handled? I was briefly thinking they might be finished during `xfs_trans_commit`, but it's not the case. I need to be sure; let's verify that `__xfs_trans_commit` and more broadly `xfs_trans_commit` don't include a call to something like `xfs_defer_finish_noroll`. Nope, `xfs_trans_commit` does *not* do it. So, that means deferred operations *must* be finalized *before* the transaction commit using `xfs_defer_finish` or there will be big problems. If not, we're looking at either a BUG or a leak, potentially.
Given that `xfs_rename` doesn't call `xfs_defer_finish`, my attention returns to `xfs_dir_rename_children`. Does this function, which is called within `xfs_rename`, actually add deferred operations? It *might*, which is the problem. But if it does, and then `xfs_rename` proceeds without calling `xfs_defer_finish`, those operations are left dangling. I think there was a rename, `xfs_bmap_finish` and `xfs_defer_finish` are the same, so no surprises there. My primary concern here is if `xfs_dir_rename_children` *does* add a deferred op, how are they *ever* finished? It appears that it's possible that deferred ops are *not* being finished if they exist within a rename.
I'm now going to go double check `xfs_trans_commit` again.
|
| 59/2 |
2026/05/21 16:55 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/xfs/xfs_trans.c IncludeLines:true Name:xfs_trans_commit]
Results: map[SourceCode: 908: int
909: xfs_trans_commit(
910: struct xfs_trans *tp)
911: {
912: /*
913: * Finish deferred items on final commit. Only permanent transactions
914: * should ever have deferred ops.
915: */
916: WARN_ON_ONCE(!list_empty(&tp->t_dfops) &&
917: !(tp->t_flags & XFS_TRANS_PERM_LOG_RES));
918: if (tp->t_flags & XFS_TRANS_PERM_LOG_RES) {
919: int error = xfs_defer_finish_noroll(&tp);
920: if (error) {
921: xfs_trans_cancel(tp);
922: return error;
923: }
924: }
925:
926: return __xfs_trans_commit(tp, false);
927: }
SourceFile:fs/xfs/xfs_trans.c]
|
| 60/2 |
2026/05/21 16:55 |
llm |
expert |
0m
Model:
Tokens:
input: 77373
output: 51
thoughts: 681
Thoughts: **XFS Transaction Commit with Sync and Deferred Operations**
Okay, so `xfs_trans_commit` *does* call `xfs_defer_finish_noroll(&tp)`. And the `xfs_rename` function, specifically, is setting the transaction to sync before the commit happens β `xfs_trans_set_sync(tp)` is called *before* `xfs_trans_commit(tp)`. This means when `xfs_trans_commit` gets invoked, `XFS_TRANS_SYNC` *is* set on the transaction structure.
Given that the sync flag is set, `xfs_trans_commit` calls `xfs_defer_finish_noroll(&tp)`, which in turn calls `xfs_defer_trans_roll(&tp)`. This function then calls `xfs_defer_save_resources`. `xfs_defer_save_resources` saves buffers using `XFS_BLI_HOLD`, and finally, `xfs_trans_roll(&tp)` gets called. That calls `__xfs_trans_commit(tp, true)`.
Because `XFS_TRANS_SYNC` is set, `__xfs_trans_commit` then calls `xfs_log_force_seq`! This means it's waiting for the log to be written while *holding* those buffers that were saved by `xfs_defer_save_resources`.
Now, does `xfs_rename` itself introduce any buffers with `XFS_BLI_HOLD`? It calls `xfs_read_agi`, which reads the AGI buffer. Does *that* set the `XFS_BLI_HOLD` flag? No, it doesn't.
But what if some other deferred operation *downstream* does, though? Could something like `xfs_bmap_extents_to_btree` introduce a hold? Wait, hang on... I remember `xfs_defer_restore_resources` sets `XFS_BLI_HOLD`! If there are multiple deferred operations, the *first* `xfs_defer_trans_roll` will save resources, if any exist.
Okay, so what if *no* resources are held? If `xfs_defer_save_resources` finds nothing that needs holding it will save nothing. Then `xfs_trans_roll` just commits and waits for the log, and `xfs_defer_restore_resources` restores nothing. Then the deferred operation is executed.
But what if a deferred operation, say `xfs_extent_free_finish_item`, *did* set `XFS_BLI_HOLD`? No, deferred operations *usually* don't set `XFS_BLI_HOLD`.
Wait, does `xfs_defer_bjoin` set `XFS_BLI_HOLD`? I should probably check that...
|
| 61/2 |
2026/05/21 16:56 |
tool |
codesearch-definition-source |
0m
Error:
Args: map[ContextFile:fs/xfs/libxfs/xfs_defer.c IncludeLines:true Name:xfs_defer_bjoin]
Results: map[SourceCode: SourceFile:]
|
| 62/2 |
2026/05/21 16:56 |
llm |
expert |
0m
Model:
Tokens:
input: 78759
output: 49
thoughts: 545
Thoughts: **Analyzing `xfs_trans_bhold` Callers and Deferred Operations**
Okay, let's circle back and re-examine the callers of `xfs_trans_bhold`. I remember we had: `xfs_ag_shrink_space`, `xfs_defer_restore_resources`, `xfs_dialloc_roll`, `xfs_dquot_disk_alloc`, and `xfs_sync_sb_buf`. Right, so `xfs_defer_restore_resources` is the sole one in the deferred operations path. But, and this is crucial, it only restores buffers previously saved by `xfs_defer_save_resources`. And that function, in turn, *only* saves buffers that *already* have the `XFS_BLI_HOLD` flag set. If nothing has the `XFS_BLI_HOLD` flag set *before* `xfs_defer_finish_noroll` gets called, then no buffer will be held across the transaction roll. That's the key.
Now, let's think about `xfs_rename`. Does that set the `XFS_BLI_HOLD` flag on any buffer? Nope. What about `xfs_create`? It calls `xfs_dialloc`, which *could* call `xfs_dialloc_roll`. Ah, yes! `xfs_dialloc_roll` does call `xfs_trans_bhold(tp, agibp)`. Then it calls `xfs_trans_roll(&tp)`. But, hang on... `xfs_create` sets `XFS_TRANS_SYNC` *after* `xfs_dialloc`. That means `xfs_dialloc_roll` won't wait for the log. After `xfs_dialloc`, `xfs_create` calls `xfs_trans_set_sync(tp)`. And finally calls `xfs_trans_commit(tp)`.
If deferred operations exist (like from `xfs_dir_create_child`), `xfs_trans_commit` triggers `xfs_defer_finish_noroll`. But the question remains: Are there any buffers with `XFS_BLI_HOLD` at this point? Now, I recall that `xfs_dialloc_roll` calls `xfs_trans_bjoin(tp, agibp)` after the roll. And `xfs_trans_bjoin`... No, it *doesn't* set `XFS_BLI_HOLD`. Wait, it's just joining the buffer into the transaction. Let's make sure, I should really verify `xfs_trans_bjoin`.
|
| 63/2 |
2026/05/21 16:56 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/xfs/xfs_trans_buf.c IncludeLines:true Name:xfs_trans_bjoin]
Results: map[SourceCode: 97: void
98: xfs_trans_bjoin(
99: struct xfs_trans *tp,
100: struct xfs_buf *bp)
101: {
102: _xfs_trans_bjoin(tp, bp, 0);
103: trace_xfs_trans_bjoin(bp->b_log_item);
104: }
SourceFile:fs/xfs/xfs_trans_buf.c]
|
| 64/2 |
2026/05/21 16:56 |
llm |
expert |
0m
Model:
Tokens:
input: 80087
output: 50
thoughts: 22
Thoughts: Okay, here's my take on those thoughts, framed as an expert's internal monologue:
**Checking XFS Transaction Boundary Behaviors**
Right, so I'm digging into `_xfs_trans_bjoin`, and the key question immediately pops up: does this function actually set the `XFS_BLI_HOLD` flag? It's crucial, obviously, because that flag controls whether the buffer is held during a transaction. Understanding how this function interacts with buffer lifecycles is absolutely fundamental to tracking down potential issues. I need to nail this down before I can proceed. Gotta know if it's contributing to contention, blocking other processes from accessing the buffer, or, conversely, letting the buffer potentially become corrupted prematurely if not held properly. This is the bedrock of transaction management, and any oversight here could cause some serious problems down the line. Let's see... I'll need to double-check the code and documentation to confirm.
|
| 65/2 |
2026/05/21 16:56 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/xfs/xfs_trans_buf.c IncludeLines:true Name:_xfs_trans_bjoin]
Results: map[SourceCode: 51: /*
52: * Add the locked buffer to the transaction.
53: *
54: * The buffer must be locked, and it cannot be associated with any
55: * transaction.
56: *
57: * If the buffer does not yet have a buf log item associated with it,
58: * then allocate one for it. Then add the buf item to the transaction.
59: */
60: STATIC void
61: _xfs_trans_bjoin(
62: struct xfs_trans *tp,
63: struct xfs_buf *bp,
64: int reset_recur)
65: {
66: struct xfs_buf_log_item *bip;
67:
68: ASSERT(bp->b_transp == NULL);
69:
70: /*
71: * The xfs_buf_log_item pointer is stored in b_log_item. If
72: * it doesn't have one yet, then allocate one and initialize it.
73: * The checks to see if one is there are in xfs_buf_item_init().
74: */
75: xfs_buf_item_init(bp, tp->t_mountp);
76: bip = bp->b_log_item;
77: ASSERT(!(bip->bli_flags & XFS_BLI_STALE));
78: ASSERT(!(bip->__bli_format.blf_flags & XFS_BLF_CANCEL));
79: ASSERT(!(bip->bli_flags & XFS_BLI_LOGGED));
80: if (reset_recur)
81: bip->bli_recur = 0;
82:
83: /*
84: * Take a reference for this transaction on the buf item.
85: */
86: atomic_inc(&bip->bli_refcount);
87:
88: /*
89: * Attach the item to the transaction so we can find it in
90: * xfs_trans_get_buf() and friends.
91: */
92: xfs_trans_add_item(tp, &bip->bli_item);
93: bp->b_transp = tp;
94:
95: }
SourceFile:fs/xfs/xfs_trans_buf.c]
|
| 66/2 |
2026/05/21 16:56 |
llm |
expert |
0m
Model:
Tokens:
input: 81035
output: 46
thoughts: 1098
Thoughts: **Analysis of the XFS Deadlock Vulnerability**
Okay, let's break this down. First, I wanted to confirm if the `xfs_create` function was involved in the deadlock, specifically if it held buffers across a sync commit. Nope, that's not the case; it doesn't set `XFS_BLI_HOLD`, so no buffers are held across the sync.
What about `xfs_dquot_disk_alloc`? It does the `xfs_trans_bhold` and `xfs_trans_commit` dance, but again, no `XFS_TRANS_SYNC`, so it can't be the culprit.
This means the only path that holds a buffer across a sync commit is `xfs_sync_sb_buf`. And that function is *only* called from `xfs_ioc_setlabel`. Ah, but `xfs_ioc_setlabel` requires `CAP_SYS_ADMIN` within the initial user namespace.
So, the question becomes, is there any other way to trigger `xfs_sync_sb_buf`? No. I checked thoroughly, even with `grepper` and `codesearch-find-references`.
Could the deadlock be triggered through a different path entirely? What if an unprivileged user tried to call `xfs_ioc_setlabel`? That's immediately blocked by the `capable(CAP_SYS_ADMIN)` check. Then I checked if `FS_IOC_SETFSLABEL` is a generic ioctl, but it's XFS-specific. And it routes to `xfs_ioc_setlabel` via `xfs_file_ioctl`, so that's also blocked.
Could `xfs_sync_sb_buf` be called from somewhere else *internally*? Again, I've checked all references.
Alright, could we construct the deadlock without `xfs_sync_sb_buf`? We need a task to wait on `ic_force_wait` while holding a buffer lock. I've exhaustively reviewed all callers of `xfs_trans_bhold`. Are there any other ways to keep a buffer lock across a commit? No, because `xlog_cil_commit` unlocks all buffers that don't have `XFS_BLI_HOLD` set. Only buffers with `XFS_BLI_HOLD` are held, and that is only set by `xfs_trans_bhold`. I've checked all of its callers, so no other methods exist.
Therefore, this deadlock strictly requires either `xfs_ioc_setlabel` or `xfs_ag_shrink_space`. And both require `CAP_SYS_ADMIN` in the initial user namespace.
So the conclusion is: This bug is *not* accessible from unprivileged processes, and it's *not* accessible from user namespaces. It's a Denial of Service (DoS) β a deadlock, not exploitable in the classic sense. No memory corruption, just resource exhaustion. It *can* be triggered by a malicious filesystem, but only if an administrator runs `xfs_admin -L` or `xfs_growfs` on it. And mounting a malicious filesystem doesn't automatically trigger `xfs_ioc_setlabel`. The syzbot reproducer explicitly calls `ioctl(FS_IOC_SETFSLABEL)`. Since syzbot runs as root, or has capabilities it's safe. But a real unprivileged user can't trigger it.
Let me double-check the permissions:
```c
if (!capable(CAP_SYS_ADMIN))
return -EPERM;
```
Yup, `FS_IOC_SETFSLABEL` strictly requires `CAP_SYS_ADMIN`. And `xfs_ag_shrink_space` is called from a similar set of calls and is also protected.
Thus, this vulnerability is not a security risk for ordinary systems.
|
| 67/2 |
2026/05/21 16:56 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/xfs/xfs_ioctl.c IncludeLines:true Name:xfs_file_ioctl]
Results: map[SourceCode:1172: /*
1173: * Note: some of the ioctl's return positive numbers as a
1174: * byte count indicating success, such as readlink_by_handle.
1175: * So we don't "sign flip" like most other routines. This means
1176: * true errors need to be returned as a negative value.
1177: */
1178: long
1179: xfs_file_ioctl(
1180: struct file *filp,
1181: unsigned int cmd,
1182: unsigned long p)
1183: {
1184: struct inode *inode = file_inode(filp);
1185: struct xfs_inode *ip = XFS_I(inode);
1186: struct xfs_mount *mp = ip->i_mount;
1187: void __user *arg = (void __user *)p;
1188: int error;
1189:
1190: trace_xfs_file_ioctl(ip);
1191:
1192: switch (cmd) {
1193: case FITRIM:
1194: return xfs_ioc_trim(mp, arg);
1195: case FS_IOC_GETFSLABEL:
1196: return xfs_ioc_getlabel(mp, arg);
1197: case FS_IOC_SETFSLABEL:
1198: return xfs_ioc_setlabel(filp, mp, arg);
1199: case XFS_IOC_ALLOCSP:
1200: case XFS_IOC_FREESP:
1201: case XFS_IOC_ALLOCSP64:
1202: case XFS_IOC_FREESP64:
1203: xfs_warn_once(mp,
1204: "%s should use fallocate; XFS_IOC_{ALLOC,FREE}SP ioctl unsupported",
1205: current->comm);
1206: return -ENOTTY;
1207: case XFS_IOC_DIOINFO: {
1208: struct kstat st;
1209: struct dioattr da;
1210:
1211: error = vfs_getattr(&filp->f_path, &st, STATX_DIOALIGN, 0);
1212: if (error)
1213: return error;
1214:
1215: /*
1216: * Some userspace directly feeds the return value to
1217: * posix_memalign, which fails for values that are smaller than
1218: * the pointer size. Round up the value to not break userspace.
1219: */
1220: da.d_mem = roundup(st.dio_mem_align, sizeof(void *));
1221: da.d_miniosz = st.dio_offset_align;
1222: da.d_maxiosz = INT_MAX & ~(da.d_miniosz - 1);
1223: if (copy_to_user(arg, &da, sizeof(da)))
1224: return -EFAULT;
1225: return 0;
1226: }
1227:
1228: case XFS_IOC_FSBULKSTAT_SINGLE:
1229: case XFS_IOC_FSBULKSTAT:
1230: case XFS_IOC_FSINUMBERS:
1231: return xfs_ioc_fsbulkstat(filp, cmd, arg);
1232:
1233: case XFS_IOC_BULKSTAT:
1234: return xfs_ioc_bulkstat(filp, cmd, arg);
1235: case XFS_IOC_INUMBERS:
1236: return xfs_ioc_inumbers(mp, cmd, arg);
1237:
1238: case XFS_IOC_FSGEOMETRY_V1:
1239: return xfs_ioc_fsgeometry(mp, arg, 3);
1240: case XFS_IOC_FSGEOMETRY_V4:
1241: return xfs_ioc_fsgeometry(mp, arg, 4);
1242: case XFS_IOC_FSGEOMETRY:
1243: return xfs_ioc_fsgeometry(mp, arg, 5);
1244:
1245: case XFS_IOC_AG_GEOMETRY:
1246: return xfs_ioc_ag_geometry(mp, arg);
1247: case XFS_IOC_RTGROUP_GEOMETRY:
1248: return xfs_ioc_rtgroup_geometry(mp, arg);
1249:
1250: case XFS_IOC_GETVERSION:
1251: return put_user(inode->i_generation, (int __user *)arg);
1252:
1253: case XFS_IOC_FSGETXATTRA:
1254: return xfs_ioc_fsgetxattra(ip, arg);
1255: case XFS_IOC_GETPARENTS:
1256: return xfs_ioc_getparents(filp, arg);
1257: case XFS_IOC_GETPARENTS_BY_HANDLE:
1258: return xfs_ioc_getparents_by_handle(filp, arg);
1259: case XFS_IOC_GETBMAP:
1260: case XFS_IOC_GETBMAPA:
1261: case XFS_IOC_GETBMAPX:
1262: return xfs_ioc_getbmap(filp, cmd, arg);
1263:
1264: case FS_IOC_GETFSMAP:
1265: return xfs_ioc_getfsmap(ip, arg);
1266:
1267: case XFS_IOC_SCRUBV_METADATA:
1268: return xfs_ioc_scrubv_metadata(filp, arg);
1269: case XFS_IOC_SCRUB_METADATA:
1270: return xfs_ioc_scrub_metadata(filp, arg);
1271:
1272: case XFS_IOC_FD_TO_HANDLE:
1273: case XFS_IOC_PATH_TO_HANDLE:
1274: case XFS_IOC_PATH_TO_FSHANDLE: {
1275: xfs_fsop_handlereq_t hreq;
1276:
1277: if (copy_from_user(&hreq, arg, sizeof(hreq)))
1278: return -EFAULT;
1279: return xfs_find_handle(cmd, &hreq);
1280: }
1281: case XFS_IOC_OPEN_BY_HANDLE: {
1282: xfs_fsop_handlereq_t hreq;
1283:
1284: if (copy_from_user(&hreq, arg, sizeof(xfs_fsop_handlereq_t)))
1285: return -EFAULT;
1286: return xfs_open_by_handle(filp, &hreq);
1287: }
1288:
1289: case XFS_IOC_READLINK_BY_HANDLE: {
1290: xfs_fsop_handlereq_t hreq;
1291:
1292: if (copy_from_user(&hreq, arg, sizeof(xfs_fsop_handlereq_t)))
1293: return -EFAULT;
1294: return xfs_readlink_by_handle(filp, &hreq);
1295: }
1296: case XFS_IOC_ATTRLIST_BY_HANDLE:
1297: return xfs_attrlist_by_handle(filp, arg);
1298:
1299: case XFS_IOC_ATTRMULTI_BY_HANDLE:
1300: return xfs_attrmulti_by_handle(filp, arg);
1301:
1302: case XFS_IOC_SWAPEXT: {
1303: struct xfs_swapext sxp;
1304:
1305: if (copy_from_user(&sxp, arg, sizeof(xfs_swapext_t)))
1306: return -EFAULT;
1307: error = mnt_want_write_file(filp);
1308: if (error)
1309: return error;
1310: error = xfs_ioc_swapext(&sxp);
1311: mnt_drop_write_file(filp);
1312: return error;
1313: }
1314:
1315: case XFS_IOC_FSCOUNTS:
1316: return xfs_ioctl_fs_counts(mp, arg);
1317:
1318: case XFS_IOC_SET_RESBLKS:
1319: case XFS_IOC_GET_RESBLKS:
1320: return xfs_ioctl_getset_resblocks(filp, cmd, arg);
1321:
1322: case XFS_IOC_FSGROWFSDATA: {
1323: struct xfs_growfs_data in;
1324:
1325: if (copy_from_user(&in, arg, sizeof(in)))
1326: return -EFAULT;
1327:
1328: error = mnt_want_write_file(filp);
1329: if (error)
1330: return error;
1331: error = xfs_growfs_data(mp, &in);
1332: mnt_drop_write_file(filp);
1333: return error;
1334: }
1335:
1336: case XFS_IOC_FSGROWFSLOG: {
1337: struct xfs_growfs_log in;
1338:
1339: if (copy_from_user(&in, arg, sizeof(in)))
1340: return -EFAULT;
1341:
1342: error = mnt_want_write_file(filp);
1343: if (error)
1344: return error;
1345: error = xfs_growfs_log(mp, &in);
1346: mnt_drop_write_file(filp);
1347: return error;
1348: }
1349:
1350: case XFS_IOC_FSGROWFSRT: {
1351: xfs_growfs_rt_t in;
1352:
1353: if (copy_from_user(&in, arg, sizeof(in)))
1354: return -EFAULT;
1355:
1356: error = mnt_want_write_file(filp);
1357: if (error)
1358: return error;
1359: error = xfs_growfs_rt(mp, &in);
1360: mnt_drop_write_file(filp);
1361: return error;
1362: }
1363:
1364: case XFS_IOC_GOINGDOWN: {
1365: uint32_t in;
1366:
1367: if (!capable(CAP_SYS_ADMIN))
1368: return -EPERM;
1369:
1370: if (get_user(in, (uint32_t __user *)arg))
1371: return -EFAULT;
1372:
1373: return xfs_fs_goingdown(mp, in);
1374: }
1375:
1376: case XFS_IOC_ERROR_INJECTION: {
1377: xfs_error_injection_t in;
1378:
1379: if (!capable(CAP_SYS_ADMIN))
1380: return -EPERM;
1381:
1382: if (copy_from_user(&in, arg, sizeof(in)))
1383: return -EFAULT;
1384:
1385: return xfs_errortag_add(mp, in.errtag);
1386: }
1387:
1388: case XFS_IOC_ERROR_CLEARALL:
1389: if (!capable(CAP_SYS_ADMIN))
1390: return -EPERM;
1391:
1392: return xfs_errortag_clearall(mp);
1393:
1394: case XFS_IOC_FREE_EOFBLOCKS: {
1395: struct xfs_fs_eofblocks eofb;
1396: struct xfs_icwalk icw;
1397:
1398: if (!capable(CAP_SYS_ADMIN))
1399: return -EPERM;
1400:
1401: if (xfs_is_readonly(mp))
1402: return -EROFS;
1403:
1404: if (copy_from_user(&eofb, arg, sizeof(eofb)))
1405: return -EFAULT;
1406:
1407: error = xfs_fs_eofblocks_from_user(&eofb, &icw);
1408: if (error)
1409: return error;
1410:
1411: trace_xfs_ioc_free_eofblocks(mp, &icw, _RET_IP_);
1412:
1413: guard(super_write)(mp->m_super);
1414: return xfs_blockgc_free_space(mp, &icw);
1415: }
1416:
1417: case XFS_IOC_EXCHANGE_RANGE:
1418: return xfs_ioc_exchange_range(filp, arg);
1419: case XFS_IOC_START_COMMIT:
1420: return xfs_ioc_start_commit(filp, arg);
1421: case XFS_IOC_COMMIT_RANGE:
1422: return xfs_ioc_commit_range(filp, arg);
1423:
1424: case XFS_IOC_HEALTH_MONITOR:
1425: return xfs_ioc_health_monitor(filp, arg);
1426: case XFS_IOC_VERIFY_MEDIA:
1427: return xfs_ioc_verify_media(filp, arg);
1428:
1429: default:
1430: return -ENOTTY;
1431: }
1432: }
SourceFile:fs/xfs/xfs_ioctl.c]
|
| 68/2 |
2026/05/21 16:56 |
llm |
expert |
0m
Model:
Tokens:
input: 87132
output: 48
thoughts: 55
Thoughts: Okay, here's my interpretation of that thought process, assuming I'm already quite familiar with the XFS filesystem internals:
**XFS Growfs Data Context**
Right, so `xfs_growfs_data` is the function responsible for the data portion growth in the XFS filesystem. And where does that actually get called from? Oh yeah, `xfs_file_ioctl`, specifically for the `XFS_IOC_FSGROWFSDATA` ioctl. It all fits. But hold on a second... are we adequately checking for privileges during this growth operation? Given this is a filesystem resize, potentially impacting the entire system, proper access control is crucial. It's a critical point to consider. The important question then, is if `xfs_growfs_data` itself verifies if the current process has the `CAP_SYS_ADMIN` capability. Or, perhaps does it rely on an earlier check higher up the call stack? I need to verify how these capabilities are handled to ensure a secure resize operation.
|
| 69/2 |
2026/05/21 16:56 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/xfs/xfs_fsops.c IncludeLines:true Name:xfs_growfs_data]
Results: map[SourceCode: 284: /*
285: * protected versions of growfs function acquire and release locks on the mount
286: * point - exported through ioctls: XFS_IOC_FSGROWFSDATA, XFS_IOC_FSGROWFSLOG,
287: * XFS_IOC_FSGROWFSRT
288: */
289: int
290: xfs_growfs_data(
291: struct xfs_mount *mp,
292: struct xfs_growfs_data *in)
293: {
294: int error;
295:
296: if (!capable(CAP_SYS_ADMIN))
297: return -EPERM;
298: if (!mutex_trylock(&mp->m_growlock))
299: return -EWOULDBLOCK;
300:
301: /* we can't grow the data section when an internal RT section exists */
302: if (in->newblocks != mp->m_sb.sb_dblocks && mp->m_sb.sb_rtstart) {
303: error = -EINVAL;
304: goto out_unlock;
305: }
306:
307: /* update imaxpct separately to the physical grow of the filesystem */
308: if (in->imaxpct != mp->m_sb.sb_imax_pct) {
309: error = xfs_growfs_imaxpct(mp, in->imaxpct);
310: if (error)
311: goto out_unlock;
312: }
313:
314: if (in->newblocks != mp->m_sb.sb_dblocks) {
315: error = xfs_growfs_data_private(mp, in);
316: if (error)
317: goto out_unlock;
318: }
319:
320: /* Post growfs calculations needed to reflect new state in operations */
321: if (mp->m_sb.sb_imax_pct) {
322: uint64_t icount = mp->m_sb.sb_dblocks * mp->m_sb.sb_imax_pct;
323: do_div(icount, 100);
324: M_IGEO(mp)->maxicount = XFS_FSB_TO_INO(mp, icount);
325: } else
326: M_IGEO(mp)->maxicount = 0;
327:
328: /* Update secondary superblocks now the physical grow has completed */
329: error = xfs_update_secondary_sbs(mp);
330:
331: /*
332: * Increment the generation unconditionally, after trying to update the
333: * secondary superblocks, as the new size is live already at this point.
334: */
335: mp->m_generation++;
336: out_unlock:
337: mutex_unlock(&mp->m_growlock);
338: return error;
339: }
SourceFile:fs/xfs/xfs_fsops.c]
|
| 70/2 |
2026/05/21 16:56 |
llm |
expert |
0m
Model:
Tokens:
input: 88367
output: 66
thoughts: 506
Thoughts: **My Analysis of the XFS Deadlock Vulnerability**
Okay, let's break this down. My initial assessment hinges on the fact that `xfs_growfs_data` checks for `CAP_SYS_ADMIN`. This immediately shapes the attack surface.
Therefore, since this deadlock relies on `CAP_SYS_ADMIN` within the initial user namespace, the attack is **not exploitable** in the conventional memory corruption sense. However, it's definitely a **Denial of Service** vulnerability; a deadlock will halt tasks, and potentially the whole system if critical tasks are involved. It's also, importantly, **not unprivileged** β root privileges (or at least `CAP_SYS_ADMIN`) are mandatory. The fact that `capable()` is used instead of `ns_capable()` means it's also not vulnerable from within a **UserNamespace**. The vulnerability can't be triggered by a **VMGuest** or **VMHost**, **network** operations, **remote** actions, or from a **peripheral** directly.
The question of a **FilesystemTrigger** is more nuanced. Initially, I thought a malicious filesystem was required, meaning it would be. That's true, in a way, as it needs to be possible to trigger a root ioctl on an XFS filesystem. And the bug report does hinge on this, the shutdown occurs during `xfs_trans_read_buf`. But it's also true that a standard filesystem can trigger an IO error. But the malicious filesystem just makes it easier.
Then I considered the possibility of triggering it without a malicious filesystem. If a disk fails (like a physically unplugged USB drive) at the right moment during `xfs_admin -L`, it could trigger the deadlock. This is an incredibly narrow race, and the syzbot reproducer uses a malicious filesystem for a reliable trigger (a corrupted btree block that fails validation).
Ultimately, considering this analysis, the dimensions shake out like this:
* Exploitable: **False**
* DenialOfService: **True**
* Unprivileged: **False**
* UserNamespace: **False**
* VMGuestTrigger: **False**
* VMHostTrigger: **False**
* NetworkTrigger: **False**
* RemoteTrigger: **False**
* PeripheralTrigger: **False**
* FilesystemTrigger: **True**
That's my final assessment. I'll set these results as finalized.
|
| 71/2 |
2026/05/21 16:56 |
tool |
set-results |
0m
Args: map[DenialOfService:true Exploitable:false FilesystemTrigger:true NetworkTrigger:false PeripheralTrigger:false RemoteTrigger:false Unprivileged:false UserNamespace:false VMGuestTrigger:false VMHostTrigger:false]
Results: map[DenialOfService:true Exploitable:false FilesystemTrigger:true NetworkTrigger:false PeripheralTrigger:false RemoteTrigger:false Unprivileged:false UserNamespace:false VMGuestTrigger:false VMHostTrigger:false]
|
| 72/2 |
2026/05/21 16:56 |
llm |
expert |
0m
Model:
Tokens:
input: 89530
output: 649
thoughts: 521
Thoughts: **My Analysis Concludes: A Deadlock in XFS**
Okay, the analysis is done. Time to synthesize my understanding into a concise explanation. Here's the core of it: we've got a deadlock scenario in the XFS filesystem. It hinges on a specific sequence of events involving two tasks.
Task 1 is in the midst of a filesystem shutdown. Specifically, it's executing `xfs_do_force_shutdown`, which then calls `xlog_state_shutdown_callbacks`. This function's job is to abort committed items in the CIL (Committed Item List) during the shutdown process. As part of this abortion, buffers need to be unpinned using `xfs_buf_item_unpin`. To unpin, it *must* acquire the buffer lock using `xfs_buf_lock`.
Task 2 is simultaneously executing `xfs_ioc_setlabel`, which, in turn, calls `xfs_sync_sb_buf`. Here's the critical bit: `xfs_sync_sb_buf` locks the superblock buffer, commits a synchronous transaction using `xfs_trans_commit`, and then *blocks* waiting for the log to be written to disk (`xlog_wait_on_iclog`). It's crucial to note that while waiting for the log flush, it *still holds* the superblock buffer lock!
The deadlock occurs if the shutdown process (Task 1) kicks off while Task 2 is waiting for the log force. Task 1 tries to acquire the superblock buffer lock in its unpinning procedure. But, boom, Task 2 is already holding it, waiting for the log to force. Here's where it gets nasty. Task 2 is waiting for the log to finish, which is effectively shut down. Task 1 is responsible for waking up the waiters when the log is closed and the shutdown is complete. However, the problem lies in the fact that Task 1 unpins buffers first, *then* wakes up the waiters, a true AB-BA deadlock situation.
To be able to trigger the deadlock, you need a task holding a buffer lock *while* waiting for a synchronous log force. In the XFS codebase, this precise pattern only appears in `xfs_sync_sb_buf`, which is, for all intents and purposes, solely called by `xfs_ioc_setlabel` β the handler for the `FS_IOC_SETFSLABEL` ioctl.
The ioctl requires `CAP_SYS_ADMIN` in the initial user namespace. Therefore, this bug is not something an unprivileged user can trigger, nor can it be initiated from within a user namespace. Additionally, since XFS doesn't support being mounted in user namespaces, it makes that particular attack vector irrelevant.
Ultimately, this is a denial-of-service vulnerability due to the deadlock, but thankfully it doesn't lead to memory corruption or provide a path for privilege escalation. Even with a maliciously crafted filesystem image (used to reliably force the shutdown via a corrupted btree block in the reproducer), the bug itself demands a highly privileged user with `CAP_SYS_ADMIN` in the initial namespace, who needs to execute a very specific ioctl.
|
| 73/1 |
2026/05/21 16:57 |
action |
format-explanation |
0m
Results: map[Explanation:Based on the analysis of the stack traces and the XFS source code, here is the
assessment of the bug:
**Bug Mechanism:**
The bug is a classic AB-BA deadlock in the XFS filesystem involving buffer locks
and log forcing during a filesystem shutdown.
1. **Task 2** executes `ioctl(FS_IOC_SETFSLABEL)`, which calls
`xfs_ioc_setlabel()` -> `xfs_sync_sb_buf()`. This function locks the superblock
buffer, commits a synchronous transaction, and waits for the log to be written
to disk (`xlog_wait_on_iclog`) **while still holding the superblock buffer
lock**.
2. **Task 1** encounters an IO error or metadata corruption (in the reproducer,
this is caused by reading a corrupted btree block from a malicious image during
a `truncate` operation). This triggers a forced filesystem shutdown
(`xfs_do_force_shutdown()`).
3. The shutdown process calls `xlog_state_shutdown_callbacks()`, which processes
committed items in the CIL to abort them. This involves unpinning buffers
(`xfs_buf_item_unpin()`), which requires acquiring the buffer lock
(`xfs_buf_lock()`).
4. **Deadlock:** Task 1 blocks trying to acquire the superblock buffer lock held
by Task 2. Task 2 is blocked waiting for the log to force, but the log is shut
down. Task 1 is responsible for waking up the log waiters, but it only does so
*after* unpinning the buffers. Both tasks wait on each other indefinitely.
**Security Impact:**
- **Exploitable:** No. This is a pure deadlock issue. It does not involve memory
corruption, use-after-free, or out-of-bounds accesses, so it cannot be exploited
for privilege escalation or arbitrary code execution.
- **Denial of Service:** Yes. The deadlock hangs the involved tasks in the `D`
(uninterruptible) state, holding critical XFS locks that will eventually hang
any other processes attempting to access the filesystem, leading to a denial of
service.
- **Unprivileged / User Namespace:** No. The only path in the kernel that holds
a buffer lock across a synchronous log commit is `xfs_sync_sb_buf()`, which is
exclusively called by `xfs_ioc_setlabel()`. This ioctl explicitly enforces a
capability check: `if (!capable(CAP_SYS_ADMIN)) return -EPERM;`. Because it uses
`capable()` rather than `ns_capable()`, it strictly requires `CAP_SYS_ADMIN` in
the **initial** user namespace. Furthermore, XFS filesystems cannot be mounted
inside user namespaces (`FS_USERNS_MOUNT` is not set).
- **Filesystem Trigger:** Yes. A malicious filesystem image is used to reliably
trigger the metadata corruption that initiates the shutdown sequence. However,
because triggering the deadlock also requires the highly privileged
`FS_IOC_SETFSLABEL` ioctl to be called concurrently, the attack surface is
extremely limited in practice.]
|