| 0/0 |
2026/05/31 13:05 |
flow |
assessment-security |
47m
Results: map[DenialOfService:true Explanation:Based on the analysis of the bug report and the GFS2 source code, here is the
assessment of the vulnerabilities:
**1. RT Spinlock Bug (`sleeping function called from invalid context`)**
In `gfs2_quota_init()`, the code acquires a bucket lock using
`spin_lock_bucket()`, which internally uses `hlist_bl_lock()`. On `PREEMPT_RT`
kernels, `hlist_bl_lock()` is implemented as a bit spinlock that explicitly
disables preemption.
While holding this lock, the code calls `gfs2_qd_search_bucket()`, which in turn
calls `lockref_get_not_dead()`. This function attempts to acquire
`spin_lock(&lockref->lock)`. On `PREEMPT_RT`, standard spinlocks are mapped to
`rt_spin_lock`, which are sleeping locks. Attempting to acquire a sleeping lock
while preemption is disabled is invalid and triggers the reported `BUG: sleeping
function called from invalid context`. This is a known RT-specific locking
constraint violation.
**2. Assertion Failure (`assertion "!qd->qd_change" failed`)**
While parsing the quota change file during mount, if `gfs2_quota_init()`
encounters a duplicate quota identifier, it attempts to handle the corruption by
dropping the previously allocated quota data object via `qd_put(old_qd)`.
Because the journal is not yet marked as live (`SDF_JOURNAL_LIVE` is not set
during this early mount phase), `qd_put()` immediately marks the object as dead
and calls `gfs2_qd_dispose()`.
However, `old_qd` was previously initialized with non-zero `qd_change` and
`qd_slot_ref` values. `gfs2_qd_dispose()` contains assertions expecting these to
be zero (`gfs2_assert_warn(sdp, !qd->qd_change)`), which fail and print the
warnings. Consequently, the bit corresponding to this quota slot in
`sd_quota_bitmap` is leaked because `slot_put()` is bypassed. The bitmap itself
is safely freed upon unmount, meaning this only results in a harmless leaked bit
(quota slot exhaustion) rather than a memory corruption or use-after-free.
**Security Impact:**
* **Exploitable:** No. Both issues result in kernel warnings and a minor
internal state leak (a bit in a bitmap). There is no memory corruption,
out-of-bounds access, or use-after-free that could be leveraged for privilege
escalation.
* **Denial of Service:** Yes. The bugs trigger kernel warnings and stack traces.
If the kernel is configured with `panic_on_warn` (common in some environments),
this will halt the system, leading to a DoS.
* **Unprivileged / User Namespace:** No. GFS2 does not implement the
`FS_USERNS_MOUNT` flag. Mounting a GFS2 filesystem strictly requires
`CAP_SYS_ADMIN` in the initial user namespace. Unprivileged users cannot trigger
this bug directly.
* **Filesystem / Peripheral Trigger:** Yes. The bug is triggered by parsing a
maliciously crafted or corrupted GFS2 filesystem image. It can be triggered if a
system is configured to auto-mount external media (like USB drives) containing
the corrupted image. Exploitable:false FilesystemTrigger:true NetworkTrigger:false PeripheralTrigger:true RemoteTrigger:false Unprivileged:false UserNamespace:false VMGuestTrigger:false VMHostTrigger:false]
|
| 1/1 |
2026/05/31 13:05 |
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;
}
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;
if (write(1, "executing program\n", sizeof("executing program\n") - 1)) {}
// syz_mount_image$gfs2 arguments: [
// fs: ptr[in, buffer] {
// buffer: {67 66 73 32 00} (length 0x5)
// }
// dir: ptr[in, buffer] {
// buffer: {2e 2f 66 69 6c 65 30 00} (length 0x8)
// }
// flags: mount_flags = 0x4800 (8 bytes)
// opts: ptr[inout, array[ANYUNION]] {
// array[ANYUNION] {
// }
// }
// chdir: int8 = 0xff (1 bytes)
// size: len = 0x125fd (8 bytes)
// img: ptr[in, buffer] {
// buffer: (compressed buffer with length 0x125fd)
// }
// ]
// returns fd_dir
memcpy((void*)0x2000000124c0, "gfs2\000", 5);
memcpy((void*)0x200000012500, "./file0\000", 8);
memcpy((void*)0x200000024b40, "... [truncated large byte array] ...", 75261);
syz_mount_image(/*fs=*/0x2000000124c0, /*dir=*/0x200000012500, /*flags=MS_REC|MS_NODIRATIME*/0x4800, /*opts=*/0x200000000180, /*chdir=*/-1, /*size=*/0x125fd, /*img=*/0x200000024b40);
return 0;
}
]
|
| 2/1 |
2026/05/31 13:05 |
action |
kernel-checkouter |
1m
Results: map[KernelSrc:/app/workdir/cache/src/b1854006425d1ad46ee1cbda3a5f468b7121f04a]
|
| 3/1 |
2026/05/31 13:06 |
action |
kernel-builder |
29m
Results: map[KernelObj:/app/workdir/cache/build/f0e15dc99d725e376dc637db8f4feceda76b2daf]
|
| 4/1 |
2026/05/31 13:36 |
action |
codesearch-prepare |
12m
Results: map[Index:codesearch-index]
|
| 5/1 |
2026/05/31 13:48 |
agent |
expert |
4m
Model:
Results: map[DenialOfService:true Exploitable:false FilesystemTrigger:true NetworkTrigger:false PeripheralTrigger:true 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 grepping
".config" file for "CONFIG_CMDLINE=". Assume sysctl parameters have default values.
But analyze for the corresponding production build w/o debugging tools enabled (like KASAN, KMSAN, UBSAN).
Try different strategies when analyzing the bug:
- think of ways in which the vulnerable code is unreachable
- or the other way around: try to come up with different ideas of how an unprivileged user can reach the bug
If still unsure err on the side of the bug being non-exploitable/not-accessible.
In the final reply, provide a reasoning for your assessment.
Analysis dimensions:
* Exploitable:
Determine if the bug can result in memory corruption or elevated privileges.
Memory safety issues are almost always exploitable (KASAN or UBSAN reports for use-after-free, out-of-bounds;
refcounting issues, corrupted lists, etc). When kernel is crashing on a completely wild pointer access
(e.g. user-space address, or non-canonical address, but not on NULL or address corresponding to KASAN shadow
for NULL address), including both data accesses and control transfers, that also usually implies possibility
of exploitation. Such reports usually say "unable to handle kernel paging request".
Uses of uninitialized values detected by KMSAN may be exploitable b/c attacker frequently can affect uninit
values with spraying techniques. However, for these exploitability depends on how exactly the uninit value
is used in the code, and what it affects.
Think of what happens after the bug is triggered. Some bugs cause kernel panic and halt execution,
they are harder to exploit. For example, BUG reports halts the kernel. However, WARNING reports don't halt
execution in production builds. Debug bug detection tools (like KASAN, KMSAN, KCSAN, UBSAN) are also not enabled
in production builds, so attacker can freely exploit these bugs w/o being detected by these tools.
If you see an integer overflow, think how the overflowed value used later (if it's used as allocation size,
or an array index). If you see an out-of-bounds read, think if it's followed by an out-of-bounds write as well.
Some KCSAN data-races may be exploitable by skilled attackers as well. Think what data structures got corrupted
as the result of data races and how. However, note that kernel has lots of "benign" data races that don't lead
to any runtime misbehavior at all.
* Denial Of Service:
Determine if the bug can result in denial-of-service. Most bugs can, since they cause system crash,
hangs, deadlocks, or resource leaks. This is mostly applicable to WARNING bugs that won't cause system crash
in production. For these think what will be consequences of the violation of the kernel assumptions flagged
by the WARNING. In some cases the unexpected condition is also properly handled by the normal control flow
(e.g. with "if (WARN_ON(...))"), these won't cause denial-of-service. If the condition is not handled,
then it may or may not cause denial-of-service.
* Accessible From Unprivileged Processes:
Determine if the bug can be reached from a typical (non-root) user process that does NOT have any special capabilities
(like CAP_SYS_ADMIN, CAP_NET_ADMIN, CAP_NET_RAW, CAP_PERFMON) or access to device nodes restricted to root.
Assume that unprivileged_bpf_disabled=1, that is eBPF loading is not accessible. However, cBPF (classical BPF)
is still accessible to non-root processes.
Assume that user namespaces are not accessible, that is, the process cannot get the mentioned capabilities even
within a new user namespace (checked by ns_capable() function in the kernel sources).
* Accessible From User Namespaces:
Determine if the bug can be reached within a user-namespace where the process has all capabilities
(including CAP_SYS_ADMIN, CAP_NET_ADMIN, CAP_NET_RAW, CAP_PERFMON). Such capabilities are checked with ns_capable()
function in the kernel sources.
* VM Guest Trigger:
Determine if the bug can be triggered from the context of a typical KVM guest (e.g., set up by a QEMU VMM).
Consider accesses to standard Linux host paravirtualized features (virtio-blk, virtio-net, etc.),
and handling of VM exits in the KVM code.
* VM Host Trigger in The Confidential Computing Context:
Determine if the bug can be triggered in a confidential computing guest kernel from the context of a KVM host.
Consider access to standard Linux guest paravirtualized features (virtio-blk, virtio-net, etc.).
* Ethernet Network Trigger:
Determine if the bug can be triggered by processing ingress network Ethernet traffic, either directly (network stack)
or via drivers exposed to network data.
* Other Remote Trigger:
Determine if the bug can be triggered by processing remote traffic other than Ethernet (Wifi, Bluetooth, NFC, etc).
* Peripheral Trigger:
Determine if the bug can be triggered via an untrusted peripheral device that can be physically plugged
into a system, such as a USB device or a niche hardware driver handling external hardware inputs.
This is particularly important for mobile and desktop environments where users can plug in unknown devices.
* Malicious Filesystem Trigger:
Determine if the bug can be triggered by the kernel mounting and parsing a malicious filesystem image.
This is highly critical for Desktop and Mobile environments where external media or downloaded images
might be auto-mounted.
Don't make assumptions about the kernel source code (it may be different from what you assume it is).
Extensively use the provided code access tools (codesearch-*, git-*, grepper, etc)
to examine the actual source code, and confirm any assumptions.
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt:
The kernel bug report is:
gfs2: fsid=syz:syz.0: first mount done, others may mount
BUG: sleeping function called from invalid context at kernel/locking/spinlock_rt.c:48
in_atomic(): 1, irqs_disabled(): 0, non_block: 0, pid: 6017, name: syz.0.17
preempt_count: 1, expected: 0
RCU nest depth: 1, expected: 1
4 locks held by syz.0.17/6017:
#0: ffff888035b200d0 (&type->s_umount_key#54/1){+.+.}-{4:4}, at: alloc_super+0x28c/0xac0 fs/super.c:345
#1: ffffffff8e620a78 (qd_lock){+.+.}-{3:3}, at: spin_lock include/linux/spinlock_rt.h:45 [inline]
#1: ffffffff8e620a78 (qd_lock){+.+.}-{3:3}, at: gfs2_quota_init+0x854/0x1220 fs/gfs2/quota.c:1459
#2: ffffffff8dfc8100 (rcu_read_lock){....}-{1:3}, at: rcu_lock_acquire include/linux/rcupdate.h:300 [inline]
#2: ffffffff8dfc8100 (rcu_read_lock){....}-{1:3}, at: rcu_read_lock include/linux/rcupdate.h:838 [inline]
#2: ffffffff8dfc8100 (rcu_read_lock){....}-{1:3}, at: __rt_spin_lock kernel/locking/spinlock_rt.c:50 [inline]
#2: ffffffff8dfc8100 (rcu_read_lock){....}-{1:3}, at: rt_spin_lock+0x1e0/0x400 kernel/locking/spinlock_rt.c:57
#3: ffff88805d082b78 (&lockref->lock#3){+.+.}-{3:3}, at: spin_lock include/linux/spinlock_rt.h:45 [inline]
#3: ffff88805d082b78 (&lockref->lock#3){+.+.}-{3:3}, at: lockref_get_not_dead+0x28/0xd0 lib/lockref.c:155
Preemption disabled at:
[<ffffffff841e0f2b>] bit_spin_lock include/linux/bit_spinlock.h:38 [inline]
[<ffffffff841e0f2b>] hlist_bl_lock include/linux/list_bl.h:149 [inline]
[<ffffffff841e0f2b>] spin_lock_bucket+0x3b/0x150 fs/gfs2/quota.c:98
CPU: 1 UID: 0 PID: 6017 Comm: syz.0.17 Not tainted syzkaller #0 PREEMPT_{RT,(full)}
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 03/18/2026
Call Trace:
<TASK>
dump_stack_lvl+0xe8/0x150 lib/dump_stack.c:120
__might_resched+0x329/0x480 kernel/sched/core.c:9162
__rt_spin_lock kernel/locking/spinlock_rt.c:48 [inline]
rt_spin_lock+0xc2/0x400 kernel/locking/spinlock_rt.c:57
spin_lock include/linux/spinlock_rt.h:45 [inline]
lockref_get_not_dead+0x28/0xd0 lib/lockref.c:155
gfs2_qd_search_bucket+0x139/0x210 fs/gfs2/quota.c:269
gfs2_quota_init+0x86c/0x1220 fs/gfs2/quota.c:1461
gfs2_make_fs_rw+0x143/0x230 fs/gfs2/super.c:149
gfs2_fill_super+0x1bfd/0x2220 fs/gfs2/ops_fstype.c:1275
get_tree_bdev_flags+0x431/0x4f0 fs/super.c:1694
gfs2_get_tree+0x51/0x1e0 fs/gfs2/ops_fstype.c:1332
vfs_get_tree+0x92/0x2a0 fs/super.c:1754
fc_mount fs/namespace.c:1193 [inline]
do_new_mount_fc fs/namespace.c:3758 [inline]
do_new_mount+0x341/0xd30 fs/namespace.c:3834
do_mount fs/namespace.c:4167 [inline]
__do_sys_mount fs/namespace.c:4399 [inline]
__se_sys_mount+0x31d/0x420 fs/namespace.c:4376
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0x15f/0xf80 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7fc2a800da8a
Code: 48 c7 c2 e8 ff ff ff f7 d8 64 89 02 b8 ff ff ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 49 89 ca b8 a5 00 00 00 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 e8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007fff3b870ea8 EFLAGS: 00000246 ORIG_RAX: 00000000000000a5
RAX: ffffffffffffffda RBX: 00007fff3b870f30 RCX: 00007fc2a800da8a
RDX: 00002000000124c0 RSI: 0000200000012500 RDI: 00007fff3b870ef0
RBP: 00002000000124c0 R08: 00007fff3b870f30 R09: 0000000000004800
R10: 0000000000004800 R11: 0000000000000246 R12: 0000200000012500
R13: 00007fff3b870ef0 R14: 00000000000125fd R15: 0000200000000180
</TASK>
gfs2: fsid=syz:syz.0: Corruption found in quota_change0file: duplicate identifier in slot 48768
gfs2: fsid=syz:syz.0: warning: assertion "!qd->qd_change" failed - function = gfs2_qd_dispose, file = fs/gfs2/quota.c, line = 129
CPU: 1 UID: 0 PID: 6017 Comm: syz.0.17 Tainted: G W syzkaller #0 PREEMPT_{RT,(full)}
Tainted: [W]=WARN
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 03/18/2026
Call Trace:
<TASK>
dump_stack_lvl+0xe8/0x150 lib/dump_stack.c:120
gfs2_assert_warn_i+0x194/0x2c0 fs/gfs2/util.c:304
gfs2_qd_dispose+0x466/0x570 fs/gfs2/quota.c:129
gfs2_quota_init+0xcda/0x1220 fs/gfs2/quota.c:1470
gfs2_make_fs_rw+0x143/0x230 fs/gfs2/super.c:149
gfs2_fill_super+0x1bfd/0x2220 fs/gfs2/ops_fstype.c:1275
get_tree_bdev_flags+0x431/0x4f0 fs/super.c:1694
gfs2_get_tree+0x51/0x1e0 fs/gfs2/ops_fstype.c:1332
vfs_get_tree+0x92/0x2a0 fs/super.c:1754
fc_mount fs/namespace.c:1193 [inline]
do_new_mount_fc fs/namespace.c:3758 [inline]
do_new_mount+0x341/0xd30 fs/namespace.c:3834
do_mount fs/namespace.c:4167 [inline]
__do_sys_mount fs/namespace.c:4399 [inline]
__se_sys_mount+0x31d/0x420 fs/namespace.c:4376
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0x15f/0xf80 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7fc2a800da8a
Code: 48 c7 c2 e8 ff ff ff f7 d8 64 89 02 b8 ff ff ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 49 89 ca b8 a5 00 00 00 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 e8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007fff3b870ea8 EFLAGS: 00000246 ORIG_RAX: 00000000000000a5
RAX: ffffffffffffffda RBX: 00007fff3b870f30 RCX: 00007fc2a800da8a
RDX: 00002000000124c0 RSI: 0000200000012500 RDI: 00007fff3b870ef0
RBP: 00002000000124c0 R08: 00007fff3b870f30 R09: 0000000000004800
R10: 0000000000004800 R11: 0000000000000246 R12: 0000200000012500
R13: 00007fff3b870ef0 R14: 00000000000125fd R15: 0000200000000180
</TASK>
gfs2: fsid=syz:syz.0: found 1 quota changes
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;
}
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;
if (write(1, "executing program\n", sizeof("executing program\n") - 1)) {}
// syz_mount_image$gfs2 arguments: [
// fs: ptr[in, buffer] {
// buffer: {67 66 73 32 00} (length 0x5)
// }
// dir: ptr[in, buffer] {
// buffer: {2e 2f 66 69 6c 65 30 00} (length 0x8)
// }
// flags: mount_flags = 0x4800 (8 bytes)
// opts: ptr[inout, array[ANYUNION]] {
// array[ANYUNION] {
// }
// }
// chdir: int8 = 0xff (1 bytes)
// size: len = 0x125fd (8 bytes)
// img: ptr[in, buffer] {
// buffer: (compressed buffer with length 0x125fd)
// }
// ]
// returns fd_dir
memcpy((void*)0x2000000124c0, "gfs2\000", 5);
memcpy((void*)0x200000012500, "./file0\000", 8);
memcpy((void*)0x200000024b40, "... [truncated large byte array] ...", 75261);
syz_mount_image(/*fs=*/0x2000000124c0, /*dir=*/0x200000012500, /*flags=MS_REC|MS_NODIRATIME*/0x4800, /*opts=*/0x200000000180, /*chdir=*/-1, /*size=*/0x125fd, /*img=*/0x200000024b40);
return 0;
}
Reply: Based on the analysis of the bug report and the GFS2 source code, here is the assessment of the vulnerabilities:
**1. RT Spinlock Bug (`sleeping function called from invalid context`)**
In `gfs2_quota_init()`, the code acquires a bucket lock using `spin_lock_bucket()`, which internally uses `hlist_bl_lock()`. On `PREEMPT_RT` kernels, `hlist_bl_lock()` is implemented as a bit spinlock that explicitly disables preemption.
While holding this lock, the code calls `gfs2_qd_search_bucket()`, which in turn calls `lockref_get_not_dead()`. This function attempts to acquire `spin_lock(&lockref->lock)`. On `PREEMPT_RT`, standard spinlocks are mapped to `rt_spin_lock`, which are sleeping locks. Attempting to acquire a sleeping lock while preemption is disabled is invalid and triggers the reported `BUG: sleeping function called from invalid context`. This is a known RT-specific locking constraint violation.
**2. Assertion Failure (`assertion "!qd->qd_change" failed`)**
While parsing the quota change file during mount, if `gfs2_quota_init()` encounters a duplicate quota identifier, it attempts to handle the corruption by dropping the previously allocated quota data object via `qd_put(old_qd)`.
Because the journal is not yet marked as live (`SDF_JOURNAL_LIVE` is not set during this early mount phase), `qd_put()` immediately marks the object as dead and calls `gfs2_qd_dispose()`.
However, `old_qd` was previously initialized with non-zero `qd_change` and `qd_slot_ref` values. `gfs2_qd_dispose()` contains assertions expecting these to be zero (`gfs2_assert_warn(sdp, !qd->qd_change)`), which fail and print the warnings. Consequently, the bit corresponding to this quota slot in `sd_quota_bitmap` is leaked because `slot_put()` is bypassed. The bitmap itself is safely freed upon unmount, meaning this only results in a harmless leaked bit (quota slot exhaustion) rather than a memory corruption or use-after-free.
**Security Impact:**
* **Exploitable:** No. Both issues result in kernel warnings and a minor internal state leak (a bit in a bitmap). There is no memory corruption, out-of-bounds access, or use-after-free that could be leveraged for privilege escalation.
* **Denial of Service:** Yes. The bugs trigger kernel warnings and stack traces. If the kernel is configured with `panic_on_warn` (common in some environments), this will halt the system, leading to a DoS.
* **Unprivileged / User Namespace:** No. GFS2 does not implement the `FS_USERNS_MOUNT` flag. Mounting a GFS2 filesystem strictly requires `CAP_SYS_ADMIN` in the initial user namespace. Unprivileged users cannot trigger this bug directly.
* **Filesystem / Peripheral Trigger:** Yes. The bug is triggered by parsing a maliciously crafted or corrupted GFS2 filesystem image. It can be triggered if a system is configured to auto-mount external media (like USB drives) containing the corrupted image.
|
| 6/2 |
2026/05/31 13:48 |
llm |
expert |
0m
Model:
Tokens:
input: 14965
output: 40
thoughts: 479
Thoughts: **Analyzing a Kernel Bug in GFS2 with PREEMPT_RT**
Okay, so I've got this bug report, and it's pretty clear where the problem lies. The report tells me that a sleeping function is being called from an invalid context, specifically within the `rt_spin_lock` function in `kernel/locking/spinlock_rt.c` at line 48. The context information is also helpful; `in_atomic()` is 1, which isn't ideal, even though interrupts aren't explicitly disabled, and it's not a non-blocking operation. It also looks like a preempt count mismatch.
The stack trace gives us a good breadcrumb trail. We see it starts in a dump stack function, moving to `__might_resched`, then `__rt_spin_lock`, which is where the error surfaces. From there, it goes through `lockref_get_not_dead`, then into the GFS2 filesystem code, hitting `gfs2_qd_search_bucket`, followed by `gfs2_quota_init`, and then finally getting back to the filesystem initialization routines, specifically `gfs2_fill_super` and eventually `gfs2_make_fs_rw`.
The clue that this is being triggered by a corrupted GFS2 filesystem makes a lot of sense, especially because the reproducer involves `syz_mount_image` with `gfs2`. And, of course, the kernel configuration is `PREEMPT_RT`. This setup is important because RT kernels have different locking semantics, and spinlocks are used quite aggressively.
My next step is to drill down into the GFS2 code at the points where this error is happening. I need to focus on `gfs2_quota_init` and `gfs2_qd_search_bucket`. I'll have to figure out how these functions interact with the spinlocks and whether or not they are violating context requirements. I'll need to figure out where the code is attempting to sleep while holding the spinlock and why this is happening. The presence of a corrupted filesystem is likely making matters worse, but the root cause has to be in the code itself.
|
| 7/2 |
2026/05/31 13:48 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/gfs2/quota.c Name:gfs2_quota_init]
Results: map[SourceCode:1389: int gfs2_quota_init(struct gfs2_sbd *sdp)
1390: {
1391: struct gfs2_inode *ip = GFS2_I(sdp->sd_qc_inode);
1392: u64 size = i_size_read(sdp->sd_qc_inode);
1393: unsigned int blocks = size >> sdp->sd_sb.sb_bsize_shift;
1394: unsigned int x, slot = 0;
1395: unsigned int found = 0;
1396: unsigned int hash;
1397: unsigned int bm_size;
1398: struct buffer_head *bh;
1399: u64 dblock;
1400: u32 extlen = 0;
1401: int error;
1402:
1403: if (gfs2_check_internal_file_size(sdp->sd_qc_inode, 1, 64 << 20))
1404: return -EIO;
1405:
1406: sdp->sd_quota_slots = blocks * sdp->sd_qc_per_block;
1407: bm_size = DIV_ROUND_UP(sdp->sd_quota_slots, 8 * sizeof(unsigned long));
1408: bm_size *= sizeof(unsigned long);
1409: error = -ENOMEM;
1410: sdp->sd_quota_bitmap = kzalloc(bm_size, GFP_NOFS | __GFP_NOWARN);
1411: if (sdp->sd_quota_bitmap == NULL)
1412: sdp->sd_quota_bitmap = __vmalloc(bm_size, GFP_NOFS |
1413: __GFP_ZERO);
1414: if (!sdp->sd_quota_bitmap)
1415: return error;
1416:
1417: for (x = 0; x < blocks; x++) {
1418: struct gfs2_quota_change *qc;
1419: unsigned int y;
1420:
1421: if (!extlen) {
1422: extlen = 32;
1423: error = gfs2_get_extent(&ip->i_inode, x, &dblock, &extlen);
1424: if (error)
1425: goto fail;
1426: }
1427: error = -EIO;
1428: bh = gfs2_meta_ra(ip->i_gl, dblock, extlen);
1429: if (!bh)
1430: goto fail;
1431: if (gfs2_metatype_check(sdp, bh, GFS2_METATYPE_QC))
1432: goto fail_brelse;
1433:
1434: qc = (struct gfs2_quota_change *)(bh->b_data + sizeof(struct gfs2_meta_header));
1435: for (y = 0; y < sdp->sd_qc_per_block && slot < sdp->sd_quota_slots;
1436: y++, slot++) {
1437: struct gfs2_quota_data *old_qd, *qd;
1438: s64 qc_change = be64_to_cpu(qc->qc_change);
1439: u32 qc_flags = be32_to_cpu(qc->qc_flags);
1440: enum quota_type qtype = (qc_flags & GFS2_QCF_USER) ?
1441: USRQUOTA : GRPQUOTA;
1442: struct kqid qc_id = make_kqid(&init_user_ns, qtype,
1443: be32_to_cpu(qc->qc_id));
1444: qc++;
1445: if (!qc_change)
1446: continue;
1447:
1448: hash = gfs2_qd_hash(sdp, qc_id);
1449: qd = qd_alloc(hash, sdp, qc_id);
1450: if (qd == NULL)
1451: goto fail_brelse;
1452:
1453: qd->qd_lockref.count = 0;
1454: set_bit(QDF_CHANGE, &qd->qd_flags);
1455: qd->qd_change = qc_change;
1456: qd->qd_slot = slot;
1457: qd->qd_slot_ref = 1;
1458:
1459: spin_lock(&qd_lock);
1460: spin_lock_bucket(hash);
1461: old_qd = gfs2_qd_search_bucket(hash, sdp, qc_id);
1462: if (old_qd) {
1463: fs_err(sdp, "Corruption found in quota_change%u"
1464: "file: duplicate identifier in "
1465: "slot %u\n",
1466: sdp->sd_jdesc->jd_jid, slot);
1467:
1468: spin_unlock_bucket(hash);
1469: spin_unlock(&qd_lock);
1470: qd_put(old_qd);
1471:
1472: gfs2_glock_put(qd->qd_gl);
1473: kmem_cache_free(gfs2_quotad_cachep, qd);
1474:
1475: /* zero out the duplicate slot */
1476: lock_buffer(bh);
1477: memset(qc, 0, sizeof(*qc));
1478: mark_buffer_dirty(bh);
1479: unlock_buffer(bh);
1480:
1481: continue;
1482: }
1483: BUG_ON(test_and_set_bit(slot, sdp->sd_quota_bitmap));
1484: list_add(&qd->qd_list, &sdp->sd_quota_list);
1485: atomic_inc(&sdp->sd_quota_count);
1486: hlist_bl_add_head_rcu(&qd->qd_hlist, &qd_hash_table[hash]);
1487: spin_unlock_bucket(hash);
1488: spin_unlock(&qd_lock);
1489:
1490: found++;
1491: }
1492:
1493: if (buffer_dirty(bh))
1494: sync_dirty_buffer(bh);
1495: brelse(bh);
1496: dblock++;
1497: extlen--;
1498: }
1499:
1500: if (found)
1501: fs_info(sdp, "found %u quota changes\n", found);
1502:
1503: return 0;
1504:
1505: fail_brelse:
1506: if (buffer_dirty(bh))
1507: sync_dirty_buffer(bh);
1508: brelse(bh);
1509: fail:
1510: gfs2_quota_cleanup(sdp);
1511: return error;
1512: }
SourceFile:fs/gfs2/quota.c]
|
| 8/2 |
2026/05/31 13:48 |
llm |
expert |
0m
Model:
Tokens:
input: 18012
output: 42
thoughts: 228
Thoughts: **Debugging a Kernel Spinlock Issue**
Okay, so I've got this interesting kernel bug, a "sleeping function called from invalid context" error, specifically in `kernel/locking/spinlock_rt.c` at line 48. The stack trace is pretty clear on the flow. It looks like `__rt_spin_lock` is being called improperly, likely from a context where it's not allowed. The stack trace dives in via `rt_spin_lock`, through the standard `spin_lock` macro, and then it's bubbling up through a `lockref_get_not_dead` call, and then into `gfs2_qd_search_bucket` within the GFS2 filesystem's quota code. Finally we see that it's all part of `gfs2_quota_init`.
My gut says, this is likely a classic locking issue. I need to figure out *why* this spinlock is being acquired in a context where it's not supposed to be. It seems I should really start by examining the `gfs2_qd_search_bucket` function, and how the lock is used within that context, as well as `spin_lock_bucket` where the lock in question is defined. My first step is to dig into the code and see exactly what's happening and figure out the context.
|
| 9/2 |
2026/05/31 13:48 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/gfs2/quota.c Name:gfs2_qd_search_bucket]
Results: map[SourceCode: 257: static struct gfs2_quota_data *gfs2_qd_search_bucket(unsigned int hash,
258: const struct gfs2_sbd *sdp,
259: struct kqid qid)
260: {
261: struct gfs2_quota_data *qd;
262: struct hlist_bl_node *h;
263:
264: hlist_bl_for_each_entry_rcu(qd, h, &qd_hash_table[hash], qd_hlist) {
265: if (!qid_eq(qd->qd_id, qid))
266: continue;
267: if (qd->qd_sbd != sdp)
268: continue;
269: if (lockref_get_not_dead(&qd->qd_lockref)) {
270: list_lru_del_obj(&gfs2_qd_lru, &qd->qd_lru);
271: return qd;
272: }
273: }
274:
275: return NULL;
276: }
SourceFile:fs/gfs2/quota.c]
|
| 10/2 |
2026/05/31 13:48 |
llm |
expert |
0m
Model:
Tokens:
input: 18928
output: 38
thoughts: 8
Thoughts: Okay, here's my summary, framed as my internal thought process, assuming I'm already well-versed in the subject:
**Analyzing the `spin_lock_bucket` Approach**
Alright, let's break down this `spin_lock_bucket` concept. Immediately, my mind goes to concurrency control, and the potential performance implications. Spinlocks, of course, are a low-level, primitive method; they're generally quick for uncontended access but can be devastatingly inefficient under high contention, leading to CPU cycles wasted in busy-waiting. The "bucket" part suggests some form of partitioning or hashing of the data being protected. The intent is likely to reduce contention on a single global lock by distributing the lock protection across multiple smaller locks.
So, the key questions immediately pop up: What's the granularity of the bucket? How many buckets are there? What's the hashing function? Is the hashing function sufficiently collision-resistant to provide meaningful reduction in contention in practical scenarios? If collisions are too frequent, the benefits of using the bucketed locks is going to be greatly diminished. Then I need to understand the potential performance tradeoffs: Is the overhead of calculating the hash and acquiring the specific bucket lock outweighing the benefits of reduced contention? This depends on the ratio of uncontended accesses to contended access, and the performance characteristics of the hash function and the bucket lock implementation. Are we talking about a simple array of spinlocks, or is there more sophisticated metadata associated with each bucket (e.g., counters, waiting lists)?
I also want to consider the context. What is this `spin_lock_bucket` used to protect? Is it a data structure, a shared resource, a kernel structure? The nature of the data/resource being protected significantly impacts the effectiveness of this approach. How often is the resource being accessed? Are there read-mostly scenarios, or are we dealing with frequent updates? If it's read-mostly, perhaps a read-write lock would provide even better performance.
Finally, I'll need to look at the other synchronization primitives, perhaps a comparison of how they are used. In a lot of cases, it might be the case that a compare-and-swap (CAS) operation might be better, or perhaps even using atomic operations.
|
| 11/2 |
2026/05/31 13:48 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/gfs2/quota.c Name:spin_lock_bucket]
Results: map[SourceCode: 96: static inline void spin_lock_bucket(unsigned int hash)
97: {
98: hlist_bl_lock(&qd_hash_table[hash]);
99: }
SourceFile:fs/gfs2/quota.c]
|
| 12/2 |
2026/05/31 13:48 |
llm |
expert |
0m
Model:
Tokens:
input: 19533
output: 40
thoughts: 1258
Thoughts: **Analyzing a PREEMPT_RT Sleeping Lock Bug in GFS2 Quota Code**
Okay, so I'm looking at this bug report, and it seems like we have a classic "sleeping function called from invalid context" issue, specifically in the GFS2 quota code, which is interesting. It all hinges on how `PREEMPT_RT` interacts with bit spinlocks and sleeping locks.
My first thought is, ah, `hlist_bl_lock` β that's a bit spinlock, right? And in a real-time (RT) kernel, bit spinlocks disable preemption, but they *don't* disable interrupts. So, the code calls `lockref_get_not_dead(&qd->qd_lockref)`. Inside, that calls `spin_lock(&lockref->lock)`. And *that's* where the trouble starts.
In PREEMPT_RT, `spin_lock` becomes an `rt_spin_lock`, which *can* sleep. It's a sleeping lock. So, the code is trying to sleep using `rt_spin_lock` while *already holding* `hlist_bl_lock`, the bit spinlock, which disables preemption. It's a textbook example of a sleeping function called from an invalid context!
The bug report confirms this. The stack trace, shows that the code is calling `rt_spin_lock` from within a context where preemption is disabled because of that `hlist_bl_lock`. Specifically, the report shows that the preemption is disabled at the call to `spin_lock_bucket`, which holds `hlist_bl_lock`.
The report also shows what locks are held during the issue:
* `&type->s_umount_key#54/1`: at `alloc_super`
* `qd_lock` which is acquired and released by calls to `gfs2_quota_init` and `spin_lock` (likely for synchronization between quota processes).
* `rcu_read_lock` which seems to be acquired while calling `rt_spin_lock`
* `&lockref->lock#3`: at `lockref_get_not_dead`
This is definitely a `PREEMPT_RT`-specific issue because in a non-RT kernel, `spin_lock` is a regular spinlock, and wouldn't sleep.
Now, I need to figure out the severity and if this is more than just a warning. The bug report says `BUG: sleeping function called from invalid context`, but is this an actual kernel panic, or just a warning? Usually, such a message, printed by `___might_sleep` in `kernel/sched/core.c`, uses `printk(KERN_ERR ...)`, which, by itself, doesn't halt the system. It usually only prints a stack trace, unless a `panic_on_warn` option is configured. So, it's probably not a complete system halt, but a strong indication of a problem.
The report also mentions an assertion failure in GFS2, `gfs2: fsid=syz:syz.0: warning: assertion "!qd->qd_change" failed - function = gfs2_qd_dispose, file = fs/gfs2/quota.c, line = 129`, which adds another layer of complexity. This could be a symptom of the underlying locking issue.
So, in summary, we've got a sleeping lock called from an invalid context in PREEMPT_RT, likely leading to a warning or, depending on configuration, a more severe kernel issue. The second error suggests a possible corruption of data, as well.
|
| 13/2 |
2026/05/31 13:49 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/gfs2/quota.c Name:gfs2_qd_dispose]
Results: map[SourceCode: 116: static void gfs2_qd_dispose(struct gfs2_quota_data *qd)
117: {
118: struct gfs2_sbd *sdp = qd->qd_sbd;
119:
120: spin_lock(&qd_lock);
121: list_del(&qd->qd_list);
122: spin_unlock(&qd_lock);
123:
124: spin_lock_bucket(qd->qd_hash);
125: hlist_bl_del_rcu(&qd->qd_hlist);
126: spin_unlock_bucket(qd->qd_hash);
127:
128: if (!gfs2_withdrawn(sdp)) {
129: gfs2_assert_warn(sdp, !qd->qd_change);
130: gfs2_assert_warn(sdp, !qd->qd_slot_ref);
131: gfs2_assert_warn(sdp, !qd->qd_bh_count);
132: }
133:
134: gfs2_glock_put(qd->qd_gl);
135: call_rcu(&qd->qd_rcu, gfs2_qd_dealloc);
136: }
SourceFile:fs/gfs2/quota.c]
|
| 14/2 |
2026/05/31 13:49 |
llm |
expert |
0m
Model:
Tokens:
input: 22021
output: 40
thoughts: 102
Thoughts: **Debugging a Quota Initialization Assertion**
Okay, so I've hit an assertion failure, specifically `gfs2_assert_warn(sdp, !qd->qd_change)`. I've seen this before, and it's popping up from quota initialization (`gfs2_quota_init`). Tracing through the code, I see this leads to `qd_put(old_qd)`, which in turn *might* trigger `gfs2_qd_dispose`. Ah, right, `qd_put` calls `gfs2_qd_dispose` when the reference count drops to zero. That's the likely scenario, but I need to make sure. Let me go back and re-examine the `gfs2_quota_init` function and understand what is happening with the reference counting. This assertion almost certainly indicates a race or some issue with how the quota descriptors are managed during initialization, and I need to figure out the exact sequence.
|
| 15/2 |
2026/05/31 13:49 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/gfs2/quota.c Name:gfs2_quota_init]
Results: map[SourceCode:1389: int gfs2_quota_init(struct gfs2_sbd *sdp)
1390: {
1391: struct gfs2_inode *ip = GFS2_I(sdp->sd_qc_inode);
1392: u64 size = i_size_read(sdp->sd_qc_inode);
1393: unsigned int blocks = size >> sdp->sd_sb.sb_bsize_shift;
1394: unsigned int x, slot = 0;
1395: unsigned int found = 0;
1396: unsigned int hash;
1397: unsigned int bm_size;
1398: struct buffer_head *bh;
1399: u64 dblock;
1400: u32 extlen = 0;
1401: int error;
1402:
1403: if (gfs2_check_internal_file_size(sdp->sd_qc_inode, 1, 64 << 20))
1404: return -EIO;
1405:
1406: sdp->sd_quota_slots = blocks * sdp->sd_qc_per_block;
1407: bm_size = DIV_ROUND_UP(sdp->sd_quota_slots, 8 * sizeof(unsigned long));
1408: bm_size *= sizeof(unsigned long);
1409: error = -ENOMEM;
1410: sdp->sd_quota_bitmap = kzalloc(bm_size, GFP_NOFS | __GFP_NOWARN);
1411: if (sdp->sd_quota_bitmap == NULL)
1412: sdp->sd_quota_bitmap = __vmalloc(bm_size, GFP_NOFS |
1413: __GFP_ZERO);
1414: if (!sdp->sd_quota_bitmap)
1415: return error;
1416:
1417: for (x = 0; x < blocks; x++) {
1418: struct gfs2_quota_change *qc;
1419: unsigned int y;
1420:
1421: if (!extlen) {
1422: extlen = 32;
1423: error = gfs2_get_extent(&ip->i_inode, x, &dblock, &extlen);
1424: if (error)
1425: goto fail;
1426: }
1427: error = -EIO;
1428: bh = gfs2_meta_ra(ip->i_gl, dblock, extlen);
1429: if (!bh)
1430: goto fail;
1431: if (gfs2_metatype_check(sdp, bh, GFS2_METATYPE_QC))
1432: goto fail_brelse;
1433:
1434: qc = (struct gfs2_quota_change *)(bh->b_data + sizeof(struct gfs2_meta_header));
1435: for (y = 0; y < sdp->sd_qc_per_block && slot < sdp->sd_quota_slots;
1436: y++, slot++) {
1437: struct gfs2_quota_data *old_qd, *qd;
1438: s64 qc_change = be64_to_cpu(qc->qc_change);
1439: u32 qc_flags = be32_to_cpu(qc->qc_flags);
1440: enum quota_type qtype = (qc_flags & GFS2_QCF_USER) ?
1441: USRQUOTA : GRPQUOTA;
1442: struct kqid qc_id = make_kqid(&init_user_ns, qtype,
1443: be32_to_cpu(qc->qc_id));
1444: qc++;
1445: if (!qc_change)
1446: continue;
1447:
1448: hash = gfs2_qd_hash(sdp, qc_id);
1449: qd = qd_alloc(hash, sdp, qc_id);
1450: if (qd == NULL)
1451: goto fail_brelse;
1452:
1453: qd->qd_lockref.count = 0;
1454: set_bit(QDF_CHANGE, &qd->qd_flags);
1455: qd->qd_change = qc_change;
1456: qd->qd_slot = slot;
1457: qd->qd_slot_ref = 1;
1458:
1459: spin_lock(&qd_lock);
1460: spin_lock_bucket(hash);
1461: old_qd = gfs2_qd_search_bucket(hash, sdp, qc_id);
1462: if (old_qd) {
1463: fs_err(sdp, "Corruption found in quota_change%u"
1464: "file: duplicate identifier in "
1465: "slot %u\n",
1466: sdp->sd_jdesc->jd_jid, slot);
1467:
1468: spin_unlock_bucket(hash);
1469: spin_unlock(&qd_lock);
1470: qd_put(old_qd);
1471:
1472: gfs2_glock_put(qd->qd_gl);
1473: kmem_cache_free(gfs2_quotad_cachep, qd);
1474:
1475: /* zero out the duplicate slot */
1476: lock_buffer(bh);
1477: memset(qc, 0, sizeof(*qc));
1478: mark_buffer_dirty(bh);
1479: unlock_buffer(bh);
1480:
1481: continue;
1482: }
1483: BUG_ON(test_and_set_bit(slot, sdp->sd_quota_bitmap));
1484: list_add(&qd->qd_list, &sdp->sd_quota_list);
1485: atomic_inc(&sdp->sd_quota_count);
1486: hlist_bl_add_head_rcu(&qd->qd_hlist, &qd_hash_table[hash]);
1487: spin_unlock_bucket(hash);
1488: spin_unlock(&qd_lock);
1489:
1490: found++;
1491: }
1492:
1493: if (buffer_dirty(bh))
1494: sync_dirty_buffer(bh);
1495: brelse(bh);
1496: dblock++;
1497: extlen--;
1498: }
1499:
1500: if (found)
1501: fs_info(sdp, "found %u quota changes\n", found);
1502:
1503: return 0;
1504:
1505: fail_brelse:
1506: if (buffer_dirty(bh))
1507: sync_dirty_buffer(bh);
1508: brelse(bh);
1509: fail:
1510: gfs2_quota_cleanup(sdp);
1511: return error;
1512: }
SourceFile:fs/gfs2/quota.c]
|
| 16/2 |
2026/05/31 13:49 |
llm |
expert |
0m
Model:
Tokens:
input: 24431
output: 38
thoughts: 582
Thoughts: **Analyzing a Potential Quota Change Corruption**
Okay, let's break this down. I'm looking at this code snippet, specifically focusing on how quota change entries are handled. The first part, the standard locking and searching for a duplicate entry (`old_qd`), makes sense. We grab the locks, search the bucket, and if we find a duplicate, we log an error. Then, and this is the crux of it, we call `qd_put(old_qd)`.
Hang on a second. `qd_put` *decrements* the lockref count, right? And `old_qd` was returned by `gfs2_qd_search_bucket`, which *incremented* the lockref count. So far, so good. But the duplicate implies this entry was added in a *previous* iteration. And when it was initially added, `qd->qd_change` would have been set to a non-zero value because we are detecting a change. So, the question becomes, why is it being called again?
Now I see it. When `old_qd` was initially *added* to the hash table, `qd->qd_lockref.count` was explicitly set to 0. Right, the code snippet shows it: `qd->qd_lockref.count = 0`. Then, `set_bit(QDF_CHANGE, &qd->qd_flags)` is called along with `qd->qd_change = qc_change;` and the slot info is updated.
Then, the second invocation of the code comes around with `spin_lock(&qd_lock);` and `spin_lock_bucket(hash);` and then another `gfs2_qd_search_bucket(hash, sdp, qc_id);`.
Okay, the crucial part: in the initial addition the `qd_lockref.count` was zero, and later `gfs2_qd_search_bucket` increments the lockref with `lockref_get_not_dead(&qd->qd_lockref)`.
Aha! Now this is where it's interesting. `lockref_get_not_dead` *should* increment the lockref count. But, if the count is zero, `lockref_get_not_dead` returns zero, unless the object is not dead. And if `count` is 0, does `lockref_get_not_dead` actually increment the count to 1? This warrants further investigation. I need to dive into the implementation of `lockref_get_not_dead` to confirm the behavior when the initial count is zero. I need to confirm whether this scenario is valid, or a race condition, or what. Let's dig into that function.
|
| 17/2 |
2026/05/31 13:49 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:lib/lockref.c Name:lockref_get_not_dead]
Results: map[SourceCode: 138: /**
139: * lockref_get_not_dead - Increments count unless the ref is dead
140: * @lockref: pointer to lockref structure
141: * Return: 1 if count updated successfully or 0 if lockref was dead
142: */
143: bool lockref_get_not_dead(struct lockref *lockref)
144: {
145: bool retval = false;
146:
147: CMPXCHG_LOOP(
148: new.count++;
149: if (old.count < 0)
150: return false;
151: ,
152: return true;
153: );
154:
155: spin_lock(&lockref->lock);
156: if (lockref->count >= 0) {
157: lockref->count++;
158: retval = true;
159: }
160: spin_unlock(&lockref->lock);
161: return retval;
162: }
SourceFile:lib/lockref.c]
|
| 18/2 |
2026/05/31 13:49 |
llm |
expert |
0m
Model:
Tokens:
input: 25982
output: 36
thoughts: 80
Thoughts: Here's my understanding of the situation, given my expertise:
**Lock Reference Behavior in GFS2**
Okay, so `lockref_get_not_dead` has a simple condition: it succeeds, returning `true`, if the internal `count` is greater than or equal to zero. If `count` is currently zero, then it cleverly increments `count` to one and *still* returns `true`. This implies that the lock is now acquired. It seems like the purpose of this is to establish a valid lock if one does not already exist.
This sets the stage. The function `gfs2_qd_search_bucket` then returns an `old_qd` (presumably a "quiesce descriptor" or something similar) with its internal `count` now sitting at one, the value we just established. Finally, `qd_put(old_qd)` is invoked. Now the interesting question is whether `qd_put` will decrement the count, and potentially free this, and that will be my next area to investigate.
|
| 19/2 |
2026/05/31 13:49 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/gfs2/quota.c Name:qd_put]
Results: map[SourceCode: 324: static void qd_put(struct gfs2_quota_data *qd)
325: {
326: struct gfs2_sbd *sdp;
327:
328: if (lockref_put_or_lock(&qd->qd_lockref))
329: return;
330:
331: BUG_ON(__lockref_is_dead(&qd->qd_lockref));
332: sdp = qd->qd_sbd;
333: if (unlikely(!test_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags))) {
334: lockref_mark_dead(&qd->qd_lockref);
335: spin_unlock(&qd->qd_lockref.lock);
336:
337: list_lru_del_obj(&gfs2_qd_lru, &qd->qd_lru);
338: gfs2_qd_dispose(qd);
339: return;
340: }
341:
342: qd->qd_lockref.count = 0;
343: list_lru_add_obj(&gfs2_qd_lru, &qd->qd_lru);
344: spin_unlock(&qd->qd_lockref.lock);
345: }
SourceFile:fs/gfs2/quota.c]
|
| 20/2 |
2026/05/31 13:49 |
llm |
expert |
0m
Model:
Tokens:
input: 26727
output: 32
thoughts: 2153
Thoughts: **Quota Change Handling and RT-Specific Deadlock in GFS2**
Alright, let's break this down. My analysis points to a few interlinked issues within GFS2's quota management, particularly when dealing with quota changes and mount operations. It appears we have a combination of a logic error and an RT-specific locking issue.
The core of the problem lies in the handling of `qd_put` and `gfs2_qd_dispose` during filesystem initialization, specifically within `gfs2_quota_init`. It seems that when a duplicate quota change identifier is encountered, a previously existing quota descriptor (`old_qd`) can be prematurely freed because the `SDF_JOURNAL_LIVE` flag isn't set yet. This leads to a chain of events:
1. `old_qd` is created with a `qd_lockref.count = 0` and placed in both a hash table and a list (`sdp->sd_quota_list`).
2. A duplicate is detected, `gfs2_qd_search_bucket` finds `old_qd`. It increments the count to 1.
3. `qd_put` is called on `old_qd` because the live flag is not set.
4. Because `SDF_JOURNAL_LIVE` is not set, `qd_put` frees `old_qd` (via `gfs2_qd_dispose`), despite it being in the hash and list! This happens before the journal is live!
The consequence? We're losing a legitimate quota change and, more problematically, leaking a bit in `sd_quota_bitmap`. This is not a memory corruption, but it is a logic error that causes quota changes to be dropped and a bit leak in the quota bitmap.
On the real-time (RT) kernel side, we have a more interesting but less critical bug. The function `gfs2_qd_search_bucket` appears to call `lockref_get_not_dead`, which takes a spinlock while holding a bit spinlock. On PREEMPT_RT kernels, the spinlock taken by `lockref_get_not_dead` can sleep, and a sleep while holding the bit spinlock can trigger this "sleeping function called from invalid context" BUG. This issue is specific to RT kernels, since a normal kernel takes a raw spinlock that does not sleep. This is essentially a denial-of-service, a BUG from an invalid context, which can cause scheduling issues.
So, in essence, we're looking at a logic bug that drops quota changes and a bit leak during quota initialization, which is not exploitable as a memory corruption, plus an RT-specific issue that could lead to a denial-of-service on RT kernels. The RT bug is not a memory corruption either.
|
| 21/2 |
2026/05/31 13:49 |
tool |
grepper |
0m
Error:
Args: map[Expression:FS_USERNS_MOUNT PathPrefix:fs/gfs2]
Results:
|
| 22/2 |
2026/05/31 13:49 |
llm |
expert |
0m
Model:
Tokens:
input: 29531
output: 40
thoughts: 351
Thoughts: **GFS2 Mounting and Quota Assertion: A Deep Dive**
Okay, so GFS2 is giving me some grief. It seems pretty clear that GFS2 lacks the `FS_USERNS_MOUNT` flag, which means it can't be mounted within a user namespace. That's a real limitation. Consequently, it's going to need `CAP_SYS_ADMIN` in the initial user namespace. This makes it a no-go for unprivileged processes, and forget about using it from within user namespaces β that's a dead end.
Now, hold on... what about that second bug? This `warning: assertion "!qd->qd_change" failed` from `gfs2_qd_dispose` has me intrigued. It looks like an assertion failure. Let's see... looking at the code, itβs a warning. My initial thought is, it should not panic the kernel unless the mount option `errors=panic` is set.
Ah, but the syzkaller reproducer... I remember now, that they're using `errors=withdraw` or `errors=continue`. That makes the warning potentially significant. So, it's *just* a warning, but that doesn't mean it's benign. It's not a kernel panic, but I need to investigate further. A warning from an assertion failure could indicate a much deeper problem. Is there the potential for memory corruption? I need to analyze `gfs2_qd_dispose` thoroughly and see where things stand.
|
| 23/2 |
2026/05/31 13:50 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/gfs2/quota.c Name:gfs2_qd_dispose]
Results: map[SourceCode: 116: static void gfs2_qd_dispose(struct gfs2_quota_data *qd)
117: {
118: struct gfs2_sbd *sdp = qd->qd_sbd;
119:
120: spin_lock(&qd_lock);
121: list_del(&qd->qd_list);
122: spin_unlock(&qd_lock);
123:
124: spin_lock_bucket(qd->qd_hash);
125: hlist_bl_del_rcu(&qd->qd_hlist);
126: spin_unlock_bucket(qd->qd_hash);
127:
128: if (!gfs2_withdrawn(sdp)) {
129: gfs2_assert_warn(sdp, !qd->qd_change);
130: gfs2_assert_warn(sdp, !qd->qd_slot_ref);
131: gfs2_assert_warn(sdp, !qd->qd_bh_count);
132: }
133:
134: gfs2_glock_put(qd->qd_gl);
135: call_rcu(&qd->qd_rcu, gfs2_qd_dealloc);
136: }
SourceFile:fs/gfs2/quota.c]
|
| 24/2 |
2026/05/31 13:50 |
llm |
expert |
0m
Model:
Tokens:
input: 30638
output: 38
thoughts: 236
Thoughts: **Quota Deletion Deep Dive**
Okay, so I'm tracing the quota descriptor deletion process, and the core actions are pretty clear: `list_del(&qd->qd_list)` is used to remove the descriptor from the `sdp->sd_quota_list`, and then `hlist_bl_del_rcu(&qd->qd_hlist)` removes it from the `qd_hash_table`. Finally, the code places the glock and calls `gfs2_qd_dealloc` using RCU. Standard stuff so far.
Now I'm trying to ensure I'm accounting for all references to `qd`. Let me backtrack to where `old_qd` (the previous descriptor) was added in `gfs2_quota_init`. Right, it calls `BUG_ON`, `list_add`, and importantly, `atomic_inc(&sdp->sd_quota_count)`. I expect a matching decrement somewhere during disposal...
Wait a second. I'm now looking at `gfs2_qd_dispose`, the expected cleanup function, and I don't see any decrement of `sdp->sd_quota_count`! That's a serious potential leak. I need to investigate where else `sd_quota_count` is handled to make sure there's not an imbalance. This could mean a memory leak or other serious quota accounting errors if left unchecked! Let's check where the count is decremented.
|
| 25/2 |
2026/05/31 13:50 |
tool |
codesearch-find-references |
0m
Error:
Args: map[ContextFile:fs/gfs2/quota.c Name:sd_quota_count]
Results: map[References:<nil> TruncatedOutput:false]
|
| 26/2 |
2026/05/31 13:50 |
llm |
expert |
0m
Model:
Tokens:
input: 31246
output: 30
thoughts: 29
Thoughts: Okay, here's my attempt at summarizing those thoughts from an expert's perspective, using the first person and aiming for a fulsome rendering:
**Digging into the GFS2 SBD Structure**
Right, okay, I'm diving into the `struct gfs2_sbd` again. Need to find something related to quotas, and the most likely candidate in my mind is a counter field. Let me start with a quick search for `sd_quota_count`. It's likely involved in tracking either the number of quota operations currently active, or perhaps the number of outstanding quota blocks or allocations. Let's see what the code around it reveals.
|
| 27/2 |
2026/05/31 13:50 |
tool |
grepper |
0m
Args: map[Expression:sd_quota_count PathPrefix:fs/gfs2]
Results: map[Output:fs/gfs2/incore.h=683=struct gfs2_sbd {
--
fs/gfs2/incore.h-785- struct list_head sd_quota_list;
fs/gfs2/incore.h:786: atomic_t sd_quota_count;
fs/gfs2/incore.h-787- struct mutex sd_quota_sync_mutex;
--
fs/gfs2/quota.c=106=static void gfs2_qd_dealloc(struct rcu_head *rcu)
--
fs/gfs2/quota.c-111- kmem_cache_free(gfs2_quotad_cachep, qd);
fs/gfs2/quota.c:112: if (atomic_dec_and_test(&sdp->sd_quota_count))
fs/gfs2/quota.c-113- wake_up(&sdp->sd_kill_wait);
--
fs/gfs2/quota.c=279=static int qd_get(struct gfs2_sbd *sdp, struct kqid qid,
--
fs/gfs2/quota.c-302- hlist_bl_add_head_rcu(&new_qd->qd_hlist, &qd_hash_table[hash]);
fs/gfs2/quota.c:303: atomic_inc(&sdp->sd_quota_count);
fs/gfs2/quota.c-304- }
--
fs/gfs2/quota.c=1389=int gfs2_quota_init(struct gfs2_sbd *sdp)
--
fs/gfs2/quota.c-1484- list_add(&qd->qd_list, &sdp->sd_quota_list);
fs/gfs2/quota.c:1485: atomic_inc(&sdp->sd_quota_count);
fs/gfs2/quota.c-1486- hlist_bl_add_head_rcu(&qd->qd_hlist, &qd_hash_table[hash]);
--
fs/gfs2/quota.c=1514=void gfs2_quota_cleanup(struct gfs2_sbd *sdp)
--
fs/gfs2/quota.c-1540- wait_event_timeout(sdp->sd_kill_wait,
fs/gfs2/quota.c:1541: (count = atomic_read(&sdp->sd_quota_count)) == 0,
fs/gfs2/quota.c-1542- HZ * 60);
]
|
| 28/2 |
2026/05/31 13:50 |
llm |
expert |
0m
Model:
Tokens:
input: 32121
output: 34
thoughts: 304
Thoughts: **Quota Data Bit Management**
Okay, so I'm looking at how quota data is handled in GFS2, specifically concerning the reference count and bitmap tracking. I see that `sd_quota_count` is correctly decremented in `gfs2_qd_dealloc`, which makes sense because that's where the quota data structure (`gfs2_quota_data`) is freed. I understand that the associated structure `gfs2_quota_data` with its associated quota data for a given slot is freed with `kmem_cache_free(gfs2_quotad_cachep, qd)`.
Now, what about the associated bit in `sd_quota_bitmap`? I remember seeing it being set during initialization in `gfs2_quota_init` with `test_and_set_bit`. That makes perfect sense. Now, the key question is, when the corresponding `gfs2_quota_data` is freed, is that bitmap bit cleared? I need to confirm there's no memory leak, or incorrect quota accounting.
Let me examine `gfs2_qd_dispose` and `gfs2_qd_dealloc` closely. No, neither of those functions contain a `clear_bit` call on the bitmap. I had a quick look through both.
Wait a second...I'm being dense. `qd->qd_slot`! That's it! `qd->qd_slot` holds the index of the bit that *needs* to be cleared. So now I need to figure out where and *if* that bit is cleared when the quota data is no longer needed. I'm sure it's handled somewhere but I need to figure out the exact location.
|
| 29/2 |
2026/05/31 13:50 |
tool |
grepper |
0m
Args: map[Expression:clear_bit.*sd_quota_bitmap PathPrefix:fs/gfs2]
Results: map[Output:fs/gfs2/quota.c=380=static void slot_put(struct gfs2_quota_data *qd)
--
fs/gfs2/quota.c-386- if (!--qd->qd_slot_ref) {
fs/gfs2/quota.c:387: BUG_ON(!test_and_clear_bit(qd->qd_slot, sdp->sd_quota_bitmap));
fs/gfs2/quota.c-388- qd->qd_slot = -1;
]
|
| 30/2 |
2026/05/31 13:50 |
llm |
expert |
0m
Model:
Tokens:
input: 32969
output: 40
thoughts: 425
Thoughts: **Quota Slot Leakage in GFS2**
Okay, so I've been looking at this `slot_put` function, and it's pretty straightforward: it decrements `qd_slot_ref` and, when it hits zero, clears a bit in `sd_quota_bitmap`. That's how it should work to free up quota slots. The bit is cleared with `test_and_clear_bit`, which is pretty standard.
Now, the issue is with `gfs2_qd_dispose`. It *doesn't* call `slot_put` directly. That's a red flag. But, hang on... it *does* assert that `!qd->qd_slot_ref`. Because the `old_qd` I'm dealing with has `qd_slot_ref = 1`, that assertion *fails*. And because the assertion fails, `slot_put` is never called! Thus, the bit isn't cleared. It's leaked.
So, a bit is leaked in `sd_quota_bitmap`. What does that actually *mean*? Well, it essentially makes the quota slot look "in use," even though it's been freed. When the filesystem tries to allocate a new quota slot, it will skip this bit. If all bits are used, it might fail to allocate a quota slot. That's a denial of service, quota slot exhaustion. However, this DoS requires mounting a corrupted filesystem. Since mounting requires `CAP_SYS_ADMIN`, it's not a security vulnerability. That's a relief!
But... is that *it*? This might have consequences beyond the immediate denial of service. The `old_qd` is freed, but the bit is still set. Hmm... later, during unmount, `gfs2_quota_cleanup` is called. That sounds like a possible point of further investigation.
|
| 31/2 |
2026/05/31 13:50 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/gfs2/quota.c Name:gfs2_quota_cleanup]
Results: map[SourceCode:1514: void gfs2_quota_cleanup(struct gfs2_sbd *sdp)
1515: {
1516: struct gfs2_quota_data *qd;
1517: LIST_HEAD(dispose);
1518: int count;
1519:
1520: BUG_ON(!test_bit(SDF_NORECOVERY, &sdp->sd_flags) &&
1521: test_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags));
1522:
1523: spin_lock(&qd_lock);
1524: list_for_each_entry(qd, &sdp->sd_quota_list, qd_list) {
1525: spin_lock(&qd->qd_lockref.lock);
1526: if (qd->qd_lockref.count != 0) {
1527: spin_unlock(&qd->qd_lockref.lock);
1528: continue;
1529: }
1530: lockref_mark_dead(&qd->qd_lockref);
1531: spin_unlock(&qd->qd_lockref.lock);
1532:
1533: list_lru_del_obj(&gfs2_qd_lru, &qd->qd_lru);
1534: list_add(&qd->qd_lru, &dispose);
1535: }
1536: spin_unlock(&qd_lock);
1537:
1538: gfs2_qd_list_dispose(&dispose);
1539:
1540: wait_event_timeout(sdp->sd_kill_wait,
1541: (count = atomic_read(&sdp->sd_quota_count)) == 0,
1542: HZ * 60);
1543:
1544: if (count != 0)
1545: fs_err(sdp, "%d left-over quota data objects\n", count);
1546:
1547: kvfree(sdp->sd_quota_bitmap);
1548: sdp->sd_quota_bitmap = NULL;
1549: }
SourceFile:fs/gfs2/quota.c]
|
| 32/2 |
2026/05/31 13:50 |
llm |
expert |
0m
Model:
Tokens:
input: 34460
output: 40
thoughts: 1021
Thoughts: **Analyzing the Quota Cleanup and Potential Use-After-Free**
Okay, let's break this down. `gfs2_quota_cleanup` frees `sdp->sd_quota_bitmap`. That much is straightforward. The function doesn't care if bits are still set in the bitmap, so there's no memory leak there. The initial assertion failure and warning are the only things to worry about.
But wait, what about `gfs2_qd_dispose` and its interaction with `sd_quota_list`? Could there be an issue with freeing `old_qd` while it's still linked? Nope. Looking at the code:
```c
spin_lock(&qd_lock);
list_del(&qd->qd_list);
spin_unlock(&qd_lock);
```
`gfs2_qd_dispose` removes `qd` (which is `old_qd` in the context we're examining) from `sd_quota_list` *before* freeing it. That's safe, good.
Now, a more insidious thought: is there a potential use-after-free scenario? Let's trace it through `gfs2_quota_init`.
```c
if (old_qd) {
fs_err(sdp, "Corruption found in quota_change%u"
"file: duplicate identifier in "
"slot %u\n",
sdp->sd_jdesc->jd_jid, slot);
spin_unlock_bucket(hash);
spin_unlock(&qd_lock);
qd_put(old_qd);
gfs2_glock_put(qd->qd_gl);
kmem_cache_free(gfs2_quotad_cachep, qd);
/* zero out the duplicate slot */
lock_buffer(bh);
memset(qc, 0, sizeof(*qc));
mark_buffer_dirty(bh);
unlock_buffer(bh);
continue;
}
```
Okay, `old_qd` is *the first instance* of this quota identifier. We've just found a *duplicate*. We call `qd_put(old_qd)`. Since `SDF_JOURNAL_LIVE` is not set, `qd_put` marks it as dead and calls `gfs2_qd_dispose(old_qd)`. And `gfs2_qd_dispose` removes it from `sd_quota_list` and `qd_hash_table`, and frees it via RCU. So far, so good.
But wait! A critical detail! `old_qd` was the *first instance*! The new `qd` (the duplicate) is freed directly after `qd_put`. Both `old_qd` and `qd` are freed, essentially. The first instance's metadata is removed from the list and hash.
Now, consider the quota change file. We *only* zero out the *duplicate* slot:
```c
/* zero out the duplicate slot */
lock_buffer(bh);
memset(qc, 0, sizeof(*qc));
mark_buffer_dirty(bh);
unlock_buffer(bh);
```
The FIRST slot (corresponding to `old_qd`) is left untouched! And we freed its `qd`!
So, we have a valid quota change record in the file, but no corresponding `qd` in memory. Is this a ticking time bomb?
When the filesystem is mounted, it syncs quotas. Will it try to access the freed `old_qd`? No, because it's removed from the list and the hash table. Will it try to re-read the quota change file? No, `gfs2_quota_init` reads it only once.
But here's a wrinkle: the bit in `sd_quota_bitmap` corresponding to `old_qd->qd_slot` is *still set*! `gfs2_qd_dispose` didn't clear it (because of an assertion!). So there's a set bit, but no `qd`. New quota change allocations will likely skip this slot. When unmounting, the bitmap is just freed.
So, is there a real problem? There is no clear use-after-free, but we have a bitmap that doesn't correspond to current data. This *could* cause issues if `gfs2_quota_sync` is called. It would be worth investigating the syncing behavior, how it interacts with the bitmap, and if it could attempt to interpret a stale bitmap bit. The assertion failure, and leaving the bitmap bit set, is a
|
| 33/2 |
2026/05/31 13:50 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/gfs2/quota.c Name:gfs2_quota_sync]
Results: map[SourceCode:1310: int gfs2_quota_sync(struct super_block *sb, int type)
1311: {
1312: struct gfs2_sbd *sdp = sb->s_fs_info;
1313: struct gfs2_quota_data **qda;
1314: unsigned int max_qd = PAGE_SIZE / sizeof(struct gfs2_holder);
1315: u64 sync_gen;
1316: int error = 0;
1317:
1318: if (sb_rdonly(sdp->sd_vfs))
1319: return 0;
1320:
1321: qda = kzalloc_objs(struct gfs2_quota_data *, max_qd);
1322: if (!qda)
1323: return -ENOMEM;
1324:
1325: mutex_lock(&sdp->sd_quota_sync_mutex);
1326: sync_gen = sdp->sd_quota_sync_gen + 1;
1327:
1328: do {
1329: struct gfs2_quota_data *iter;
1330: unsigned int num_qd = 0;
1331: unsigned int x;
1332:
1333: spin_lock(&qd_lock);
1334: list_for_each_entry(iter, &sdp->sd_quota_list, qd_list) {
1335: if (qd_grab_sync(sdp, iter, sync_gen)) {
1336: qda[num_qd++] = iter;
1337: if (num_qd == max_qd)
1338: break;
1339: }
1340: }
1341: spin_unlock(&qd_lock);
1342:
1343: if (!num_qd)
1344: break;
1345:
1346: for (x = 0; x < num_qd; x++) {
1347: error = bh_get(qda[x]);
1348: if (!error)
1349: continue;
1350:
1351: while (x < num_qd)
1352: qd_ungrab_sync(qda[--num_qd]);
1353: break;
1354: }
1355:
1356: if (!error) {
1357: WRITE_ONCE(sdp->sd_quota_sync_gen, sync_gen);
1358: error = do_sync(num_qd, qda, sync_gen);
1359: }
1360:
1361: for (x = 0; x < num_qd; x++)
1362: qd_unlock(qda[x]);
1363: } while (!error);
1364:
1365: mutex_unlock(&sdp->sd_quota_sync_mutex);
1366: kfree(qda);
1367:
1368: return error;
1369: }
SourceFile:fs/gfs2/quota.c]
|
| 34/2 |
2026/05/31 13:50 |
llm |
expert |
0m
Model:
Tokens:
input: 37431
output: 34
thoughts: 938
Thoughts: **Analyzing a GFS2 Quota Synchronization Bug**
Okay, so I'm digging into this `gfs2_quota_sync` issue. My initial thought was that if `old_qd` was removed from the `sd_quota_list`, it wouldn't be synced, and the quota change in the first slot would just be ignored. No memory corruption, that's good. But wait, what if `old_qd` had another reference? It's in both `sd_quota_list` and `qd_hash_table`. Could another thread have grabbed it from the `qd_hash_table` and incremented its reference count?
Let's think. `gfs2_quota_init` is called during the mount process. Is the filesystem even accessible to other threads at that point? No, it's called from `gfs2_make_fs_rw` or `gfs2_fill_super`. During `gfs2_fill_super`, the filesystem isn't visible to userspace yet, so no other thread could access it. This means `old_qd` only has the one reference from `gfs2_qd_search_bucket`. And `gfs2_qd_search_bucket` increments the reference count to one, and then `qd_put` decrements it to zero and frees it. So, no other references exist.
Wait... is there another bug here? The bug report mentions a "sleeping function called from invalid context" in `kernel/locking/spinlock_rt.c`. That's an RT-specific issue. There's also a warning about an assertion failing in `gfs2_qd_dispose`, but that's just a warning, not a critical failure.
Now, how could this be triggered? Could an unprivileged user mount a GFS2 filesystem? Quick check, `FS_USERNS_MOUNT` isn't set for GFS2. So it requires `CAP_SYS_ADMIN` in the initial user namespace. Therefore, unprivileged processes and user namespaces are out.
Okay, what about a VM guest? Yes, a VM guest *could* trigger this if it mounts a corrupted GFS2 filesystem. But the bug would be in the guest kernel, right? Could it affect the host? Not directly, since GFS2 is a block-based filesystem, unless the host mounts a GFS2 filesystem from a block device provided by the guest, like with virtiofs. Usually, the host doesn't mount guest filesystems.
Aha! A "Peripheral Trigger." If a user plugs in a USB drive with a corrupted GFS2 filesystem, and the system auto-mounts it, that *could* trigger the bug. Auto-mounting is common on desktop environments. So, a malicious filesystem could trigger this.
Let's go back and dissect the RT spinlock issue. We've got this code:
```c
spin_lock(&qd_lock);
spin_lock_bucket(hash);
old_qd = gfs2_qd_search_bucket(hash, sdp, qc_id);
```
`spin_lock_bucket` takes `hlist_bl_lock`, which disables preemption. `gfs2_qd_search_bucket` then calls `lockref_get_not_dead`, which takes `spin_lock(&lockref->lock)`. On PREEMPT_RT, that `spin_lock` is a sleeping lock (`rt_spin_lock`), which can't be taken when preemption is disabled. *This* is the bug! It's a known issue with `lockref` and `hlist_bl` on PREEMPT_RT. And `lockref_get_not_dead` is used everywhere! The million dollar question: is `lockref->lock` a raw spinlock on PREEMPT_RT?
|
| 35/2 |
2026/05/31 13:50 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:include/linux/lockref.h Name:lockref]
Results: map[SourceCode: 25: struct lockref {
26: union {
27: #if USE_CMPXCHG_LOCKREF
28: aligned_u64 lock_count;
29: #endif
30: struct {
31: spinlock_t lock;
32: int count;
33: };
34: };
35: };
SourceFile:include/linux/lockref.h]
|
| 36/2 |
2026/05/31 13:50 |
llm |
expert |
1m
Model:
Tokens:
input: 39373
output: 43
thoughts: 1166
Thoughts: **GFS2 Spinlock Issues on PREEMPT_RT: Assessment and Impact**
Okay, so I've been digging into this GFS2 code, specifically around how it interacts with spinlocks and the Real-Time Preemption (PREEMPT_RT) kernel. It looks like we've got a potential issue. From what I can tell, a `spinlock_t` on PREEMPT_RT translates to an `rt_spinlock`, which is a sleeping lock. The code in question involves `hlist_bl_lock`, which uses a `bit_spin_lock`. The problem is that `bit_spin_lock` disables preemption on PREEMPT_RT. So, taking a regular `spinlock_t` within the context of a `bit_spin_lock` is just wrong, a complete no-go.
This seems like a broader issue for `hlist_bl` and `lockref` under PREEMPT_RT. I'm seeing it in the GFS2 code, but I'm going to have to make sure it's not a more general concern. The VFS's `dentry` uses this pattern: `d_hash` uses `hlist_bl` and `d_lockref` uses `lockref`. However, `d_lookup` specifically uses `rcu_read_lock`, so it's not a direct conflict. It seems `hlist_bl_lock` is only used when the hash list is modified.
I've traced this back to the `gfs2_qd_search_bucket` function. It's called while holding the `hlist_bl_lock`. This is odd because the code suggests a design that's RCU-friendly (using `hlist_bl_for_each_entry_rcu`), and there's a corresponding RCU-protected path (`rcu_read_lock` and call to `gfs2_qd_search_bucket`). In `gfs2_quota_init`, we take the bucket lock to prevent concurrent additions, but since this happens during mount, there's no real concurrency anyway! The code holds *both* `spin_lock(&qd_lock)` and `spin_lock_bucket(hash)`. Then, it calls `gfs2_qd_search_bucket`, which internally takes `lockref->lock`. **That's the bug**. This is a PREEMPT_RT incompatibility.
I'm thinking about the exploitability. It's not a straight-up vulnerability; it's just a "sleeping function called from invalid context" warning. However, if `CONFIG_PANIC_ON_WARN` is set, it *could* lead to a panic, which is a denial of service. The caveat is that triggering it requires mounting a corrupted filesystem, which, in turn, requires `CAP_SYS_ADMIN`. That keeps it from being a serious security issue.
Now, let's look at the second bug: the assertion failure in `gfs2_qd_dispose`, where `!qd->qd_change` fails. This needs a duplicate quota identifier in the quota change file to trigger. Again, this is an internal file that can only get corrupted if the GFS2 image itself is corrupted. So, it's also a mount-a-corrupted-filesystem scenario.
Okay, let's summarize the impact clearly:
* Exploitable: **No.** It's a warning or assertion failure and a very minor memory leak (a bitmap bit that's not freed), no real memory corruption.
* Denial of Service: **Yes**, potential kernel warning or panic (if `panic_on_warn` is set).
* Unprivileged Access: **No**. Requires `CAP_SYS_ADMIN` for mounting GFS2.
* User Namespaces: **No.** GFS2 doesn't support `FS_USERNS_MOUNT`.
* VM Guest: **No**. Mounting in a guest doesn't affect the host.
* VM Host (Confidential Computing): **No**.
* Network: **No**.
* Other Remote: **No**.
* Peripheral: **Yes**. If a malicious GFS2 filesystem is auto-mounted from something like a USB drive.
* Malicious Filesystem: **Yes**. Triggered by mounting a corrupted GFS2 filesystem.
Wait a second... could an unprivileged user trigger this via auto-mounting? If the system has udisks2 or something similar, *physical* access lets an unprivileged user plug in a corrupted drive. That's a valid path. I've covered this under "Peripheral Trigger" and "Malicious Filesystem Trigger".
Just to double check, I have to confirm that GFS2 can't be mounted by unprivileged users
|
| 37/2 |
2026/05/31 13:52 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/gfs2/ops_fstype.c Name:gfs2_fs_type]
Results: map[SourceCode:1800: struct file_system_type gfs2_fs_type = {
1801: .name = "gfs2",
1802: .fs_flags = FS_REQUIRES_DEV,
1803: .init_fs_context = gfs2_init_fs_context,
1804: .parameters = gfs2_fs_parameters,
1805: .kill_sb = gfs2_kill_sb,
1806: .owner = THIS_MODULE,
1807: };
SourceFile:fs/gfs2/ops_fstype.c]
|
| 38/2 |
2026/05/31 13:52 |
llm |
expert |
0m
Model:
Tokens:
input: 41782
output: 42
thoughts: 134
Thoughts: Here's my analysis of the situation:
**Investigating the `gfs2_qd_dispose` Assertion Failure**
Okay, so I've confirmed that `FS_USERNS_MOUNT` isn't defined. That's a key piece of information. Now, I need to understand why we're hitting that `gfs2_qd_dispose` assertion failure. Let's break down that code block:
```c
if (!gfs2_withdrawn(sdp)) {
gfs2_assert_warn(sdp, !qd->qd_change);
gfs2_assert_warn(sdp, !qd->qd_slot_ref);
gfs2_assert_warn(sdp, !qd->qd_bh_count);
}
```
Essentially, if the shared data pointer (`sdp`) isn't marked as "withdrawn," then the code is designed to check for three specific conditions within the `gfs2_assert_warn` calls. It looks like it wants these conditions to be true:
* `!qd->qd_change`: The "change" flag within the quota data structure (`qd`) should be false.
* `!qd->qd_slot_ref`: The "slot reference" count in `qd` should be zero.
* `!qd->qd_bh_count`: The block header (`bh`) count in `qd` should be zero.
The purpose of these assertions is to ensure that when we're disposing of quota data, we have a clean state and no lingering modifications or references. If any of these assertions fail, it means we've somehow ended up with a quota data entry that has changes, slot references, or buffered headers that should not be present when it's being disposed. Understanding the definition of `gfs2_assert_warn` will clarify its behaviour and how it could fail.
|
| 39/2 |
2026/05/31 13:52 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/gfs2/util.c Name:gfs2_assert_warn_i]
Results: map[SourceCode: 288: void gfs2_assert_warn_i(struct gfs2_sbd *sdp, char *assertion,
289: const char *function, char *file, unsigned int line)
290: {
291: if (time_before(jiffies,
292: sdp->sd_last_warning +
293: gfs2_tune_get(sdp, gt_complain_secs) * HZ))
294: return;
295:
296: if (sdp->sd_args.ar_errors == GFS2_ERRORS_WITHDRAW)
297: fs_warn(sdp, "warning: assertion \"%s\" failed - "
298: "function = %s, file = %s, line = %u\n",
299: assertion, function, file, line);
300:
301: if (sdp->sd_args.ar_debug)
302: BUG();
303: else
304: dump_stack();
305:
306: if (sdp->sd_args.ar_errors == GFS2_ERRORS_PANIC)
307: panic("GFS2: fsid=%s: warning: assertion \"%s\" failed - "
308: "function = %s, file = %s, line = %u\n",
309: sdp->sd_fsname, assertion,
310: function, file, line);
311:
312: sdp->sd_last_warning = jiffies;
313: }
SourceFile:fs/gfs2/util.c]
|
| 40/2 |
2026/05/31 13:52 |
llm |
expert |
0m
Model:
Tokens:
input: 42848
output: 66
thoughts: 3179
Thoughts: **My Assessment of the GFS2 Quota Initialization Bug**
Okay, let's break this down. It seems the core issue revolves around the `gfs2_quota_init` function, which is only called during the mount or remount of a GFS2 filesystem. This code path is triggered by the filesystem itself, meaning an attacker would need to create a malicious GFS2 image to exploit this.
The code prints a warning from `dump_stack()` or triggers a `BUG()` depending on the debug options passed. This isn't a *severe* denial of service in itself, but a warning can be escalated to a panic if the user has `panic_on_warn` set. The syzkaller reproducer uses `errors=withdraw`, which defaults to panic or debug in the GFS2 context, hence the warning and stack trace. There is also a `BUG: sleeping function called from invalid context` warning, triggered by `___might_sleep`.
Initially, I investigated the possibility of memory corruption related to `old_qd` being freed while still referenced in `sd_quota_list`. However, `gfs2_qd_dispose` removes it from the list before freeing it. So, that's safe. There's also no use-after-free because `qd_put` will safely free `old_qd`. It then proceeds to free `qd`, zeroes out a duplicate slot in the buffer, and continues. No pointers to `old_qd` are saved anywhere else.
The main consequence is a minor resource leak: a bit is left set in `sd_quota_bitmap` and one slot in the quota change file is effectively ignored. This is not a security vulnerability.
The *impact* is a Denial of Service. The warnings and `BUG`s can trigger panics and crash the system. It's triggered by a Malicious Filesystem. The trigger is not accessible from unprivileged processes or user namespaces. It can be triggered via Peripheral (USB drive) since external drives are often auto-mounted.
Crucially, I confirmed that `gfs2_quota_init` is ONLY called during mount or remount, eliminating other attack vectors. The code path can also be reached during remount, which still requires `CAP_SYS_ADMIN`.
Now, to the PREEMPT_RT specifics. The crucial part here is the interplay between `bit_spin_lock` which *disables* preemption, and `rt_spin_lock` used inside `gfs2_qd_search_bucket`, and by the fact `rt_spin_lock` will trigger an error if used in `preempt_disable()` context. This bug arises because of a sleeping spinlock call within a critical section that is disabled by `bit_spin_lock` (hlist_bl_lock). This `bit_spin_lock` call happens in `spin_lock_bucket()`, which leads to the `gfs2_quota_init` code path taking `bit_spin_lock` before getting a `rt_spin_lock`, thus violating the RT rules.
On PREEMPT_RT, `rcu_read_lock` does *not* disable preemption. The problem arises when taking a sleeping lock (`rt_spin_lock`) within the context of the `hlist_bl_lock`, which uses `bit_spin_lock`, hence disabling preemption.
The `preempt_count` is 1 when the bug occurs because `bit_spin_lock` explicitly calls `preempt_disable()`. `rt_spin_lock` then checks for `preempt_count` being non-zero, triggering the "sleeping function called from invalid context" BUG. This *only* happens in `gfs2_quota_init` because it's the only place where the `spin_lock_bucket` -> `hlist_bl_lock` path intersects with the `gfs2_qd_search_bucket`'s use of `lockref_get_not_dead` and its `rt_spin_lock`.
In the `qd_get` path, the RCU read-lock is used, so preemption is NOT disabled, which avoids the issue.
Regarding the assertion failure, this arises in `gfs2_quota_init` when it encounters the corrupted quota entry. It's not exploitable on its own, but it contributes to the denial of service.
As for other possible memory corruption, I re-examined `gfs2_qd_dispose` and the related cleanup paths, finding everything is handled safely. Even if `gfs2_quota_init` fails, it calls `gfs2_quota_cleanup`, which correctly cleans up all allocated resources.
I am concluding that this is a Denial of Service, specifically, warnings and potentially a kernel panic.
|
| 41/2 |
2026/05/31 13:52 |
tool |
set-results |
0m
Args: map[DenialOfService:true Exploitable:false FilesystemTrigger:true NetworkTrigger:false PeripheralTrigger:true RemoteTrigger:false Unprivileged:false UserNamespace:false VMGuestTrigger:false VMHostTrigger:false]
Results: map[DenialOfService:true Exploitable:false FilesystemTrigger:true NetworkTrigger:false PeripheralTrigger:true RemoteTrigger:false Unprivileged:false UserNamespace:false VMGuestTrigger:false VMHostTrigger:false]
|
| 42/2 |
2026/05/31 13:52 |
llm |
expert |
0m
Model:
Tokens:
input: 47182
output: 707
thoughts: 696
Thoughts: **Analyzing the GFS2 Filesystem Corruption Bug Report**
Alright, the data's in, time to synthesize this into a final response. This bug report lays out two distinct issues arising from mounting a corrupted GFS2 filesystem.
First, there's the `PREEMPT_RT` kernel issue: a "sleeping function called from invalid context" warning. The root cause appears to be in `gfs2_quota_init`. The code takes a bucket lock using `spin_lock_bucket`, which uses `hlist_bl_lock`. On `PREEMPT_RT`, that's a bit spinlock which disables preemption. While this lock is held, it calls `gfs2_qd_search_bucket`, and then `lockref_get_not_dead`, which then calls `spin_lock`. In the RT world, this `spin_lock` becomes a sleeping lock and you can't have sleeping functions in a context where preemption is disabled. This isn't causing memory corruption, but it can lead to a kernel panic if `panic_on_warn` is set. Essentially, the code's violating a fundamental RT kernel constraint.
Second, we've got an assertion failure, specifically the `warning: assertion "!qd->qd_change" failed` in `gfs2_qd_dispose`. This happens during the quota data parsing in `gfs2_quota_init`. The logic tries to handle duplicate quota identifiers by freeing the old quota data object (`qd_put(old_qd)`). Because the journal isn't active during the mount, `qd_put` marks the object as dead immediately and calls `gfs2_qd_dispose`. The problem is that the object was initialized with some non-zero values for `qd_change` and `qd_slot_ref`. `gfs2_qd_dispose` asserts these values are zero. The assertion fails because, due to the corruption, `old_qd` wasn't cleaned up correctly, and it's bypassing a crucial bit of logic in `slot_put`. This means a single bit in the `sd_quota_bitmap` isn't getting cleared, resulting in a minor resource leak. The bitmap itself will be freed correctly on unmount, so it's not a major issue, and we're not dealing with any use-after-free or memory corruption, thankfully.
Critically, both of these issues are predicated on mounting a maliciously crafted GFS2 filesystem. It's not exploitable by unprivileged users because GFS2 doesn't allow unprivileged mounts, it requires `CAP_SYS_ADMIN` in the initial user namespace. So, an unprivileged user can't create this scenario. A peripheral device auto-mounting a corrupted image is where you might see this issue, if the system is configured to do this.
Ultimately, the impact is limited to Denial of Service β kernel warnings, and potentially a panic. We're not looking at privilege escalation or any memory corruption vulnerabilities. So, the risk is pretty contained.
|
| 43/1 |
2026/05/31 13:53 |
action |
format-explanation |
0m
Results: map[Explanation:Based on the analysis of the bug report and the GFS2 source code, here is the
assessment of the vulnerabilities:
**1. RT Spinlock Bug (`sleeping function called from invalid context`)**
In `gfs2_quota_init()`, the code acquires a bucket lock using
`spin_lock_bucket()`, which internally uses `hlist_bl_lock()`. On `PREEMPT_RT`
kernels, `hlist_bl_lock()` is implemented as a bit spinlock that explicitly
disables preemption.
While holding this lock, the code calls `gfs2_qd_search_bucket()`, which in turn
calls `lockref_get_not_dead()`. This function attempts to acquire
`spin_lock(&lockref->lock)`. On `PREEMPT_RT`, standard spinlocks are mapped to
`rt_spin_lock`, which are sleeping locks. Attempting to acquire a sleeping lock
while preemption is disabled is invalid and triggers the reported `BUG: sleeping
function called from invalid context`. This is a known RT-specific locking
constraint violation.
**2. Assertion Failure (`assertion "!qd->qd_change" failed`)**
While parsing the quota change file during mount, if `gfs2_quota_init()`
encounters a duplicate quota identifier, it attempts to handle the corruption by
dropping the previously allocated quota data object via `qd_put(old_qd)`.
Because the journal is not yet marked as live (`SDF_JOURNAL_LIVE` is not set
during this early mount phase), `qd_put()` immediately marks the object as dead
and calls `gfs2_qd_dispose()`.
However, `old_qd` was previously initialized with non-zero `qd_change` and
`qd_slot_ref` values. `gfs2_qd_dispose()` contains assertions expecting these to
be zero (`gfs2_assert_warn(sdp, !qd->qd_change)`), which fail and print the
warnings. Consequently, the bit corresponding to this quota slot in
`sd_quota_bitmap` is leaked because `slot_put()` is bypassed. The bitmap itself
is safely freed upon unmount, meaning this only results in a harmless leaked bit
(quota slot exhaustion) rather than a memory corruption or use-after-free.
**Security Impact:**
* **Exploitable:** No. Both issues result in kernel warnings and a minor
internal state leak (a bit in a bitmap). There is no memory corruption,
out-of-bounds access, or use-after-free that could be leveraged for privilege
escalation.
* **Denial of Service:** Yes. The bugs trigger kernel warnings and stack traces.
If the kernel is configured with `panic_on_warn` (common in some environments),
this will halt the system, leading to a DoS.
* **Unprivileged / User Namespace:** No. GFS2 does not implement the
`FS_USERNS_MOUNT` flag. Mounting a GFS2 filesystem strictly requires
`CAP_SYS_ADMIN` in the initial user namespace. Unprivileged users cannot trigger
this bug directly.
* **Filesystem / Peripheral Trigger:** Yes. The bug is triggered by parsing a
maliciously crafted or corrupted GFS2 filesystem image. It can be triggered if a
system is configured to auto-mount external media (like USB drives) containing
the corrupted image.]
|