| 0/0 |
2026/05/18 14:09 |
flow |
assessment-security |
1h00m
Results: map[DenialOfService:true Explanation:**Analysis of the Bug Report**
The bug report indicates a "possible circular locking dependency detected" (an
ABBA deadlock) in the `ocfs2` filesystem. The lockdep warning highlights a lock
inversion between the global bitmap inode lock and the transaction barrier
locks.
**Detailed Mechanism:**
The deadlock involves the following locks:
1. `&ocfs2_sysfile_lock_key[GLOBAL_BITMAP_SYSTEM_INODE]` (the `i_rwsem` mutex of
the global bitmap inode)
2. `sb_internal#2` (the `s_writers.rw_sem` for `SB_FREEZE_FS`, taken via
`sb_start_intwrite`)
3. `&journal->j_trans_barrier` (the journal transaction barrier rwsem)
There are two conflicting code paths in `ocfs2` that acquire these locks in
reverse order:
* **Path A (Cluster Allocation - e.g., `mkdir`, `fallocate`, or `write`):**
When allocating clusters, if the local allocator is full or disabled, `ocfs2`
falls back to the global bitmap. It calls
`ocfs2_reserve_cluster_bitmap_bits()`, which acquires the `i_rwsem` of the
`GLOBAL_BITMAP_SYSTEM_INODE`. With this lock held, it subsequently starts a
journal transaction via `ocfs2_start_trans()`, which acquires `sb_internal#2`
(read) and `&journal->j_trans_barrier` (read).
*Lock Order:* `GLOBAL_BITMAP_SYSTEM_INODE` -> `sb_internal#2` ->
`&journal->j_trans_barrier`
* **Path B (Inode Deletion - e.g., `rmdir` or `unlink`):**
When an inode is deleted, `ocfs2_remove_inode()` first starts a transaction,
acquiring `sb_internal#2` (read) and `&journal->j_trans_barrier` (read). It
then proceeds to free the inode. If this inode happens to be the last
allocated inode in its suballocator group, the group becomes empty. `ocfs2`
then attempts to reclaim the group's space back to the main bitmap by calling
`_ocfs2_reclaim_suballoc_to_main()`. This function acquires the `i_rwsem` of
the `GLOBAL_BITMAP_SYSTEM_INODE`.
*Lock Order:* `sb_internal#2` -> `&journal->j_trans_barrier` ->
`GLOBAL_BITMAP_SYSTEM_INODE`
Although `sb_internal#2` and `&journal->j_trans_barrier` are acquired as read
locks in both paths, they are `rw_semaphore`s. If a third thread attempts to
acquire either of them for writing (e.g., during a filesystem freeze or a
journal commit), it will block waiting for the read locks to be released. Any
subsequent read lock attempts will then queue up behind the writer, completing
the 3-way deadlock cycle.
**Security Impact:**
* **Exploitable:** No. This is a pure concurrency logic bug (deadlock) and does
not result in memory corruption, out-of-bounds accesses, or privilege
escalation.
* **Denial Of Service:** Yes. Triggering the deadlock will hang the threads
involved and eventually hang the entire filesystem and any tasks attempting to
access it, resulting in a local Denial of Service (DoS).
* **Malicious Filesystem Trigger:** Yes. The syzkaller reproducer triggers this
by mounting a maliciously crafted `ocfs2` image designed to perfectly align the
conditions (e.g., an inode group with exactly one allocated inode and a full
local allocator) and then performing basic operations like `mkdirat`.
* **Accessible From Unprivileged Processes:** Yes. If a standard `ocfs2`
filesystem is mounted and an unprivileged user has write access to a directory
within it, they can trigger this deadlock by concurrently creating and deleting
directories/files to hit Path A and Path B simultaneously.
* **Accessible From User Namespaces:** No. The `ocfs2` filesystem lacks the
`FS_USERNS_MOUNT` flag, meaning it cannot be mounted by an unprivileged user
inside a user namespace. It requires `CAP_SYS_ADMIN` in the initial namespace to
mount. Exploitable:false FilesystemTrigger:true NetworkTrigger:false PeripheralTrigger:false RemoteTrigger:false Unprivileged:true UserNamespace:false VMGuestTrigger:false VMHostTrigger:false]
|
| 1/1 |
2026/05/18 14:09 |
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$ocfs2 arguments: [
// fs: ptr[in, buffer] {
// buffer: {6f 63 66 73 32 00} (length 0x6)
// }
// dir: ptr[in, buffer] {
// buffer: {2e 2f 66 69 6c 65 31 00} (length 0x8)
// }
// flags: mount_flags = 0x8c0 (8 bytes)
// opts: ptr[inout, array[ANYUNION]] {
// array[ANYUNION] {
// union ANYUNION {
// ANYBLOB: buffer: {61 63 6c 2c 68 65 61 72 74 62 65 61 74 3d 6e 6f 6e 65 2c 64 69 72 5f 72 65 73 76 5f 6c 65 76 65 6c 3d 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 33 2c 72 65 73 76 5f 6c 65 76 65 6c 3d 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 36 2c 63 6f 68 65 72 65 6e 63 79 3d 66 75 6c 6c 2c 6c 6f 63 61 6c 66 6c 6f 63 6b 73 2c 63 6f 68 65 72 65 6e 63 79 3d 66 75 6c 6c 2c 6e 6f 61 63 6c 2c 00 4c 98 06 5b 85 e5 b1 37 d6 3b 22 11 c6 2c 40 20 45 08 3d a9 bd dc 3b 0d 88 d4 4e cd 24 ba 52 88 d4 28 19 72 84 f3 32 85 8b 83 34 9a f2 c7 64 6f 1e 07 e9 11 20 d7 f2 3c e2 03 89 bb c0 31 d8 1d 65 4f 1c a0 8f 61 c9 2d 90 e6 ea 47 88 43 c1 ad 94 2c 7c 25 7f 9f f5 34 8d d0 38 e9 47 77 59 91 ad 90 f8 86 1d ad a2 1d 5f a2 de 70 42 b5 e2 cb bc d1 ad a2 b5 68 e3 75 81 2e b0 bc 44 8e 68 ed a4 c7 0c f1 d5 ad f5 66 14 2e d4 59 24 fe 72 a1 eb 1a 91 4f af 75 4b 9d 94 bf 0f dc 1f 98 c7 08 bd 89 94 0b 5e f9 6e 32 82 40 c3 95 59 b3 5b c8 3c 15 c1 51 04 f3 b3 fe 19 45 f0 27 8c 34 e2 39 9d ad cd 97 76 ac 65 9a fc bb 23 95 69 14 0a b4 08 ad 87 f1 5b 35 39 41} (length 0x160)
// }
// }
// }
// chdir: int8 = 0x1 (1 bytes)
// size: len = 0x442a (8 bytes)
// img: ptr[in, buffer] {
// buffer: (compressed buffer with length 0x442a)
// }
// ]
// returns fd_dir
memcpy((void*)0x200000004440, "ocfs2\000", 6);
memcpy((void*)0x200000000040, "./file1\000", 8);
memcpy((void*)0x200000000600, "... [truncated large byte array] ...", 352);
memcpy((void*)0x200000004480, "... [truncated large byte array] ...", 17450);
syz_mount_image(/*fs=*/0x200000004440, /*dir=*/0x200000000040, /*flags=MS_NODIRATIME|MS_MANDLOCK|MS_DIRSYNC*/0x8c0, /*opts=*/0x200000000600, /*chdir=*/1, /*size=*/0x442a, /*img=*/0x200000004480);
// mkdirat arguments: [
// fd: fd_dir (resource)
// path: ptr[in, buffer] {
// buffer: {2e 2f 66 69 6c 65 30 00} (length 0x8)
// }
// mode: open_mode = 0x1a1 (8 bytes)
// ]
memcpy((void*)0x200000000100, "./file0\000", 8);
syscall(__NR_mkdirat, /*fd=*/0xffffff9c, /*path=*/0x200000000100ul, /*mode=S_IXOTH|S_IRGRP|S_IWUSR|S_IRUSR*/0x1a1ul);
// mount arguments: [
// src: nil
// dst: ptr[in, buffer] {
// buffer: {2e 2f 66 69 6c 65 30 00} (length 0x8)
// }
// type: ptr[in, buffer] {
// buffer: {6d 71 75 65 75 65 00} (length 0x7)
// }
// flags: mount_flags = 0x200011 (8 bytes)
// data: nil
// ]
memcpy((void*)0x2000000000c0, "./file0\000", 8);
memcpy((void*)0x200000000080, "mqueue\000", 7);
syscall(__NR_mount, /*src=*/0ul, /*dst=*/0x2000000000c0ul, /*type=*/0x200000000080ul, /*flags=MS_SYNCHRONOUS|MS_RELATIME|MS_RDONLY*/0x200011ul, /*data=*/0ul);
return 0;
}
]
|
| 2/1 |
2026/05/18 14:09 |
action |
kernel-checkouter |
2m
Results: map[KernelSrc:/app/workdir/cache/src/7386e8bf16aed7f1e22143f4ab1682d4b2919568]
|
| 3/1 |
2026/05/18 14:11 |
action |
kernel-builder |
33m
Results: map[KernelObj:/app/workdir/cache/build/5c95ef285ba50b5c3b97a026bbbbbcb3a430abf0]
|
| 4/1 |
2026/05/18 14:44 |
action |
codesearch-prepare |
18m
Results: map[Index:codesearch-index]
|
| 5/1 |
2026/05/18 15:02 |
agent |
expert |
7m
Model:
Results: map[DenialOfService:true Exploitable:false FilesystemTrigger:true NetworkTrigger:false PeripheralTrigger:false RemoteTrigger:false Unprivileged:true UserNamespace:false VMGuestTrigger:false VMHostTrigger:false]
Instruction:
You are an experienced Linux kernel security engineer. Your task is to analyze given kernel bug report
and determine its security impact based on the following dimensions.
Use the provided tools to examine the source code, check for capability checks (e.g., capable(), ns_capable()),
and understand the nature of the bug. Analyze the given kernel build and configuration.
You can check the kernel config by grepping ".config" file; you can check kernel cmdline by greeping
".config" file for "CONFIG_CMDLINE=". Assume sysctl parameters have default values.
But analyze for the corresponding production build w/o debugging tools enabled (like KASAN, KMSAN, UBSAN).
Don't make assumptions; verify them with source code access. Try different strategies when analyzing the bug:
- think of ways in which the vulnerable code is unreachable
- or the other way around: try to come up with different ideas of how an unprivileged user can reach the bug
If still unsure err on the side of the bug being non-exploitable/not-accessible.
In the final reply, provide a reasoning for your assessment.
Analysis dimensions:
* Exploitable:
Determine if the bug can result in memory corruption or elevated privileges.
Memory safety issues are almost always exploitable (KASAN or UBSAN reports for use-after-free, out-of-bounds;
refcounting issues, corrupted lists, etc). When kernel is crashing on a completly wild pointer access
(e.g. user-space address, or non-canonical address, but not on NULL or address corresponding to KASAN shadow
for NULL address), including both data accesses and control tranfers, that's also usually implies possibility
of exploitation. Such reports usually say "unable to handle kernel paging request".
Uses of uninitialized values detected by KMSAN may be exploitable b/c attacker frequently can affect uninit
values with spraying techniques. However, for these exploitabability depends on how exactly the uninit value
is used in the code, and what it affects.
Think of what happens after the bug is triggered. Some bugs cause kernel panic and halt execution,
they are harder to exploit. For example, BUG reports halts the kernel. However, WARNING reports don't halt
execution in production builds. Debug bug detection tools (like KASAN, KMSAN, KCSAN, UBSAN) are also not enabled
in production builds, so attacker can freely exploit these bugs w/o being detected by these tools.
If you see an integer overflow, think how the overflowed value used later (if it's used as allocation size,
or an array index). If you see an out-of-bounds read, think if it's followed by an out-of-bounds write as well.
Some KCSAN data-races may be exploitable by skilled attackers as well. Think what data structures got corrupted
as the result of data races and how. However, note that kernel has lots of "benign" data races that don't lead
to any runtime misbehavior at all.
* Denial Of Service:
Determine if the bug can result in denial-of-service. Most bugs can, since they cause system crash,
hangs, deadlocks, or resource leaks. This is mostly applicable to WARNING bugs that won't cause system crash
in production. For these think what will be consequences of the violation of the kernel assumptions flagged
by the WARNING. In some cases the unexpected condition is also properly handled by the normal control flow
(e.g. with "if (WARN_ON(...))"), these won't cause denial-of-service. If the condition is not handled,
then it may or may not cause denial-of-service.
* Accessible From Unprivileged Processes:
Determine if the bug can be reached from a typical (non-root) user process that does NOT have any special capabilities
(like CAP_SYS_ADMIN, CAP_NET_ADMIN, CAP_NET_RAW, CAP_PERFMON) or access to device nodes restricted to root.
Assume that unprivileged_bpf_disabled=1, that is eBPF loading is not accessible. However, cBPF (classical BPF)
is still accessible to non-root processes.
Assume that user namespaces are not accessible, that is, the process cannot get the mentioned capabilities even
within a new user namespace (checked by ns_capable() function in the kernel sources).
* Accessible From User Namespaces:
Determine if the bug can be reached within a user-namespace where the process has all capabilities
(including CAP_SYS_ADMIN, CAP_NET_ADMIN, CAP_NET_RAW, CAP_PERFMON). Such capabilities are checked with ns_capable()
function in the kernel sources.
* VM Guest Trigger:
Determine if the bug can be triggered from the context of a typical KVM guest (e.g., set up by a QEMU VMM).
Consider accesses to standard Linux host paravirtualized features (virtio-blk, virtio-net, etc.),
and handling of VM exits in the KVM code.
* VM Host Trigger in The Confidetial Computing Context:
Determine if the bug can be triggered in a confidential computing guest kernel from the context of a KVM host.
Consider access to standard Linux guest paravirtualized features (virtio-blk, virtio-net, etc.).
* Ethernet Network Trigger:
Determine if the bug can be triggered by processing ingress network Ethernet traffic, either directly (network stack)
or via drivers exposed to network data.
* Other Remote Trigger:
Determine if the bug can be triggered by processing remote traffic other than Ethernet (Wifi, Bluetooth, NFC, etc).
* Peripheral Trigger:
Determine if the bug can be triggered via an untrusted peripheral device that can be physically plugged
into a system, such as a USB device or a niche hardware driver handling external hardware inputs.
This is particularly important for mobile and desktop environments where users can plug in unknown devices.
* Malicious Filesystem Trigger:
Determine if the bug can be triggered by the kernel mounting and parsing a malicious filesystem image.
This is highly critical for Desktop and Mobile environments where external media or downloaded images
might be auto-mounted.
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt:
The kernel bug report is:
======================================================
WARNING: possible circular locking dependency detected
syzkaller #0 Not tainted
------------------------------------------------------
syz-executor/5944 is trying to acquire lock:
ffff88805a865100 (&ocfs2_sysfile_lock_key[GLOBAL_BITMAP_SYSTEM_INODE]){+.+.}-{4:4}, at: inode_lock include/linux/fs.h:1028 [inline]
ffff88805a865100 (&ocfs2_sysfile_lock_key[GLOBAL_BITMAP_SYSTEM_INODE]){+.+.}-{4:4}, at: _ocfs2_reclaim_suballoc_to_main fs/ocfs2/suballoc.c:2757 [inline]
ffff88805a865100 (&ocfs2_sysfile_lock_key[GLOBAL_BITMAP_SYSTEM_INODE]){+.+.}-{4:4}, at: _ocfs2_free_suballoc_bits+0x13f1/0x2130 fs/ocfs2/suballoc.c:2911
but task is already holding lock:
ffff888032f57ce8 (&journal->j_trans_barrier){.+.+}-{4:4}, at: ocfs2_start_trans+0x36a/0x6d0 fs/ocfs2/journal.c:372
which lock already depends on the new lock.
the existing dependency chain (in reverse order) is:
-> #2 (&journal->j_trans_barrier){.+.+}-{4:4}:
down_read+0x47/0x2e0 kernel/locking/rwsem.c:1537
ocfs2_start_trans+0x36a/0x6d0 fs/ocfs2/journal.c:372
ocfs2_block_group_alloc fs/ocfs2/suballoc.c:754 [inline]
ocfs2_reserve_suballoc_bits+0x722/0x4600 fs/ocfs2/suballoc.c:903
ocfs2_reserve_new_inode+0x4f4/0xc90 fs/ocfs2/suballoc.c:1143
ocfs2_mknod+0x831/0x2030 fs/ocfs2/namei.c:307
ocfs2_mkdir+0x181/0x420 fs/ocfs2/namei.c:660
vfs_mkdir+0x414/0x630 fs/namei.c:5196
do_mkdirat+0x276/0x500 fs/namei.c:5230
__do_sys_mkdirat fs/namei.c:5252 [inline]
__se_sys_mkdirat fs/namei.c:5250 [inline]
__x64_sys_mkdirat+0x87/0xa0 fs/namei.c:5250
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xfa/0xf80 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
-> #1 (sb_internal#2){.+.+}-{0:0}:
percpu_down_read_internal include/linux/percpu-rwsem.h:53 [inline]
percpu_down_read_freezable include/linux/percpu-rwsem.h:83 [inline]
__sb_start_write include/linux/fs/super.h:19 [inline]
sb_start_intwrite include/linux/fs/super.h:177 [inline]
ocfs2_start_trans+0x26b/0x6d0 fs/ocfs2/journal.c:370
ocfs2_block_group_alloc fs/ocfs2/suballoc.c:754 [inline]
ocfs2_reserve_suballoc_bits+0x722/0x4600 fs/ocfs2/suballoc.c:903
ocfs2_reserve_new_inode+0x4f4/0xc90 fs/ocfs2/suballoc.c:1143
ocfs2_mknod+0x831/0x2030 fs/ocfs2/namei.c:307
ocfs2_mkdir+0x181/0x420 fs/ocfs2/namei.c:660
vfs_mkdir+0x414/0x630 fs/namei.c:5196
do_mkdirat+0x276/0x500 fs/namei.c:5230
__do_sys_mkdirat fs/namei.c:5252 [inline]
__se_sys_mkdirat fs/namei.c:5250 [inline]
__x64_sys_mkdirat+0x87/0xa0 fs/namei.c:5250
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xfa/0xf80 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
-> #0 (&ocfs2_sysfile_lock_key[GLOBAL_BITMAP_SYSTEM_INODE]){+.+.}-{4:4}:
check_prev_add kernel/locking/lockdep.c:3165 [inline]
check_prevs_add kernel/locking/lockdep.c:3284 [inline]
validate_chain kernel/locking/lockdep.c:3908 [inline]
__lock_acquire+0x15a6/0x2cf0 kernel/locking/lockdep.c:5237
lock_acquire+0x117/0x340 kernel/locking/lockdep.c:5868
down_write+0x96/0x1f0 kernel/locking/rwsem.c:1590
inode_lock include/linux/fs.h:1028 [inline]
_ocfs2_reclaim_suballoc_to_main fs/ocfs2/suballoc.c:2757 [inline]
_ocfs2_free_suballoc_bits+0x13f1/0x2130 fs/ocfs2/suballoc.c:2911
ocfs2_free_suballoc_bits fs/ocfs2/suballoc.c:2925 [inline]
ocfs2_free_dinode+0xb1/0xe0 fs/ocfs2/suballoc.c:2940
ocfs2_remove_inode fs/ocfs2/inode.c:774 [inline]
ocfs2_wipe_inode fs/ocfs2/inode.c:896 [inline]
ocfs2_delete_inode fs/ocfs2/inode.c:1157 [inline]
ocfs2_evict_inode+0x1d84/0x4040 fs/ocfs2/inode.c:1299
evict+0x5f4/0xae0 fs/inode.c:837
d_delete_notify include/linux/fsnotify.h:377 [inline]
vfs_rmdir+0x427/0x6e0 fs/namei.c:5315
do_rmdir+0x281/0x500 fs/namei.c:5357
__do_sys_unlinkat fs/namei.c:5534 [inline]
__se_sys_unlinkat fs/namei.c:5528 [inline]
__x64_sys_unlinkat+0xc2/0xf0 fs/namei.c:5528
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xfa/0xf80 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
other info that might help us debug this:
Chain exists of:
&ocfs2_sysfile_lock_key[GLOBAL_BITMAP_SYSTEM_INODE] --> sb_internal#2 --> &journal->j_trans_barrier
Possible unsafe locking scenario:
CPU0 CPU1
---- ----
rlock(&journal->j_trans_barrier);
lock(sb_internal#2);
lock(&journal->j_trans_barrier);
lock(&ocfs2_sysfile_lock_key[GLOBAL_BITMAP_SYSTEM_INODE]);
*** DEADLOCK ***
8 locks held by syz-executor/5944:
#0: ffff888021f00420 (sb_writers#12){.+.+}-{0:0}, at: mnt_want_write+0x41/0x90 fs/namespace.c:499
#1: ffff88805a8609c0 (&type->i_mutex_dir_key#8/1){+.+.}-{4:4}, at: inode_lock_nested include/linux/fs.h:1073 [inline]
#1: ffff88805a8609c0 (&type->i_mutex_dir_key#8/1){+.+.}-{4:4}, at: __start_dirop fs/namei.c:2864 [inline]
#1: ffff88805a8609c0 (&type->i_mutex_dir_key#8/1){+.+.}-{4:4}, at: start_dirop fs/namei.c:2875 [inline]
#1: ffff88805a8609c0 (&type->i_mutex_dir_key#8/1){+.+.}-{4:4}, at: do_rmdir+0x1be/0x500 fs/namei.c:5350
#2: ffff888032084bd0 (&osb->nfs_sync_rwlock){.+.+}-{4:4}, at: ocfs2_nfs_sync_lock+0x106/0x250 fs/ocfs2/dlmglue.c:2875
#3: ffff88805a865f40 (&ocfs2_sysfile_lock_key[ORPHAN_DIR_SYSTEM_INODE]){+.+.}-{4:4}, at: inode_lock include/linux/fs.h:1028 [inline]
#3: ffff88805a865f40 (&ocfs2_sysfile_lock_key[ORPHAN_DIR_SYSTEM_INODE]){+.+.}-{4:4}, at: ocfs2_wipe_inode fs/ocfs2/inode.c:854 [inline]
#3: ffff88805a865f40 (&ocfs2_sysfile_lock_key[ORPHAN_DIR_SYSTEM_INODE]){+.+.}-{4:4}, at: ocfs2_delete_inode fs/ocfs2/inode.c:1157 [inline]
#3: ffff88805a865f40 (&ocfs2_sysfile_lock_key[ORPHAN_DIR_SYSTEM_INODE]){+.+.}-{4:4}, at: ocfs2_evict_inode+0xf6c/0x4040 fs/ocfs2/inode.c:1299
#4: ffff88805a8689c0 (&ocfs2_sysfile_lock_key[INODE_ALLOC_SYSTEM_INODE]){+.+.}-{4:4}, at: inode_lock include/linux/fs.h:1028 [inline]
#4: ffff88805a8689c0 (&ocfs2_sysfile_lock_key[INODE_ALLOC_SYSTEM_INODE]){+.+.}-{4:4}, at: ocfs2_remove_inode fs/ocfs2/inode.c:733 [inline]
#4: ffff88805a8689c0 (&ocfs2_sysfile_lock_key[INODE_ALLOC_SYSTEM_INODE]){+.+.}-{4:4}, at: ocfs2_wipe_inode fs/ocfs2/inode.c:896 [inline]
#4: ffff88805a8689c0 (&ocfs2_sysfile_lock_key[INODE_ALLOC_SYSTEM_INODE]){+.+.}-{4:4}, at: ocfs2_delete_inode fs/ocfs2/inode.c:1157 [inline]
#4: ffff88805a8689c0 (&ocfs2_sysfile_lock_key[INODE_ALLOC_SYSTEM_INODE]){+.+.}-{4:4}, at: ocfs2_evict_inode+0x1507/0x4040 fs/ocfs2/inode.c:1299
#5: ffff888021f00610 (sb_internal#2){.+.+}-{0:0}, at: ocfs2_remove_inode fs/ocfs2/inode.c:742 [inline]
#5: ffff888021f00610 (sb_internal#2){.+.+}-{0:0}, at: ocfs2_wipe_inode fs/ocfs2/inode.c:896 [inline]
#5: ffff888021f00610 (sb_internal#2){.+.+}-{0:0}, at: ocfs2_delete_inode fs/ocfs2/inode.c:1157 [inline]
#5: ffff888021f00610 (sb_internal#2){.+.+}-{0:0}, at: ocfs2_evict_inode+0x15ea/0x4040 fs/ocfs2/inode.c:1299
#6: ffff888032f57ce8 (&journal->j_trans_barrier){.+.+}-{4:4}, at: ocfs2_start_trans+0x36a/0x6d0 fs/ocfs2/journal.c:372
#7: ffff888021f02950 (jbd2_handle#2){.+.+}-{0:0}, at: start_this_handle+0x1f87/0x21c0 fs/jbd2/transaction.c:444
stack backtrace:
CPU: 1 UID: 0 PID: 5944 Comm: syz-executor Not tainted syzkaller #0 PREEMPT(full)
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 10/25/2025
Call Trace:
<TASK>
dump_stack_lvl+0x189/0x250 lib/dump_stack.c:120
print_circular_bug+0x2e2/0x300 kernel/locking/lockdep.c:2043
check_noncircular+0x12e/0x150 kernel/locking/lockdep.c:2175
check_prev_add kernel/locking/lockdep.c:3165 [inline]
check_prevs_add kernel/locking/lockdep.c:3284 [inline]
validate_chain kernel/locking/lockdep.c:3908 [inline]
__lock_acquire+0x15a6/0x2cf0 kernel/locking/lockdep.c:5237
lock_acquire+0x117/0x340 kernel/locking/lockdep.c:5868
down_write+0x96/0x1f0 kernel/locking/rwsem.c:1590
inode_lock include/linux/fs.h:1028 [inline]
_ocfs2_reclaim_suballoc_to_main fs/ocfs2/suballoc.c:2757 [inline]
_ocfs2_free_suballoc_bits+0x13f1/0x2130 fs/ocfs2/suballoc.c:2911
ocfs2_free_suballoc_bits fs/ocfs2/suballoc.c:2925 [inline]
ocfs2_free_dinode+0xb1/0xe0 fs/ocfs2/suballoc.c:2940
ocfs2_remove_inode fs/ocfs2/inode.c:774 [inline]
ocfs2_wipe_inode fs/ocfs2/inode.c:896 [inline]
ocfs2_delete_inode fs/ocfs2/inode.c:1157 [inline]
ocfs2_evict_inode+0x1d84/0x4040 fs/ocfs2/inode.c:1299
evict+0x5f4/0xae0 fs/inode.c:837
d_delete_notify include/linux/fsnotify.h:377 [inline]
vfs_rmdir+0x427/0x6e0 fs/namei.c:5315
do_rmdir+0x281/0x500 fs/namei.c:5357
__do_sys_unlinkat fs/namei.c:5534 [inline]
__se_sys_unlinkat fs/namei.c:5528 [inline]
__x64_sys_unlinkat+0xc2/0xf0 fs/namei.c:5528
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xfa/0xf80 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f877438ed27
Code: 73 01 c3 48 c7 c1 a8 ff ff ff f7 d8 64 89 01 48 83 c8 ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 b8 07 01 00 00 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 a8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007ffe2ce25a58 EFLAGS: 00000207 ORIG_RAX: 0000000000000107
RAX: ffffffffffffffda RBX: 0000000000000065 RCX: 00007f877438ed27
RDX: 0000000000000200 RSI: 00007ffe2ce26c00 RDI: 00000000ffffff9c
RBP: 00007f8774413d7d R08: 0000555594caa66b R09: 0000000000000000
R10: 0000000000001000 R11: 0000000000000207 R12: 00007ffe2ce26c00
R13: 00007f8774413d7d R14: 000000000001e634 R15: 00007ffe2ce28dc0
</TASK>
ocfs2: Unmounting device (7,0) on (node local)
ocfs2: Unmounting device (7,0) on (node local)
ocfs2: Unmounting device (7,0) on (node local)
ocfs2: Unmounting device (7,0) on (node local)
ocfs2: Unmounting device (7,0) on (node local)
ocfs2: Unmounting device (7,0) on (node local)
ocfs2: Unmounting device (7,0) on (node local)
ocfs2: Unmounting device (7,0) on (node local)
ocfs2: Unmounting device (7,0) on (node local)
ocfs2: Unmounting device (7,0) on (node local)
ocfs2: Unmounting device (7,0) on (node local)
ocfs2: Unmounting device (7,0) on (node local)
ocfs2: Unmounting device (7,0) on (node local)
ocfs2: Unmounting device (7,0) on (node local)
ocfs2: Unmounting device (7,0) on (node local)
ocfs2: Unmounting device (7,0) on (node local)
ocfs2: Unmounting device (7,0) on (node local)
ocfs2: Unmounting device (7,0) on (node local)
ocfs2: Unmounting device (7,0) on (node local)
ocfs2: Unmounting device (7,0) on (node local)
ocfs2: Unmounting device (7,0) on (node local)
ocfs2: Unmounting device (7,0) on (node local)
ocfs2: Unmounting device (7,0) on (node local)
ocfs2: Unmounting device (7,0) on (node local)
ocfs2: Unmounting device (7,0) on (node local)
ocfs2: Unmounting device (7,0) on (node local)
ocfs2: Unmounting device (7,0) on (node local)
ocfs2: Unmounting device (7,0) on (node local)
ocfs2: Unmounting device (7,0) on (node local)
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$ocfs2 arguments: [
// fs: ptr[in, buffer] {
// buffer: {6f 63 66 73 32 00} (length 0x6)
// }
// dir: ptr[in, buffer] {
// buffer: {2e 2f 66 69 6c 65 31 00} (length 0x8)
// }
// flags: mount_flags = 0x8c0 (8 bytes)
// opts: ptr[inout, array[ANYUNION]] {
// array[ANYUNION] {
// union ANYUNION {
// ANYBLOB: buffer: {61 63 6c 2c 68 65 61 72 74 62 65 61 74 3d 6e 6f 6e 65 2c 64 69 72 5f 72 65 73 76 5f 6c 65 76 65 6c 3d 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 33 2c 72 65 73 76 5f 6c 65 76 65 6c 3d 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 36 2c 63 6f 68 65 72 65 6e 63 79 3d 66 75 6c 6c 2c 6c 6f 63 61 6c 66 6c 6f 63 6b 73 2c 63 6f 68 65 72 65 6e 63 79 3d 66 75 6c 6c 2c 6e 6f 61 63 6c 2c 00 4c 98 06 5b 85 e5 b1 37 d6 3b 22 11 c6 2c 40 20 45 08 3d a9 bd dc 3b 0d 88 d4 4e cd 24 ba 52 88 d4 28 19 72 84 f3 32 85 8b 83 34 9a f2 c7 64 6f 1e 07 e9 11 20 d7 f2 3c e2 03 89 bb c0 31 d8 1d 65 4f 1c a0 8f 61 c9 2d 90 e6 ea 47 88 43 c1 ad 94 2c 7c 25 7f 9f f5 34 8d d0 38 e9 47 77 59 91 ad 90 f8 86 1d ad a2 1d 5f a2 de 70 42 b5 e2 cb bc d1 ad a2 b5 68 e3 75 81 2e b0 bc 44 8e 68 ed a4 c7 0c f1 d5 ad f5 66 14 2e d4 59 24 fe 72 a1 eb 1a 91 4f af 75 4b 9d 94 bf 0f dc 1f 98 c7 08 bd 89 94 0b 5e f9 6e 32 82 40 c3 95 59 b3 5b c8 3c 15 c1 51 04 f3 b3 fe 19 45 f0 27 8c 34 e2 39 9d ad cd 97 76 ac 65 9a fc bb 23 95 69 14 0a b4 08 ad 87 f1 5b 35 39 41} (length 0x160)
// }
// }
// }
// chdir: int8 = 0x1 (1 bytes)
// size: len = 0x442a (8 bytes)
// img: ptr[in, buffer] {
// buffer: (compressed buffer with length 0x442a)
// }
// ]
// returns fd_dir
memcpy((void*)0x200000004440, "ocfs2\000", 6);
memcpy((void*)0x200000000040, "./file1\000", 8);
memcpy((void*)0x200000000600, "... [truncated large byte array] ...", 352);
memcpy((void*)0x200000004480, "... [truncated large byte array] ...", 17450);
syz_mount_image(/*fs=*/0x200000004440, /*dir=*/0x200000000040, /*flags=MS_NODIRATIME|MS_MANDLOCK|MS_DIRSYNC*/0x8c0, /*opts=*/0x200000000600, /*chdir=*/1, /*size=*/0x442a, /*img=*/0x200000004480);
// mkdirat arguments: [
// fd: fd_dir (resource)
// path: ptr[in, buffer] {
// buffer: {2e 2f 66 69 6c 65 30 00} (length 0x8)
// }
// mode: open_mode = 0x1a1 (8 bytes)
// ]
memcpy((void*)0x200000000100, "./file0\000", 8);
syscall(__NR_mkdirat, /*fd=*/0xffffff9c, /*path=*/0x200000000100ul, /*mode=S_IXOTH|S_IRGRP|S_IWUSR|S_IRUSR*/0x1a1ul);
// mount arguments: [
// src: nil
// dst: ptr[in, buffer] {
// buffer: {2e 2f 66 69 6c 65 30 00} (length 0x8)
// }
// type: ptr[in, buffer] {
// buffer: {6d 71 75 65 75 65 00} (length 0x7)
// }
// flags: mount_flags = 0x200011 (8 bytes)
// data: nil
// ]
memcpy((void*)0x2000000000c0, "./file0\000", 8);
memcpy((void*)0x200000000080, "mqueue\000", 7);
syscall(__NR_mount, /*src=*/0ul, /*dst=*/0x2000000000c0ul, /*type=*/0x200000000080ul, /*flags=MS_SYNCHRONOUS|MS_RELATIME|MS_RDONLY*/0x200011ul, /*data=*/0ul);
return 0;
}
Reply: **Analysis of the Bug Report**
The bug report indicates a "possible circular locking dependency detected" (an ABBA deadlock) in the `ocfs2` filesystem. The lockdep warning highlights a lock inversion between the global bitmap inode lock and the transaction barrier locks.
**Detailed Mechanism:**
The deadlock involves the following locks:
1. `&ocfs2_sysfile_lock_key[GLOBAL_BITMAP_SYSTEM_INODE]` (the `i_rwsem` mutex of the global bitmap inode)
2. `sb_internal#2` (the `s_writers.rw_sem` for `SB_FREEZE_FS`, taken via `sb_start_intwrite`)
3. `&journal->j_trans_barrier` (the journal transaction barrier rwsem)
There are two conflicting code paths in `ocfs2` that acquire these locks in reverse order:
* **Path A (Cluster Allocation - e.g., `mkdir`, `fallocate`, or `write`):**
When allocating clusters, if the local allocator is full or disabled, `ocfs2` falls back to the global bitmap. It calls `ocfs2_reserve_cluster_bitmap_bits()`, which acquires the `i_rwsem` of the `GLOBAL_BITMAP_SYSTEM_INODE`. With this lock held, it subsequently starts a journal transaction via `ocfs2_start_trans()`, which acquires `sb_internal#2` (read) and `&journal->j_trans_barrier` (read).
*Lock Order:* `GLOBAL_BITMAP_SYSTEM_INODE` -> `sb_internal#2` -> `&journal->j_trans_barrier`
* **Path B (Inode Deletion - e.g., `rmdir` or `unlink`):**
When an inode is deleted, `ocfs2_remove_inode()` first starts a transaction, acquiring `sb_internal#2` (read) and `&journal->j_trans_barrier` (read). It then proceeds to free the inode. If this inode happens to be the last allocated inode in its suballocator group, the group becomes empty. `ocfs2` then attempts to reclaim the group's space back to the main bitmap by calling `_ocfs2_reclaim_suballoc_to_main()`. This function acquires the `i_rwsem` of the `GLOBAL_BITMAP_SYSTEM_INODE`.
*Lock Order:* `sb_internal#2` -> `&journal->j_trans_barrier` -> `GLOBAL_BITMAP_SYSTEM_INODE`
Although `sb_internal#2` and `&journal->j_trans_barrier` are acquired as read locks in both paths, they are `rw_semaphore`s. If a third thread attempts to acquire either of them for writing (e.g., during a filesystem freeze or a journal commit), it will block waiting for the read locks to be released. Any subsequent read lock attempts will then queue up behind the writer, completing the 3-way deadlock cycle.
**Security Impact:**
* **Exploitable:** No. This is a pure concurrency logic bug (deadlock) and does not result in memory corruption, out-of-bounds accesses, or privilege escalation.
* **Denial Of Service:** Yes. Triggering the deadlock will hang the threads involved and eventually hang the entire filesystem and any tasks attempting to access it, resulting in a local Denial of Service (DoS).
* **Malicious Filesystem Trigger:** Yes. The syzkaller reproducer triggers this by mounting a maliciously crafted `ocfs2` image designed to perfectly align the conditions (e.g., an inode group with exactly one allocated inode and a full local allocator) and then performing basic operations like `mkdirat`.
* **Accessible From Unprivileged Processes:** Yes. If a standard `ocfs2` filesystem is mounted and an unprivileged user has write access to a directory within it, they can trigger this deadlock by concurrently creating and deleting directories/files to hit Path A and Path B simultaneously.
* **Accessible From User Namespaces:** No. The `ocfs2` filesystem lacks the `FS_USERNS_MOUNT` flag, meaning it cannot be mounted by an unprivileged user inside a user namespace. It requires `CAP_SYS_ADMIN` in the initial namespace to mount.
|
| 6/2 |
2026/05/18 15:02 |
llm |
expert |
0m
Model:
Tokens:
input: 17822
output: 21
thoughts: 344
Thoughts: **Analyzing a Potential OCFS2 Circular Lock Dependency**
Okay, here's what I'm seeing: a syzkaller report flagged a "possible circular locking dependency" within OCFS2. The lockdep warning is pointing to a circular dependency involving a few key locks: specifically `&ocfs2_sysfile_lock_key[GLOBAL_BITMAP_SYSTEM_INODE]`, `sb_internal#2`, and `&journal->j_trans_barrier`. The locking chain, as the warning indicates, goes from `&ocfs2_sysfile_lock_key[GLOBAL_BITMAP_SYSTEM_INODE]` to `sb_internal#2` and then finally to `&journal->j_trans_barrier`.
The warning itself describes the lock acquisition order in a multi-CPU scenario: CPU0 acquires `&journal->j_trans_barrier` then `&ocfs2_sysfile_lock_key[GLOBAL_BITMAP_SYSTEM_INODE]`, while CPU1 acquires `sb_internal#2` and then tries `&journal->j_trans_barrier`. That's a classic deadlock scenario that could lead to Denial of Service, which is obviously a problem.
The reproducer involves mounting an OCFS2 image, then using `mkdirat` and `mount` on the created directory. This suggests the mount operation is the key. Now, mounting OCFS2 usually requires `CAP_SYS_ADMIN` in the initial namespace, which is concerning because it is difficult to reproduce by a normal user. However, I need to consider options like `fs_use_trans` or similar, which might allow it to be mounted in a user namespace. But, OCFS2 is not allowed to be mounted in unprivileged user namespaces. I should confirm that `FS_USERNS_MOUNT` isn't set, as this would provide a clue.
|
| 7/2 |
2026/05/18 15:03 |
tool |
grepper |
0m
Args: map[Expression:FS_USERNS_MOUNT]
Results: map[Output:drivers/android/binder/rust_binderfs.c=758=static struct file_system_type binder_fs_type = {
--
drivers/android/binder/rust_binderfs.c-762- .kill_sb = binderfs_kill_super,
drivers/android/binder/rust_binderfs.c:763: .fs_flags = FS_USERNS_MOUNT,
drivers/android/binder/rust_binderfs.c-764-};
--
drivers/android/binderfs.c=749=static struct file_system_type binder_fs_type = {
--
drivers/android/binderfs.c-753- .kill_sb = binderfs_kill_super,
drivers/android/binderfs.c:754: .fs_flags = FS_USERNS_MOUNT,
drivers/android/binderfs.c-755-};
--
fs/binfmt_misc.c=1021=static struct file_system_type bm_fs_type = {
--
fs/binfmt_misc.c-1024- .init_fs_context = bm_init_fs_context,
fs/binfmt_misc.c:1025: .fs_flags = FS_USERNS_MOUNT,
fs/binfmt_misc.c-1026- .kill_sb = kill_anon_super,
--
fs/devpts/inode.c=453=static struct file_system_type devpts_fs_type = {
--
fs/devpts/inode.c-457- .kill_sb = devpts_kill_sb,
fs/devpts/inode.c:458: .fs_flags = FS_USERNS_MOUNT,
fs/devpts/inode.c-459-};
--
fs/fuse/inode.c=2130=static struct file_system_type fuse_fs_type = {
--
fs/fuse/inode.c-2132- .name = "fuse",
fs/fuse/inode.c:2133: .fs_flags = FS_HAS_SUBTYPE | FS_USERNS_MOUNT | FS_ALLOW_IDMAP,
fs/fuse/inode.c-2134- .init_fs_context = fuse_init_fs_context,
--
fs/overlayfs/params.c=760=static const struct fs_context_operations ovl_context_ops = {
--
fs/overlayfs/params.c-769- * This is called during fsopen() and will record the user namespace of
fs/overlayfs/params.c:770: * the caller in fc->user_ns since we've raised FS_USERNS_MOUNT. We'll
fs/overlayfs/params.c-771- * need it when we actually create the superblock to verify that the
--
fs/overlayfs/super.c=1578=struct file_system_type ovl_fs_type = {
--
fs/overlayfs/super.c-1582- .parameters = ovl_parameter_spec,
fs/overlayfs/super.c:1583: .fs_flags = FS_USERNS_MOUNT,
fs/overlayfs/super.c-1584- .kill_sb = kill_anon_super,
--
fs/proc/root.c=357=static struct file_system_type proc_fs_type = {
--
fs/proc/root.c-361- .kill_sb = proc_kill_sb,
fs/proc/root.c:362: .fs_flags = FS_USERNS_MOUNT | FS_DISALLOW_NOTIFY_PERM,
fs/proc/root.c-363-};
--
fs/ramfs/inode.c=317=static struct file_system_type ramfs_fs_type = {
--
fs/ramfs/inode.c-321- .kill_sb = ramfs_kill_sb,
fs/ramfs/inode.c:322: .fs_flags = FS_USERNS_MOUNT,
fs/ramfs/inode.c-323-};
--
fs/super.c=691=bool mount_capable(struct fs_context *fc)
fs/super.c-692-{
fs/super.c:693: if (!(fc->fs_type->fs_flags & FS_USERNS_MOUNT))
fs/super.c-694- return capable(CAP_SYS_ADMIN);
--
fs/super.c=731=struct super_block *sget_fc(struct fs_context *fc,
--
fs/super.c-740- /*
fs/super.c:741: * Never allow s_user_ns != &init_user_ns when FS_USERNS_MOUNT is
fs/super.c-742- * not set, as the filesystem is likely unprepared to handle it.
--
fs/super.c-745- */
fs/super.c:746: if (user_ns != &init_user_ns && !(fc->fs_type->fs_flags & FS_USERNS_MOUNT)) {
fs/super.c-747- errorfc(fc, "VFS: Mounting from non-initial user namespace is not allowed");
--
fs/sysfs/mount.c=90=static struct file_system_type sysfs_fs_type = {
--
fs/sysfs/mount.c-93- .kill_sb = sysfs_kill_sb,
fs/sysfs/mount.c:94: .fs_flags = FS_USERNS_MOUNT,
fs/sysfs/mount.c-95-};
--
include/linux/fs.h=2263=struct file_system_type {
--
include/linux/fs.h-2268-#define FS_HAS_SUBTYPE 4
include/linux/fs.h:2269:#define FS_USERNS_MOUNT 8 /* Can be mounted by userns root */
include/linux/fs.h-2270-#define FS_DISALLOW_NOTIFY_PERM 16 /* Disable fanotify permission events */
--
ipc/mqueue.c=1619=static struct file_system_type mqueue_fs_type = {
--
ipc/mqueue.c-1622- .kill_sb = kill_anon_super,
ipc/mqueue.c:1623: .fs_flags = FS_USERNS_MOUNT,
ipc/mqueue.c-1624-};
--
kernel/bpf/inode.c=1082=static struct file_system_type bpf_fs_type = {
--
kernel/bpf/inode.c-1087- .kill_sb = bpf_kill_super,
kernel/bpf/inode.c:1088: .fs_flags = FS_USERNS_MOUNT,
kernel/bpf/inode.c-1089-};
--
kernel/cgroup/cgroup.c=2395=struct file_system_type cgroup_fs_type = {
--
kernel/cgroup/cgroup.c-2399- .kill_sb = cgroup_kill_sb,
kernel/cgroup/cgroup.c:2400: .fs_flags = FS_USERNS_MOUNT,
kernel/cgroup/cgroup.c-2401-};
--
kernel/cgroup/cgroup.c=2403=static struct file_system_type cgroup2_fs_type = {
--
kernel/cgroup/cgroup.c-2407- .kill_sb = cgroup_kill_sb,
kernel/cgroup/cgroup.c:2408: .fs_flags = FS_USERNS_MOUNT,
kernel/cgroup/cgroup.c-2409-};
--
kernel/cgroup/cgroup.c=2476=static struct file_system_type cpuset_fs_type = {
--
kernel/cgroup/cgroup.c-2479- .parameters = cpuset_fs_parameters,
kernel/cgroup/cgroup.c:2480: .fs_flags = FS_USERNS_MOUNT,
kernel/cgroup/cgroup.c-2481-};
--
mm/shmem.c=5347=static struct file_system_type shmem_fs_type = {
--
mm/shmem.c-5354- .kill_sb = kill_anon_super,
mm/shmem.c:5355: .fs_flags = FS_USERNS_MOUNT | FS_ALLOW_IDMAP | FS_MGTIME,
mm/shmem.c-5356-};
--
mm/shmem.c=5757=static struct file_system_type shmem_fs_type = {
--
mm/shmem.c-5761- .kill_sb = ramfs_kill_sb,
mm/shmem.c:5762: .fs_flags = FS_USERNS_MOUNT,
mm/shmem.c-5763-};
]
|
| 8/2 |
2026/05/18 15:03 |
llm |
expert |
0m
Model:
Tokens:
input: 20904
output: 49
thoughts: 4961
Thoughts: **Analyzing the OCFS2 Deadlock Vulnerability**
Okay, so here's the deal: OCFS2, the clustered file system, isn't user namespace-friendly due to the lack of `FS_USERNS_MOUNT`. This means that without `CAP_SYS_ADMIN` privileges, you can't mount it. The key here is the "Malicious Filesystem Trigger" β a specially crafted OCFS2 image. This is a dead-end, though, from an *exploitable* perspective; itβs a deadlock, and deadlocks rarely lead to straightforward privilege escalation or memory corruption. They're more of a headache in terms of Denial of Service (DoS), which is exactly what we've got.
The dimensions are pretty clear: Not exploitable, definite DoS, inaccessible to unprivileged processes (requires `CAP_SYS_ADMIN`), not user namespace-accessible, not a VM or network trigger, but definitely triggered by a malicious filesystem image. Peripheral? No, because it's a filesystem issue; the malicious image covers that. So, Yes for Malicious Filesystem, and No for Peripheral.
Now, let's circle back to the core of the bug. The lockdep warning is the smoking gun: a circular locking dependency. `rlock(&journal->j_trans_barrier)` is trying to acquire something else that is locked by something else which depends on the barrier. In a deadlock, it's all about locks: specifically, `&journal->j_trans_barrier` with `ocfs2_sysfile_lock_key[GLOBAL_BITMAP_SYSTEM_INODE]` and `sb_internal#2`, the filesystem superblock internal lock. The resulting DoS is a result of the deadlock.
Checking further, the `mount` and `mkdirat` operations in the reproducer are key. The `mkdirat` triggers the `ocfs2_mkdir`, which starts the locking process. The `mount mqueue` doesn't seem directly relevant, it's likely just mounting an unrelated thing into the newly created dir.
The lockdep chain shows a specific sequence: A task is holding locks, including the barrier, when it wants the global lock, and another context is trying to get those locks. It's a race, right? Is this something that needs a malicious image, or can normal filesystem operations trigger this? Here's the kicker: if any user who can call `mkdir` and `rmdir` can trigger this, the bug goes from "interesting" to "a potential problem." The code path for mkdir and rmdir will need to be concurrently executed to trigger the lock.
Let's drill down: The lock order is `&journal->j_trans_barrier` and `sb_internal#2` from within `ocfs2_start_trans` for the `mkdir` path. Then, `rmdir` -> `ocfs2_evict_inode` is trying to take the same lock. The lockdep output confirms the two paths. There's an rmdir operation occurring somewhere in a concurrent operation to the mknod/mkdir path. The rmdir seems to be going down the path of `ocfs2_evict_inode`, which is where we acquire `&ocfs2_sysfile_lock_key[GLOBAL_BITMAP_SYSTEM_INODE]`.
The lockdep output points to the scenario: `ocfs2_evict_inode` acquires it, but it seems to want `sb_internal#2` and `&journal->j_trans_barrier`, which are held by `mkdir`. If you can get `rmdir` and `mkdir` going at the same time and in the right order, you are in a deadlock.
So the real question: does this require a crafted image? Or can *normal* OCFS2 filesystem interactions cause this? The stack traces for `mkdir` and `rmdir` show they're using OCFS2 functions. So this isn't necessarily a malicious image issue. A user with sufficient OCFS2 access could potentially trigger this deadlock with `mkdir` and `rmdir` operations.
|
| 9/2 |
2026/05/18 15:04 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/ocfs2/suballoc.c IncludeLines:true Name:ocfs2_reserve_suballoc_bits]
Results: map[SourceCode: 837: static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
838: struct ocfs2_alloc_context *ac,
839: int type,
840: u32 slot,
841: u64 *last_alloc_group,
842: int flags)
843: {
844: int status;
845: u32 bits_wanted = ac->ac_bits_wanted;
846: struct inode *alloc_inode;
847: struct buffer_head *bh = NULL;
848: struct ocfs2_dinode *fe;
849: u32 free_bits;
850:
851: alloc_inode = ocfs2_get_system_file_inode(osb, type, slot);
852: if (!alloc_inode) {
853: mlog_errno(-EINVAL);
854: return -EINVAL;
855: }
856:
857: inode_lock(alloc_inode);
858:
859: status = ocfs2_inode_lock(alloc_inode, &bh, 1);
860: if (status < 0) {
861: inode_unlock(alloc_inode);
862: iput(alloc_inode);
863:
864: mlog_errno(status);
865: return status;
866: }
867:
868: ac->ac_inode = alloc_inode;
869: ac->ac_alloc_slot = slot;
870:
871: fe = (struct ocfs2_dinode *) bh->b_data;
872:
873: /* The bh was validated by the inode read inside
874: * ocfs2_inode_lock(). Any corruption is a code bug. */
875: BUG_ON(!OCFS2_IS_VALID_DINODE(fe));
876:
877: if (!(fe->i_flags & cpu_to_le32(OCFS2_CHAIN_FL))) {
878: status = ocfs2_error(alloc_inode->i_sb,
879: "Invalid chain allocator %llu\n",
880: (unsigned long long)le64_to_cpu(fe->i_blkno));
881: goto bail;
882: }
883:
884: free_bits = le32_to_cpu(fe->id1.bitmap1.i_total) -
885: le32_to_cpu(fe->id1.bitmap1.i_used);
886:
887: if (bits_wanted > free_bits) {
888: /* cluster bitmap never grows */
889: if (ocfs2_is_cluster_bitmap(alloc_inode)) {
890: trace_ocfs2_reserve_suballoc_bits_nospc(bits_wanted,
891: free_bits);
892: status = -ENOSPC;
893: goto bail;
894: }
895:
896: if (!(flags & ALLOC_NEW_GROUP)) {
897: trace_ocfs2_reserve_suballoc_bits_no_new_group(
898: slot, bits_wanted, free_bits);
899: status = -ENOSPC;
900: goto bail;
901: }
902:
903: status = ocfs2_block_group_alloc(osb, alloc_inode, bh,
904: ac->ac_max_block,
905: last_alloc_group, flags);
906: if (status < 0) {
907: if (status != -ENOSPC)
908: mlog_errno(status);
909: goto bail;
910: }
911: atomic_inc(&osb->alloc_stats.bg_extends);
912:
913: /* You should never ask for this much metadata */
914: BUG_ON(bits_wanted >
915: (le32_to_cpu(fe->id1.bitmap1.i_total)
916: - le32_to_cpu(fe->id1.bitmap1.i_used)));
917: }
918:
919: get_bh(bh);
920: ac->ac_bh = bh;
921: bail:
922: brelse(bh);
923:
924: if (status)
925: mlog_errno(status);
926: return status;
927: }
SourceFile:fs/ocfs2/suballoc.c]
|
| 10/2 |
2026/05/18 15:04 |
llm |
expert |
0m
Model:
Tokens:
input: 28186
output: 53
thoughts: 735
Thoughts: **Analyzing a Potential Lock Ordering Issue in OCFS2 Suballocation**
Okay, let's break this down. My initial thought is to trace the lock acquisition sequence within `ocfs2_reserve_suballoc_bits`. Line 857, we see `inode_lock(alloc_inode)`. Then, line 903 calls `ocfs2_block_group_alloc`, which in turn, calls `ocfs2_start_trans`. `ocfs2_start_trans` is the key, as it involves `sb_internal#2` (through `sb_start_intwrite`) and `&journal->j_trans_barrier`. So we have `inode_lock(alloc_inode)` chaining to `sb_start_intwrite`, which then leads to `down_read(&journal->j_trans_barrier)`.
The crucial part here is `alloc_inode`. It looks like if it's the `GLOBAL_BITMAP_SYSTEM_INODE`, then it tries to acquire `&ocfs2_sysfile_lock_key[GLOBAL_BITMAP_SYSTEM_INODE]`. And in `ocfs2_reserve_suballoc_bits`, the `alloc_inode` comes from `ocfs2_get_system_file_inode(osb, type, slot)`. If `type` is `INODE_ALLOC_SYSTEM_INODE`, then we're talking about `&ocfs2_sysfile_lock_key[INODE_ALLOC_SYSTEM_INODE]`. If the type is `GLOBAL_BITMAP_SYSTEM_INODE`, then it is `&ocfs2_sysfile_lock_key[GLOBAL_BITMAP_SYSTEM_INODE]`.
Now, the lockdep warning... the executor is holding `sb_internal#2` and `&journal->j_trans_barrier`, and the key here is it's attempting to acquire `&ocfs2_sysfile_lock_key[INODE_ALLOC_SYSTEM_INODE]` as well! Then `&journal->j_trans_barrier` is held. So there's definitely a lock ordering conflict happening.
I need to figure out *where* it's attempting to acquire `&ocfs2_sysfile_lock_key[GLOBAL_BITMAP_SYSTEM_INODE]`. It seems that the attempt takes place within `_ocfs2_reclaim_suballoc_to_main`, specifically when calling `inode_lock(main_bm_inode)`.
|
| 11/2 |
2026/05/18 15:04 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/ocfs2/suballoc.c IncludeLines:true Name:_ocfs2_reclaim_suballoc_to_main]
Results: map[SourceCode:2637: /*
2638: * Reclaim the suballocator managed space to main bitmap.
2639: * This function first works on the suballocator to perform the
2640: * cleanup rec/alloc_inode job, then switches to the main bitmap
2641: * to reclaim released space.
2642: *
2643: * handle: The transaction handle
2644: * alloc_inode: The suballoc inode
2645: * alloc_bh: The buffer_head of suballoc inode
2646: * group_bh: The group descriptor buffer_head of suballocator managed.
2647: * Caller should release the input group_bh.
2648: */
2649: static int _ocfs2_reclaim_suballoc_to_main(handle_t *handle,
2650: struct inode *alloc_inode,
2651: struct buffer_head *alloc_bh,
2652: struct buffer_head *group_bh)
2653: {
2654: int idx, status = 0;
2655: int i, next_free_rec, len = 0;
2656: __le16 old_bg_contig_free_bits = 0;
2657: u16 start_bit;
2658: u32 tmp_used;
2659: u64 bg_blkno, start_blk;
2660: unsigned int count;
2661: struct ocfs2_chain_rec *rec;
2662: struct buffer_head *main_bm_bh = NULL;
2663: struct inode *main_bm_inode = NULL;
2664: struct ocfs2_super *osb = OCFS2_SB(alloc_inode->i_sb);
2665: struct ocfs2_dinode *fe = (struct ocfs2_dinode *) alloc_bh->b_data;
2666: struct ocfs2_chain_list *cl = &fe->id2.i_chain;
2667: struct ocfs2_group_desc *group = (struct ocfs2_group_desc *) group_bh->b_data;
2668:
2669: idx = le16_to_cpu(group->bg_chain);
2670: rec = &(cl->cl_recs[idx]);
2671:
2672: status = ocfs2_extend_trans(handle,
2673: ocfs2_calc_group_alloc_credits(osb->sb,
2674: le16_to_cpu(cl->cl_cpg)));
2675: if (status) {
2676: mlog_errno(status);
2677: goto bail;
2678: }
2679: status = ocfs2_journal_access_di(handle, INODE_CACHE(alloc_inode),
2680: alloc_bh, OCFS2_JOURNAL_ACCESS_WRITE);
2681: if (status < 0) {
2682: mlog_errno(status);
2683: goto bail;
2684: }
2685:
2686: /*
2687: * Only clear the suballocator rec item in-place.
2688: *
2689: * If idx is not the last, we don't compress (remove the empty item)
2690: * the cl_recs[]. If not, we need to do lots jobs.
2691: *
2692: * Compress cl_recs[] code example:
2693: * if (idx != cl->cl_next_free_rec - 1)
2694: * memmove(&cl->cl_recs[idx], &cl->cl_recs[idx + 1],
2695: * sizeof(struct ocfs2_chain_rec) *
2696: * (cl->cl_next_free_rec - idx - 1));
2697: * for(i = idx; i < cl->cl_next_free_rec-1; i++) {
2698: * group->bg_chain = "later group->bg_chain";
2699: * group->bg_blkno = xxx;
2700: * ... ...
2701: * }
2702: */
2703:
2704: tmp_used = le32_to_cpu(fe->id1.bitmap1.i_total);
2705: fe->id1.bitmap1.i_total = cpu_to_le32(tmp_used - le32_to_cpu(rec->c_total));
2706:
2707: /* Substraction 1 for the block group itself */
2708: tmp_used = le32_to_cpu(fe->id1.bitmap1.i_used);
2709: fe->id1.bitmap1.i_used = cpu_to_le32(tmp_used - 1);
2710:
2711: tmp_used = le32_to_cpu(fe->i_clusters);
2712: fe->i_clusters = cpu_to_le32(tmp_used - le16_to_cpu(cl->cl_cpg));
2713:
2714: spin_lock(&OCFS2_I(alloc_inode)->ip_lock);
2715: OCFS2_I(alloc_inode)->ip_clusters -= le32_to_cpu(fe->i_clusters);
2716: fe->i_size = cpu_to_le64(ocfs2_clusters_to_bytes(alloc_inode->i_sb,
2717: le32_to_cpu(fe->i_clusters)));
2718: spin_unlock(&OCFS2_I(alloc_inode)->ip_lock);
2719: i_size_write(alloc_inode, le64_to_cpu(fe->i_size));
2720: alloc_inode->i_blocks = ocfs2_inode_sector_count(alloc_inode);
2721:
2722: ocfs2_journal_dirty(handle, alloc_bh);
2723: ocfs2_update_inode_fsync_trans(handle, alloc_inode, 0);
2724:
2725: start_blk = le64_to_cpu(rec->c_blkno);
2726: count = le32_to_cpu(rec->c_total) / le16_to_cpu(cl->cl_bpc);
2727:
2728: /*
2729: * If the rec is the last one, let's compress the chain list by
2730: * removing the empty cl_recs[] at the end.
2731: */
2732: next_free_rec = le16_to_cpu(cl->cl_next_free_rec);
2733: if (idx == (next_free_rec - 1)) {
2734: len++; /* the last item should be counted first */
2735: for (i = (next_free_rec - 2); i > 0; i--) {
2736: if (cl->cl_recs[i].c_free == cl->cl_recs[i].c_total)
2737: len++;
2738: else
2739: break;
2740: }
2741: }
2742: le16_add_cpu(&cl->cl_next_free_rec, -len);
2743:
2744: rec->c_free = 0;
2745: rec->c_total = 0;
2746: rec->c_blkno = 0;
2747: ocfs2_remove_from_cache(INODE_CACHE(alloc_inode), group_bh);
2748: memset(group, 0, sizeof(struct ocfs2_group_desc));
2749:
2750: /* prepare job for reclaim clusters */
2751: main_bm_inode = ocfs2_get_system_file_inode(osb,
2752: GLOBAL_BITMAP_SYSTEM_INODE,
2753: OCFS2_INVALID_SLOT);
2754: if (!main_bm_inode)
2755: goto bail; /* ignore the error in reclaim path */
2756:
2757: inode_lock(main_bm_inode);
2758:
2759: status = ocfs2_inode_lock(main_bm_inode, &main_bm_bh, 1);
2760: if (status < 0)
2761: goto free_bm_inode; /* ignore the error in reclaim path */
2762:
2763: ocfs2_block_to_cluster_group(main_bm_inode, start_blk, &bg_blkno,
2764: &start_bit);
2765: fe = (struct ocfs2_dinode *) main_bm_bh->b_data;
2766: cl = &fe->id2.i_chain;
2767: /* reuse group_bh, caller will release the input group_bh */
2768: group_bh = NULL;
2769:
2770: /* reclaim clusters to global_bitmap */
2771: status = ocfs2_read_group_descriptor(main_bm_inode, fe, bg_blkno,
2772: &group_bh);
2773: if (status < 0) {
2774: mlog_errno(status);
2775: goto free_bm_bh;
2776: }
2777: group = (struct ocfs2_group_desc *) group_bh->b_data;
2778:
2779: if ((count + start_bit) > le16_to_cpu(group->bg_bits)) {
2780: ocfs2_error(alloc_inode->i_sb,
2781: "reclaim length (%d) beyands block group length (%d)",
2782: count + start_bit, le16_to_cpu(group->bg_bits));
2783: goto free_group_bh;
2784: }
2785:
2786: old_bg_contig_free_bits = group->bg_contig_free_bits;
2787: status = ocfs2_block_group_clear_bits(handle, main_bm_inode,
2788: group, group_bh,
2789: start_bit, count, 0,
2790: _ocfs2_clear_bit);
2791: if (status < 0) {
2792: mlog_errno(status);
2793: goto free_group_bh;
2794: }
2795:
2796: status = ocfs2_journal_access_di(handle, INODE_CACHE(main_bm_inode),
2797: main_bm_bh, OCFS2_JOURNAL_ACCESS_WRITE);
2798: if (status < 0) {
2799: mlog_errno(status);
2800: ocfs2_block_group_set_bits(handle, main_bm_inode, group, group_bh,
2801: start_bit, count,
2802: le16_to_cpu(old_bg_contig_free_bits), 1);
2803: goto free_group_bh;
2804: }
2805:
2806: idx = le16_to_cpu(group->bg_chain);
2807: rec = &(cl->cl_recs[idx]);
2808:
2809: le32_add_cpu(&rec->c_free, count);
2810: tmp_used = le32_to_cpu(fe->id1.bitmap1.i_used);
2811: fe->id1.bitmap1.i_used = cpu_to_le32(tmp_used - count);
2812: ocfs2_journal_dirty(handle, main_bm_bh);
2813:
2814: free_group_bh:
2815: brelse(group_bh);
2816:
2817: free_bm_bh:
2818: ocfs2_inode_unlock(main_bm_inode, 1);
2819: brelse(main_bm_bh);
2820:
2821: free_bm_inode:
2822: inode_unlock(main_bm_inode);
2823: iput(main_bm_inode);
2824:
2825: bail:
2826: return status;
2827: }
SourceFile:fs/ocfs2/suballoc.c]
|
| 12/2 |
2026/05/18 15:04 |
llm |
expert |
0m
Model:
Tokens:
input: 33015
output: 57
thoughts: 966
Thoughts: **Analyzing a Potential Lock Ordering Problem in OCFS2**
Okay, let's break this down. I'm looking at a potential deadlock scenario within the OCFS2 file system. Specifically, I'm focusing on the interaction between two functions: `_ocfs2_reclaim_suballoc_to_main` and `ocfs2_reserve_suballoc_bits`. The lockdep warning really grabbed my attention, so let's dig deeper.
The core of the issue lies in how these functions handle locking, particularly concerning the `GLOBAL_BITMAP_SYSTEM_INODE`, which maps to `&ocfs2_sysfile_lock_key[GLOBAL_BITMAP_SYSTEM_INODE]`.
In `_ocfs2_reclaim_suballoc_to_main`, the code already operates within a transaction indicated by the `handle_t *handle`. This means it *already* holds the `sb_internal#2` and `&journal->j_trans_barrier` locks because the transaction mechanism mandates it. However, within this function, `inode_lock(main_bm_inode)` which is equivalent to `inode_lock(GLOBAL_BITMAP_SYSTEM_INODE)` is also called. The lockdep warning clearly highlights this exact scenario where it tries to acquire `&ocfs2_sysfile_lock_key[GLOBAL_BITMAP_SYSTEM_INODE]` *while already holding* the transaction locks.
Conversely, `ocfs2_reserve_suballoc_bits` takes a different route. It acquires `inode_lock(alloc_inode)` *before* starting the transaction. Critically, if `alloc_inode` happens to be `GLOBAL_BITMAP_SYSTEM_INODE`, this means the code will acquire `&ocfs2_sysfile_lock_key[GLOBAL_BITMAP_SYSTEM_INODE]` *before* taking the `sb_internal#2` and `&journal->j_trans_barrier` locks via `ocfs2_start_trans` called within `ocfs2_block_group_alloc`.
Now, the classic ABBA deadlock pattern emerges. We have two locking paths:
* **Path A:** `ocfs2_reserve_suballoc_bits` (if called with `GLOBAL_BITMAP_SYSTEM_INODE`):
1. `inode_lock(GLOBAL_BITMAP_SYSTEM_INODE)`
2. `ocfs2_start_trans` (acquires `sb_internal#2` and `&journal->j_trans_barrier`)
* **Path B:** `_ocfs2_reclaim_suballoc_to_main`:
1. `ocfs2_start_trans` (likely within `ocfs2_remove_inode` or a similar transaction-initiating function) (acquires `sb_internal#2` and `&journal->j_trans_barrier`)
2. `_ocfs2_reclaim_suballoc_to_main` acquires `inode_lock(GLOBAL_BITMAP_SYSTEM_INODE)`
This is textbook: one path locks A then B, and the other locks B then A. Deadlock City.
The key question is, *can* Path A actually happen? Does `ocfs2_reserve_suballoc_bits` *ever* get called with `GLOBAL_BITMAP_SYSTEM_INODE` as the `alloc_inode`? I need to trace the call paths to `ocfs2_reserve_suballoc_bits` and see under what conditions it's called with the global bitmap's inode. If that's possible, then we have a real and serious problem. The `type` and `slot` arguments that are passed to `ocfs2_reserve_suballoc_bits` need to be analyzed to see if they can result in the `alloc_inode` argument becoming `GLOBAL_BITMAP_SYSTEM_INODE`.
|
| 13/2 |
2026/05/18 15:04 |
tool |
codesearch-find-references |
0m
Args: map[ContextFile:fs/ocfs2/suballoc.c IncludeSnippetLines:0 Name:ocfs2_reserve_suballoc_bits SourceTreePrefix:]
Results: map[References:[map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ocfs2_reserve_cluster_bitmap_bits SourceFile:fs/ocfs2/suballoc.c SourceLine:1203] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ocfs2_reserve_new_inode SourceFile:fs/ocfs2/suballoc.c SourceLine:1143] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ocfs2_reserve_new_metadata_blocks SourceFile:fs/ocfs2/suballoc.c SourceLine:1053] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ocfs2_steal_resource SourceFile:fs/ocfs2/suballoc.c SourceLine:1003]] TruncatedOutput:false]
|
| 14/2 |
2026/05/18 15:04 |
llm |
expert |
0m
Model:
Tokens:
input: 35130
output: 50
thoughts: 17
Thoughts: Okay, here's my attempt at summarizing that thought process, keeping in mind I'm speaking to a fellow expert:
**Investigating `ocfs2_reserve_cluster_bitmap_bits`**
Alright, let's dive into this `ocfs2_reserve_cluster_bitmap_bits` function. I need to refresh my memory on the intricacies of OCFS2 bitmap management, and how this particular function fits into the overall allocation strategy. I'm assuming we're dealing with resource reservation, potentially at the cluster level. Is this about preventing contention? Protecting against starvation? What's the context where this call is made? Are we looking at a performance bottleneck, a potential race condition, or a subtle bug in a specific corner case? I need to analyze its role within the larger allocation framework to truly understand its purpose and behavior. Let's see how it interacts with the lock structures, what data structures it modifies, and how it handles potential errors. Time to get down into the code and trace the execution path.
|
| 15/2 |
2026/05/18 15:05 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/ocfs2/suballoc.c IncludeLines:true Name:ocfs2_reserve_cluster_bitmap_bits]
Results: map[SourceCode:1193: /* local alloc code has to do the same thing, so rather than do this
1194: * twice.. */
1195: int ocfs2_reserve_cluster_bitmap_bits(struct ocfs2_super *osb,
1196: struct ocfs2_alloc_context *ac)
1197: {
1198: int status;
1199:
1200: ac->ac_which = OCFS2_AC_USE_MAIN;
1201: ac->ac_group_search = ocfs2_cluster_group_search;
1202:
1203: status = ocfs2_reserve_suballoc_bits(osb, ac,
1204: GLOBAL_BITMAP_SYSTEM_INODE,
1205: OCFS2_INVALID_SLOT, NULL,
1206: ALLOC_NEW_GROUP);
1207: if (status < 0 && status != -ENOSPC)
1208: mlog_errno(status);
1209:
1210: return status;
1211: }
SourceFile:fs/ocfs2/suballoc.c]
|
| 16/2 |
2026/05/18 15:05 |
llm |
expert |
0m
Model:
Tokens:
input: 35745
output: 58
thoughts: 132
Thoughts: **Cluster Allocation Reservation Flow**
Okay, so I'm tracing this cluster allocation process in OCFS2. My immediate thought is, yes, `ocfs2_reserve_cluster_bitmap_bits` is definitely calling `ocfs2_reserve_suballoc_bits` and, specifically, using `GLOBAL_BITMAP_SYSTEM_INODE`. That's the correct path, and it makes sense, given what I know about the bitmap's structure. And, from what I'm seeing, `ocfs2_reserve_cluster_bitmap_bits` is also definitely being called when clusters are allocated. That confirms the initial hunch.
Now, wait a second... where *exactly* is `ocfs2_reserve_cluster_bitmap_bits` being called from? Ah, yes, it's called from `ocfs2_reserve_clusters`. Okay, that's the next critical piece. But that makes me think... does `ocfs2_reserve_clusters` actually *start* a transaction? Because, if memory serves, reservations are usually done *before* the transaction is initiated in OCFS2, right? That's how it's supposed to work. So, I need to verify that. I'll need to check the code for `ocfs2_reserve_clusters` to ensure the correct order of operations.
|
| 17/2 |
2026/05/18 15:05 |
tool |
codesearch-find-references |
0m
Args: map[ContextFile:fs/ocfs2/suballoc.c IncludeSnippetLines:0 Name:ocfs2_reserve_cluster_bitmap_bits SourceTreePrefix:]
Results: map[References:[map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ocfs2_local_alloc_reserve_for_window SourceFile:fs/ocfs2/localalloc.c SourceLine:1108] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ocfs2_reserve_clusters_with_limit SourceFile:fs/ocfs2/suballoc.c SourceLine:1248]] TruncatedOutput:false]
|
| 18/2 |
2026/05/18 15:05 |
llm |
expert |
0m
Model:
Tokens:
input: 36365
output: 50
thoughts: 17
Thoughts: Okay, let's dive into this. Here's my thought process on checking `ocfs2_reserve_clusters_with_limit`, as if I were considering it myself:
**Analyzing the Cluster Reservation Limit Function**
Alright, time to get into the nitty-gritty and take a look at `ocfs2_reserve_clusters_with_limit`. My initial question is always, "What problem is this function designed to solve?" Given its name, it's pretty clear: cluster reservation, with some kind of controlled limit involved. I need to understand *how* that limit is implemented and, more importantly, *why*. Is this for fairness across nodes? Is it a way to prevent starvation? Or maybe it's just a mechanism to avoid excessive allocation? Understanding the *why* is key to evaluating its effectiveness.
I'll start by tracing the function's call sites and dependencies. Where is it used in the overall OCFS2 ecosystem? Which other functions rely on its output? Are there any potential bottlenecks or race conditions I should be on the lookout for?
Next, I need to look at the internal logic. What are the specific parameters? What checks are performed? How does it actually calculate the amount to reserve? Are there any obvious areas for improvement or potential pitfalls? Are there any error conditions that are not being properly handled? Is this a potential point of failure for the cluster if not implemented and/or implemented correctly?
I'll also keep the bigger picture in mind. How does this fit into the broader cluster management strategy? Does it align with the overall allocation and deallocation strategy? How does it interact with other resources like inodes, blocks, and extents?
Essentially, I want to confirm that this is a well-designed piece of code that does what it's supposed to do efficiently and safely, without introducing any new issues or limitations to the overall system. Time to dig in!
|
| 19/2 |
2026/05/18 15:05 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/ocfs2/suballoc.c IncludeLines:true Name:ocfs2_reserve_clusters_with_limit]
Results: map[SourceCode:1213: /* Callers don't need to care which bitmap (local alloc or main) to
1214: * use so we figure it out for them, but unfortunately this clutters
1215: * things a bit. */
1216: static int ocfs2_reserve_clusters_with_limit(struct ocfs2_super *osb,
1217: u32 bits_wanted, u64 max_block,
1218: int flags,
1219: struct ocfs2_alloc_context **ac)
1220: {
1221: int status, ret = 0;
1222: int retried = 0;
1223:
1224: *ac = kzalloc(sizeof(struct ocfs2_alloc_context), GFP_KERNEL);
1225: if (!(*ac)) {
1226: status = -ENOMEM;
1227: mlog_errno(status);
1228: goto bail;
1229: }
1230:
1231: (*ac)->ac_bits_wanted = bits_wanted;
1232: (*ac)->ac_max_block = max_block;
1233:
1234: status = -ENOSPC;
1235: if (!(flags & ALLOC_GROUPS_FROM_GLOBAL) &&
1236: ocfs2_alloc_should_use_local(osb, bits_wanted)) {
1237: status = ocfs2_reserve_local_alloc_bits(osb,
1238: bits_wanted,
1239: *ac);
1240: if ((status < 0) && (status != -ENOSPC)) {
1241: mlog_errno(status);
1242: goto bail;
1243: }
1244: }
1245:
1246: if (status == -ENOSPC) {
1247: retry:
1248: status = ocfs2_reserve_cluster_bitmap_bits(osb, *ac);
1249: /* Retry if there is sufficient space cached in truncate log */
1250: if (status == -ENOSPC && !retried) {
1251: retried = 1;
1252: ocfs2_inode_unlock((*ac)->ac_inode, 1);
1253: inode_unlock((*ac)->ac_inode);
1254:
1255: ret = ocfs2_try_to_free_truncate_log(osb, bits_wanted);
1256: if (ret == 1) {
1257: iput((*ac)->ac_inode);
1258: (*ac)->ac_inode = NULL;
1259: goto retry;
1260: }
1261:
1262: if (ret < 0)
1263: mlog_errno(ret);
1264:
1265: inode_lock((*ac)->ac_inode);
1266: ret = ocfs2_inode_lock((*ac)->ac_inode, NULL, 1);
1267: if (ret < 0) {
1268: mlog_errno(ret);
1269: inode_unlock((*ac)->ac_inode);
1270: iput((*ac)->ac_inode);
1271: (*ac)->ac_inode = NULL;
1272: goto bail;
1273: }
1274: }
1275: if (status < 0) {
1276: if (status != -ENOSPC)
1277: mlog_errno(status);
1278: goto bail;
1279: }
1280: }
1281:
1282: status = 0;
1283: bail:
1284: if ((status < 0) && *ac) {
1285: ocfs2_free_alloc_context(*ac);
1286: *ac = NULL;
1287: }
1288:
1289: if (status)
1290: mlog_errno(status);
1291: return status;
1292: }
SourceFile:fs/ocfs2/suballoc.c]
|
| 20/2 |
2026/05/18 15:05 |
llm |
expert |
0m
Model:
Tokens:
input: 38022
output: 48
thoughts: 701
Thoughts: **Deadlock Analysis in OCFS2 Suballocator Operations**
Okay, let's break this down. My initial thought process is leading me to a potential ABBA deadlock scenario within the OCFS2 suballocator code, and it seems this could be triggered during fairly routine filesystem operations.
Path A, dealing with cluster group allocation, starts with `ocfs2_reserve_clusters` which calls `ocfs2_reserve_cluster_bitmap_bits`. This in turn calls `ocfs2_reserve_suballoc_bits`, passing `GLOBAL_BITMAP_SYSTEM_INODE`. Crucially, within `ocfs2_reserve_suballoc_bits`, the code grabs `inode_lock(alloc_inode)`, and that lock is on our `GLOBAL_BITMAP_SYSTEM_INODE`. If a new block group is needed, `ocfs2_block_group_alloc` is invoked, which then kicks off a transaction using `ocfs2_start_trans`. The transaction uses `sb_internal#2` and `&journal->j_trans_barrier`. So, from the initial lock, the flow is `GLOBAL_BITMAP_SYSTEM_INODE -> sb_internal#2 -> &journal->j_trans_barrier`.
Path B, on the other hand, deals with inode deletion and suballocator reclamation. The trail starts with `_ocfs2_reclaim_suballoc_to_main`, which is called through `ocfs2_free_suballoc_bits` (via `ocfs2_free_dinode` and ultimately stemming from `ocfs2_remove_inode`). `ocfs2_remove_inode` itself is called by `ocfs2_wipe_inode` which is called by `ocfs2_delete_inode`, and so on. In `ocfs2_remove_inode`, we see the call to `ocfs2_start_trans` using `sb_internal#2` and `&journal->j_trans_barrier`. Later, within `_ocfs2_reclaim_suballoc_to_main`, `inode_lock(main_bm_inode)` is acquired, and `main_bm_inode` also resolves to `GLOBAL_BITMAP_SYSTEM_INODE`. This means in Path B, we have the sequence `sb_internal#2 -> &journal->j_trans_barrier -> GLOBAL_BITMAP_SYSTEM_INODE`.
The order of lock acquisition is the critical part here. Path A takes `GLOBAL_BITMAP_SYSTEM_INODE` first, and Path B takes `sb_internal#2` first. This is a clear ABBA deadlock, and it's looking like normal file system operations could trigger this, specifically in scenarios where new block groups are allocated (Path A) and inodes are deleted (Path B).
Now, the question is how common Path A is on a running system. Let's remember `ocfs2_reserve_suballoc_bits` calls `ocfs2_block_group_alloc` when `bits_wanted > free_bits` and `flags & ALLOC_NEW_GROUP`. And, because we're talking about `GLOBAL_BITMAP_SYSTEM_INODE`, `ocfs2_is_cluster_bitmap(alloc_inode)` is true. I should probably check that last function.
|
| 21/2 |
2026/05/18 15:05 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/ocfs2/suballoc.c IncludeLines:true Name:ocfs2_is_cluster_bitmap]
Results: map[SourceCode: 168: static inline int ocfs2_is_cluster_bitmap(struct inode *inode)
169: {
170: struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
171: return osb->bitmap_blkno == OCFS2_I(inode)->ip_blkno;
172: }
SourceFile:fs/ocfs2/suballoc.h]
|
| 22/2 |
2026/05/18 15:05 |
llm |
expert |
0m
Model:
Tokens:
input: 39612
output: 54
thoughts: 1635
Thoughts: **Analyzing an OCFS2 Lockdep Issue**
Okay, so I'm digging into this `ocfs2_reserve_suballoc_bits` function and I've hit a conceptual snag. The code checks if the `alloc_inode` is the cluster bitmap. If it *is*, and we don't have enough free bits, we bail with `-ENOSPC`. This makes perfect sense; the cluster bitmap can't grow dynamically, so there's no need to call `ocfs2_block_group_alloc` for it.
Now, my initial question is: how does `ocfs2_reserve_suballoc_bits` trigger a transaction using `ocfs2_block_group_alloc`? The lockdep trace reveals `ocfs2_reserve_new_inode` -> `ocfs2_reserve_suballoc_bits`. Crucially, this calls `ocfs2_reserve_suballoc_bits` with `INODE_ALLOC_SYSTEM_INODE`, *not* `GLOBAL_BITMAP_SYSTEM_INODE` (the cluster bitmap). This means the lock acquisition should be on `&ocfs2_sysfile_lock_key[INODE_ALLOC_SYSTEM_INODE]`.
However, the lockdep warning keeps complaining about `GLOBAL_BITMAP_SYSTEM_INODE`. Why? It doesn't seem to make sense.
I went back and checked the lockdep trace again, this time for where the `GLOBAL_BITMAP_SYSTEM_INODE` lock is acquired. This is *Path B*, and it shows that `GLOBAL_BITMAP_SYSTEM_INODE` is used in a path that starts with `_ocfs2_reclaim_suballoc_to_main`, and eventually reaches `ocfs2_remove_inode`.
But Path A, which is the sequence leading from `ocfs2_reserve_new_inode`, doesn't seem to explain why the lockdep is warning about the `GLOBAL_BITMAP_SYSTEM_INODE`. It's all about `INODE_ALLOC_SYSTEM_INODE`.
The connection here is, in fact: `&ocfs2_sysfile_lock_key[GLOBAL_BITMAP_SYSTEM_INODE]` --> `sb_internal#2` --> `&journal->j_trans_barrier`. This clearly means that *somewhere*, the code acquires `&ocfs2_sysfile_lock_key[GLOBAL_BITMAP_SYSTEM_INODE]` *before* `sb_internal#2`.
The next point I checked was `ocfs2_reserve_cluster_bitmap_bits`. It does call `ocfs2_reserve_suballoc_bits` with `GLOBAL_BITMAP_SYSTEM_INODE`. This then takes `inode_lock(GLOBAL_BITMAP_SYSTEM_INODE)`. It returns to `ocfs2_reserve_clusters_with_limit`.
This makes me think, if `ocfs2_reserve_clusters_with_limit` is called from `ocfs2_reserve_clusters`, does the caller start a transaction *after* reserving the clusters? If it does, then the transaction will take `sb_internal#2` *while still holding* `inode_lock(GLOBAL_BITMAP_SYSTEM_INODE)`. That's where the conflict is. I should check `ocfs2_reserve_clusters` to confirm this.
|
| 23/2 |
2026/05/18 15:06 |
tool |
codesearch-find-references |
0m
Args: map[ContextFile:fs/ocfs2/suballoc.c IncludeSnippetLines:0 Name:ocfs2_reserve_clusters SourceTreePrefix:]
Results: map[References:[map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ocfs2_convert_inline_data_to_extents SourceFile:fs/ocfs2/alloc.c SourceLine:7099] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ocfs2_defrag_extent SourceFile:fs/ocfs2/move_extents.c SourceLine:272] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ocfs2_expand_inline_dir SourceFile:fs/ocfs2/dir.c SourceLine:2883] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ocfs2_expand_inline_dx_root SourceFile:fs/ocfs2/dir.c SourceLine:4070] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ocfs2_extend_dir SourceFile:fs/ocfs2/dir.c SourceLine:3294] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ocfs2_init_xattr_set_ctxt SourceFile:fs/ocfs2/xattr.c SourceLine:3317] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ocfs2_lock_allocators SourceFile:fs/ocfs2/suballoc.c SourceLine:3073] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ocfs2_lock_refcount_allocators SourceFile:fs/ocfs2/refcounttree.c SourceLine:2872] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ocfs2_lock_reflink_xattr_rec_allocators SourceFile:fs/ocfs2/xattr.c SourceLine:6833] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ocfs2_mknod SourceFile:fs/ocfs2/namei.c SourceLine:358] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ocfs2_symlink SourceFile:fs/ocfs2/namei.c SourceLine:1924]] TruncatedOutput:false]
|
| 24/2 |
2026/05/18 15:06 |
llm |
expert |
0m
Model:
Tokens:
input: 42679
output: 46
thoughts: 13
Thoughts: Okay, here's my summary, presented as a stream of thought:
**Diving into `ocfs2_mknod`**
Alright, time to get into this. Let's start with `ocfs2_mknod`. I need to refresh my memory on the specifics of how OCFS2 handles the creation of new nodes. This is a foundational operation, so understanding the ins and outs is critical. I'm going to quickly review the code and relevant data structures, focusing on the interactions with the journal and inode allocation. I'll need to keep an eye out for potential concurrency issues, especially when considering multiple nodes creating files/directories simultaneously. I want to see how it handles the different types of nodes (regular files, directories, symlinks, etc.) and if there's any clever optimization or edge cases to consider. I'm specifically interested in the error handling. I'll mentally map out the execution path and identify the key lock acquisitions and releases. My goal is to grasp the overall design and any potential areas for improvement or deeper investigation. I want to make sure the implementation is solid. Let's get to it.
|
| 25/2 |
2026/05/18 15:06 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/ocfs2/namei.c IncludeLines:true Name:ocfs2_mknod]
Results: map[SourceCode: 230: static int ocfs2_mknod(struct mnt_idmap *idmap,
231: struct inode *dir,
232: struct dentry *dentry,
233: umode_t mode,
234: dev_t dev)
235: {
236: int status = 0;
237: struct buffer_head *parent_fe_bh = NULL;
238: handle_t *handle = NULL;
239: struct ocfs2_super *osb;
240: struct ocfs2_dinode *dirfe;
241: struct ocfs2_dinode *fe = NULL;
242: struct buffer_head *new_fe_bh = NULL;
243: struct inode *inode = NULL;
244: struct ocfs2_alloc_context *inode_ac = NULL;
245: struct ocfs2_alloc_context *data_ac = NULL;
246: struct ocfs2_alloc_context *meta_ac = NULL;
247: int want_clusters = 0;
248: int want_meta = 0;
249: int xattr_credits = 0;
250: struct ocfs2_security_xattr_info si = {
251: .name = NULL,
252: .enable = 1,
253: };
254: int did_quota_inode = 0;
255: struct ocfs2_dir_lookup_result lookup = { NULL, };
256: sigset_t oldset;
257: int did_block_signals = 0;
258: struct ocfs2_dentry_lock *dl = NULL;
259:
260: trace_ocfs2_mknod(dir, dentry, dentry->d_name.len, dentry->d_name.name,
261: (unsigned long long)OCFS2_I(dir)->ip_blkno,
262: (unsigned long)dev, mode);
263:
264: status = dquot_initialize(dir);
265: if (status) {
266: mlog_errno(status);
267: return status;
268: }
269:
270: /* get our super block */
271: osb = OCFS2_SB(dir->i_sb);
272:
273: status = ocfs2_inode_lock(dir, &parent_fe_bh, 1);
274: if (status < 0) {
275: if (status != -ENOENT)
276: mlog_errno(status);
277: return status;
278: }
279:
280: if (S_ISDIR(mode) && (dir->i_nlink >= ocfs2_link_max(osb))) {
281: status = -EMLINK;
282: goto leave;
283: }
284:
285: dirfe = (struct ocfs2_dinode *) parent_fe_bh->b_data;
286: if (!ocfs2_read_links_count(dirfe)) {
287: /* can't make a file in a deleted directory. */
288: status = -ENOENT;
289: goto leave;
290: }
291:
292: status = ocfs2_check_dir_for_entry(dir, dentry->d_name.name,
293: dentry->d_name.len);
294: if (status)
295: goto leave;
296:
297: /* get a spot inside the dir. */
298: status = ocfs2_prepare_dir_for_insert(osb, dir, parent_fe_bh,
299: dentry->d_name.name,
300: dentry->d_name.len, &lookup);
301: if (status < 0) {
302: mlog_errno(status);
303: goto leave;
304: }
305:
306: /* reserve an inode spot */
307: status = ocfs2_reserve_new_inode(osb, &inode_ac);
308: if (status < 0) {
309: if (status != -ENOSPC)
310: mlog_errno(status);
311: goto leave;
312: }
313:
314: inode = ocfs2_get_init_inode(dir, mode);
315: if (IS_ERR(inode)) {
316: status = PTR_ERR(inode);
317: inode = NULL;
318: mlog_errno(status);
319: goto leave;
320: }
321:
322: /* get security xattr */
323: status = ocfs2_init_security_get(inode, dir, &dentry->d_name, &si);
324: if (status) {
325: if (status == -EOPNOTSUPP)
326: si.enable = 0;
327: else {
328: mlog_errno(status);
329: goto leave;
330: }
331: }
332:
333: /* calculate meta data/clusters for setting security and acl xattr */
334: status = ocfs2_calc_xattr_init(dir, parent_fe_bh, mode,
335: &si, &want_clusters,
336: &xattr_credits, &want_meta);
337: if (status < 0) {
338: mlog_errno(status);
339: goto leave;
340: }
341:
342: /* Reserve a cluster if creating an extent based directory. */
343: if (S_ISDIR(mode) && !ocfs2_supports_inline_data(osb)) {
344: want_clusters += 1;
345:
346: /* Dir indexing requires extra space as well */
347: if (ocfs2_supports_indexed_dirs(osb))
348: want_meta++;
349: }
350:
351: status = ocfs2_reserve_new_metadata_blocks(osb, want_meta, &meta_ac);
352: if (status < 0) {
353: if (status != -ENOSPC)
354: mlog_errno(status);
355: goto leave;
356: }
357:
358: status = ocfs2_reserve_clusters(osb, want_clusters, &data_ac);
359: if (status < 0) {
360: if (status != -ENOSPC)
361: mlog_errno(status);
362: goto leave;
363: }
364:
365: handle = ocfs2_start_trans(osb, ocfs2_mknod_credits(osb->sb,
366: S_ISDIR(mode),
367: xattr_credits));
368: if (IS_ERR(handle)) {
369: status = PTR_ERR(handle);
370: handle = NULL;
371: mlog_errno(status);
372: goto leave;
373: }
374:
375: /* Starting to change things, restart is no longer possible. */
376: ocfs2_block_signals(&oldset);
377: did_block_signals = 1;
378:
379: status = dquot_alloc_inode(inode);
380: if (status)
381: goto leave;
382: did_quota_inode = 1;
383:
384: /* do the real work now. */
385: status = ocfs2_mknod_locked(osb, dir, inode, dev,
386: &new_fe_bh, parent_fe_bh, handle,
387: inode_ac);
388: if (status < 0) {
389: mlog_errno(status);
390: goto leave;
391: }
392:
393: fe = (struct ocfs2_dinode *) new_fe_bh->b_data;
394: if (S_ISDIR(mode)) {
395: status = ocfs2_fill_new_dir(osb, handle, dir, inode,
396: new_fe_bh, data_ac, meta_ac);
397: if (status < 0) {
398: mlog_errno(status);
399: goto leave;
400: }
401:
402: status = ocfs2_journal_access_di(handle, INODE_CACHE(dir),
403: parent_fe_bh,
404: OCFS2_JOURNAL_ACCESS_WRITE);
405: if (status < 0) {
406: mlog_errno(status);
407: goto leave;
408: }
409: ocfs2_add_links_count(dirfe, 1);
410: ocfs2_journal_dirty(handle, parent_fe_bh);
411: inc_nlink(dir);
412: }
413:
414: status = ocfs2_init_acl(handle, inode, dir, new_fe_bh, parent_fe_bh,
415: meta_ac, data_ac);
416:
417: if (status < 0) {
418: mlog_errno(status);
419: goto roll_back;
420: }
421:
422: if (si.enable) {
423: status = ocfs2_init_security_set(handle, inode, new_fe_bh, &si,
424: meta_ac, data_ac);
425: if (status < 0) {
426: mlog_errno(status);
427: goto roll_back;
428: }
429: }
430:
431: /*
432: * Do this before adding the entry to the directory. We add
433: * also set d_op after success so that ->d_iput() will cleanup
434: * the dentry lock even if ocfs2_add_entry() fails below.
435: */
436: status = ocfs2_dentry_attach_lock(dentry, inode,
437: OCFS2_I(dir)->ip_blkno);
438: if (status) {
439: mlog_errno(status);
440: goto roll_back;
441: }
442:
443: dl = dentry->d_fsdata;
444:
445: status = ocfs2_add_entry(handle, dentry, inode,
446: OCFS2_I(inode)->ip_blkno, parent_fe_bh,
447: &lookup);
448: if (status < 0) {
449: mlog_errno(status);
450: goto roll_back;
451: }
452:
453: insert_inode_hash(inode);
454: d_instantiate(dentry, inode);
455: status = 0;
456:
457: roll_back:
458: if (status < 0 && S_ISDIR(mode)) {
459: ocfs2_add_links_count(dirfe, -1);
460: drop_nlink(dir);
461: }
462:
463: leave:
464: if (status < 0 && did_quota_inode)
465: dquot_free_inode(inode);
466: if (handle) {
467: if (status < 0 && fe)
468: ocfs2_set_links_count(fe, 0);
469: ocfs2_commit_trans(osb, handle);
470: }
471:
472: ocfs2_inode_unlock(dir, 1);
473: if (did_block_signals)
474: ocfs2_unblock_signals(&oldset);
475:
476: brelse(new_fe_bh);
477: brelse(parent_fe_bh);
478: kfree(si.value);
479:
480: ocfs2_free_dir_lookup_result(&lookup);
481:
482: if (inode_ac)
483: ocfs2_free_alloc_context(inode_ac);
484:
485: if (data_ac)
486: ocfs2_free_alloc_context(data_ac);
487:
488: if (meta_ac)
489: ocfs2_free_alloc_context(meta_ac);
490:
491: /*
492: * We should call iput after the i_rwsem of the bitmap been
493: * unlocked in ocfs2_free_alloc_context, or the
494: * ocfs2_delete_inode will mutex_lock again.
495: */
496: if ((status < 0) && inode) {
497: if (dl)
498: ocfs2_cleanup_add_entry_failure(osb, dentry, inode);
499:
500: OCFS2_I(inode)->ip_flags |= OCFS2_INODE_SKIP_ORPHAN_DIR;
501: clear_nlink(inode);
502: iput(inode);
503: }
504:
505: if (status)
506: mlog_errno(status);
507:
508: return status;
509: }
SourceFile:fs/ocfs2/namei.c]
|
| 26/2 |
2026/05/18 15:06 |
llm |
expert |
0m
Model:
Tokens:
input: 47138
output: 49
thoughts: 597
Thoughts: **ABBA Deadlock in ocfs2!**
Alright, let's break this down. I've found a nasty ABBA deadlock scenario within `ocfs2`. It's pretty clear: In `ocfs2_mknod`, specifically during directory creation, we have Path A. This begins by calling `ocfs2_reserve_clusters`, which goes through `ocfs2_reserve_cluster_bitmap_bits` and finally `ocfs2_reserve_suballoc_bits(GLOBAL_BITMAP_SYSTEM_INODE)`. Bingo, that takes `inode_lock(GLOBAL_BITMAP_SYSTEM_INODE)`. After that's done, the code continues and then calls `ocfs2_start_trans`, which grabs `sb_internal#2` and `&journal->j_trans_barrier`. So, Path A's lock acquisition order is `GLOBAL_BITMAP_SYSTEM_INODE` -> `sb_internal#2` -> `&journal->j_trans_barrier`.
Now, look at Path B, stemming from the `ocfs2_remove_inode` function during inode deletion. Here, we have the call to `ocfs2_free_dinode`, which in turn calls `ocfs2_free_suballoc_bits` and finally, `_ocfs2_reclaim_suballoc_to_main`. Crucially, `_ocfs2_reclaim_suballoc_to_main` *also* grabs the `inode_lock(main_bm_inode)` which is, you guessed it, `GLOBAL_BITMAP_SYSTEM_INODE`. Path B's lock acquisition order is thus `sb_internal#2` -> `&journal->j_trans_barrier` -> `GLOBAL_BITMAP_SYSTEM_INODE`.
See it? We have a textbook ABBA deadlock: Path A does A->B->C, Path B does B->C->A. `GLOBAL_BITMAP_SYSTEM_INODE` -> `sb_internal#2` is the order that causes the conflict.
This is not a theoretical exercise. This deadlock *will* occur. Anytime we create a new directory (that needs cluster allocation) and, concurrently, we delete an inode whose suballocator space needs to be reclaimed into the main bitmap, we are in trouble. This happens on normal filesystem operations like `mkdir`, `rmdir`, and `unlink`. I'm starting to think this happens every time `ocfs2_free_suballoc_bits` reclaims space, and I'm not sure if that is always into the main bitmap, but this is clearly where I need to look closer.
|
| 27/2 |
2026/05/18 15:06 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/ocfs2/suballoc.c IncludeLines:true Name:ocfs2_free_suballoc_bits]
Results: map[SourceCode:2918: int ocfs2_free_suballoc_bits(handle_t *handle,
2919: struct inode *alloc_inode,
2920: struct buffer_head *alloc_bh,
2921: unsigned int start_bit,
2922: u64 bg_blkno,
2923: unsigned int count)
2924: {
2925: return _ocfs2_free_suballoc_bits(handle, alloc_inode, alloc_bh,
2926: start_bit, bg_blkno, count, NULL);
2927: }
SourceFile:fs/ocfs2/suballoc.c]
|
| 28/2 |
2026/05/18 15:06 |
llm |
expert |
0m
Model:
Tokens:
input: 48545
output: 50
thoughts: 17
Thoughts: Okay, here's my interpretation of that thought process, assuming I'm an expert in file systems, particularly OCFS2:
**Diving into Suballocation Freed Bits**
Alright, time to dig in. I'm going to take a look at the `_ocfs2_free_suballoc_bits` function. This is critical for understanding and potentially debugging any issues with OCFS2's suballocation system. Knowing what's happening with these free bits is essential for diagnosing potential fragmentation, allocation problems, or inconsistencies in metadata. I need to understand how free blocks are tracked, and how the algorithm manages to assign blocks to requests. I hope this helps me to solve the underlying problem.
|
| 29/2 |
2026/05/18 15:06 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/ocfs2/suballoc.c IncludeLines:true Name:_ocfs2_free_suballoc_bits]
Results: map[SourceCode:2829: /*
2830: * expects the suballoc inode to already be locked.
2831: */
2832: static int _ocfs2_free_suballoc_bits(handle_t *handle,
2833: struct inode *alloc_inode,
2834: struct buffer_head *alloc_bh,
2835: unsigned int start_bit,
2836: u64 bg_blkno,
2837: unsigned int count,
2838: void (*undo_fn)(unsigned int bit,
2839: unsigned long *bitmap))
2840: {
2841: int idx, status = 0;
2842: u32 tmp_used;
2843: struct ocfs2_dinode *fe = (struct ocfs2_dinode *) alloc_bh->b_data;
2844: struct ocfs2_chain_list *cl = &fe->id2.i_chain;
2845: struct buffer_head *group_bh = NULL;
2846: struct ocfs2_group_desc *group;
2847: struct ocfs2_chain_rec *rec;
2848: __le16 old_bg_contig_free_bits = 0;
2849:
2850: /* The alloc_bh comes from ocfs2_free_dinode() or
2851: * ocfs2_free_clusters(). The callers have all locked the
2852: * allocator and gotten alloc_bh from the lock call. This
2853: * validates the dinode buffer. Any corruption that has happened
2854: * is a code bug. */
2855: BUG_ON(!OCFS2_IS_VALID_DINODE(fe));
2856: BUG_ON((count + start_bit) > ocfs2_bits_per_group(cl));
2857:
2858: trace_ocfs2_free_suballoc_bits(
2859: (unsigned long long)OCFS2_I(alloc_inode)->ip_blkno,
2860: (unsigned long long)bg_blkno,
2861: start_bit, count);
2862:
2863: status = ocfs2_read_group_descriptor(alloc_inode, fe, bg_blkno,
2864: &group_bh);
2865: if (status < 0) {
2866: mlog_errno(status);
2867: goto bail;
2868: }
2869: group = (struct ocfs2_group_desc *) group_bh->b_data;
2870:
2871: BUG_ON((count + start_bit) > le16_to_cpu(group->bg_bits));
2872:
2873: if (ocfs2_is_cluster_bitmap(alloc_inode))
2874: old_bg_contig_free_bits = group->bg_contig_free_bits;
2875: status = ocfs2_block_group_clear_bits(handle, alloc_inode,
2876: group, group_bh,
2877: start_bit, count, 0, undo_fn);
2878: if (status < 0) {
2879: mlog_errno(status);
2880: goto bail;
2881: }
2882:
2883: status = ocfs2_journal_access_di(handle, INODE_CACHE(alloc_inode),
2884: alloc_bh, OCFS2_JOURNAL_ACCESS_WRITE);
2885: if (status < 0) {
2886: mlog_errno(status);
2887: ocfs2_block_group_set_bits(handle, alloc_inode, group, group_bh,
2888: start_bit, count,
2889: le16_to_cpu(old_bg_contig_free_bits), 1);
2890: goto bail;
2891: }
2892:
2893: idx = le16_to_cpu(group->bg_chain);
2894: rec = &(cl->cl_recs[idx]);
2895:
2896: le32_add_cpu(&rec->c_free, count);
2897: tmp_used = le32_to_cpu(fe->id1.bitmap1.i_used);
2898: fe->id1.bitmap1.i_used = cpu_to_le32(tmp_used - count);
2899: ocfs2_journal_dirty(handle, alloc_bh);
2900:
2901: /*
2902: * Reclaim suballocator free space.
2903: * Bypass: global_bitmap, non empty rec, first rec in cl_recs[]
2904: */
2905: if (ocfs2_is_cluster_bitmap(alloc_inode) ||
2906: (le32_to_cpu(rec->c_free) != (le32_to_cpu(rec->c_total) - 1)) ||
2907: (le16_to_cpu(cl->cl_next_free_rec) == 1)) {
2908: goto bail;
2909: }
2910:
2911: _ocfs2_reclaim_suballoc_to_main(handle, alloc_inode, alloc_bh, group_bh);
2912:
2913: bail:
2914: brelse(group_bh);
2915: return status;
2916: }
SourceFile:fs/ocfs2/suballoc.c]
|
| 30/2 |
2026/05/18 15:06 |
llm |
expert |
0m
Model:
Tokens:
input: 50335
output: 48
thoughts: 1453
Thoughts: **Deadlock in OCFS2: A Deep Dive**
Okay, so here's what's happening. I've been looking at this `_ocfs2_reclaim_suballoc_to_main` function and it's called when a few specific conditions are met: it's not the cluster bitmap, the group is nearly empty (only the group descriptor itself remains), and it's not the first group in a chain. Effectively, this function reclaims space from a suballocator group, like the one used for inode allocation (`INODE_ALLOC_SYSTEM_INODE`), back to the main bitmap. It's a perfectly normal operation within the filesystem.
The scenario unfolds like this: an unprivileged user creates a bunch of directories, which triggers the allocation of a new inode group. Then, they delete those directories, and this empty group triggers `_ocfs2_reclaim_suballoc_to_main`. This reclamation process acquires the `GLOBAL_BITMAP_SYSTEM_INODE` while holding `sb_internal#2` and `&journal->j_trans_barrier`.
At the same time, if *another* process (or the same user, in another thread) creates *another* directory that requires a new cluster group, it takes `GLOBAL_BITMAP_SYSTEM_INODE` and then *starts a transaction* which takes `sb_internal#2` and `&journal->j_trans_barrier`.
Bingo! Classic ABBA deadlock! This is a deadlock that can happen on a regular OCFS2 filesystem, triggered by an unprivileged user.
Hang on⦠does the user even need any special privileges to trigger this? I was expecting `CAP_SYS_ADMIN` or something, but no! Nope, they just need to be able to create and delete directories on an OCFS2 filesystem! If the system has an OCFS2 filesystem mounted, and the user has write access to a directory, they can trigger this.
So, is this "Accessible From Unprivileged Processes"? Yes, absolutely. If they have write access to an OCFS2 mount, they can trigger this bug.
Now, the prompt⦠wait, it says the bug can be reproduced with a malicious image. But the *bug itself* is a *generic deadlock* in OCFS2 that can happen on a normal filesystem! We need to verify this!
Okay, let's trace the execution paths. Path A: `ocfs2_mknod` -> `ocfs2_reserve_clusters` -> `ocfs2_reserve_cluster_bitmap_bits` -> `ocfs2_reserve_suballoc_bits(GLOBAL_BITMAP_SYSTEM_INODE)` -> `inode_lock(GLOBAL_BITMAP_SYSTEM_INODE)` -> `ocfs2_start_trans` -> `sb_internal#2` -> `&journal->j_trans_barrier`.
Path B: `ocfs2_remove_inode` -> `ocfs2_start_trans` -> `sb_internal#2` -> `&journal->j_trans_barrier` -> `ocfs2_free_dinode` -> `ocfs2_free_suballoc_bits` -> `_ocfs2_free_suballoc_bits` -> `_ocfs2_reclaim_suballoc_to_main` -> `inode_lock(GLOBAL_BITMAP_SYSTEM_INODE)`.
Is there any condition that could prevent the deadlock in a normal filesystem?
In Path A, `ocfs2_reserve_cluster_bitmap_bits` calls `ocfs2_reserve_suballoc_bits` with `ALLOC_NEW_GROUP`.
Aha! Wait⦠`ocfs2_reserve_suballoc_bits` for `GLOBAL_BITMAP_SYSTEM_INODE` returns `-ENOSPC` if the desired bits exceed the available free bits. And it never calls `ocfs2_block_group_alloc`. Let's re-read the code for `ocfs2_reserve_suballoc_bits`.
```c
if (bits_wanted > free_bits) {
/* cluster bitmap never grows */
if (ocfs2_is_cluster_bitmap(alloc_inode)) {
trace_ocfs2_reserve_suballoc_bits_nospc(bits_wanted,
free_bits);
status = -ENOSPC;
goto bail;
}
```
If it returns `-ENOSPC`, it goes to `bail`, which unlocks the inode. Wait... it doesn't unlock the inode! It just returns `-ENOSPC`!
Wait a second. I need to make sure I am reading this correctly! The code does *not* unlock the inode if it returns `-EN
|
| 31/2 |
2026/05/18 15:07 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/ocfs2/suballoc.c IncludeLines:true Name:ocfs2_free_alloc_context]
Results: map[SourceCode: 143: void ocfs2_free_alloc_context(struct ocfs2_alloc_context *ac)
144: {
145: ocfs2_free_ac_resource(ac);
146: kfree(ac);
147: }
SourceFile:fs/ocfs2/suballoc.c]
|
| 32/2 |
2026/05/18 15:07 |
llm |
expert |
0m
Model:
Tokens:
input: 52970
output: 48
thoughts: 15
Thoughts: Okay, here's my attempt at summarizing that thought process, tailored for an expert audience:
**Diving into `ocfs2_free_ac_resource`**
Alright, time to dive into `ocfs2_free_ac_resource`. Let's see what's going on under the hood here. I need to refresh my memory on the access control resource freeing mechanism within OCFS2. What are the key data structures involved, and what's the typical flow of operations? I'm particularly interested in potential race conditions and any areas that are prone to errors, such as memory management or lock acquisition/release sequencing. I'll need to consider how this function interacts with the broader context of the access control system. Also, I'll need to check how it interfaces with the resource manager. Time to trace the execution path and identify any potential gotchas. I need to make sure I understand the error handling in case of issues like resource not found or corruption. Let's see if there are any obvious inefficiencies or optimizations that could be made.
|
| 33/2 |
2026/05/18 15:07 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/ocfs2/suballoc.c IncludeLines:true Name:ocfs2_free_ac_resource]
Results: map[SourceCode: 123: void ocfs2_free_ac_resource(struct ocfs2_alloc_context *ac)
124: {
125: struct inode *inode = ac->ac_inode;
126:
127: if (inode) {
128: if (ac->ac_which != OCFS2_AC_USE_LOCAL)
129: ocfs2_inode_unlock(inode, 1);
130:
131: inode_unlock(inode);
132:
133: iput(inode);
134: ac->ac_inode = NULL;
135: }
136: brelse(ac->ac_bh);
137: ac->ac_bh = NULL;
138: ac->ac_resv = NULL;
139: kfree(ac->ac_find_loc_priv);
140: ac->ac_find_loc_priv = NULL;
141: }
SourceFile:fs/ocfs2/suballoc.c]
|
| 34/2 |
2026/05/18 15:07 |
llm |
expert |
1m
Model:
Tokens:
input: 53565
output: 45
thoughts: 2199
Thoughts: **Analysis of OCFS2 Deadlock Vulnerability**
Okay, let's break this down. It seems the core issue revolves around a potential lock ordering inversion within the OCFS2 file system. My thought process is as follows:
First, I observe that `ocfs2_free_ac_resource` releases the inode lock, so that part of the resource allocation flow is not causing the problem. However, the subsequent allocation and transaction startup steps, especially when combined with the bitmap management, raise red flags. `ocfs2_reserve_suballoc_bits` potentially locks `GLOBAL_BITMAP_SYSTEM_INODE`. Subsequent calls to `ocfs2_start_trans` grabs a transaction barrier, and the underlying `sb_internal` lock. This setup is Path A, which happens on every cluster allocation.
The initial concern is that this lock acquisition pattern appears potentially deadlocking. But, the filesystem doesn't instantly die because another path `_ocfs2_reclaim_suballoc_to_main` can happen when a suballocator group becomes empty. This is Path B, and it locks the `GLOBAL_BITMAP_SYSTEM_INODE` *after* starting a transaction. This is a crucial distinction.
Now I see it. This is a classic ABBA deadlock. Path A (allocation) locks `GLOBAL_BITMAP_SYSTEM_INODE` and attempts to start a transaction. Path B (reclamation) starts a transaction and then tries to lock `GLOBAL_BITMAP_SYSTEM_INODE`. The lock order is inverted in these two paths.
The key question is whether this is a known issue. The lockdep warning confirms this circular dependency! That's a strong indicator.
Next, I need to assess its exploitability. Can an unprivileged user trigger this? Yes, if they have write access to an OCFS2 filesystem, they can create and delete files/directories. Path A is triggered by creating files, and Path B is triggered by removing the last inode in a group, and the groups reclaim back to the main bitmap. Therefore, creating and deleting files concurrently can trigger this.
The question of "Accessible From Unprivileged Processes" hinges on the ability of an unprivileged user to reach this bug. Assuming a user has write access to an *already mounted* OCFS2 filesystem, the answer is unequivocally yes. This is a standard assumption for filesystem DoS vulnerabilities: if a normal user on a filesystem can cause a DoS by write and delete, it's considered accessible. The fact that OCFS2 is not a default filesystem is secondary; the *type* of mount is the relevant factor here.
The syzkaller reproducer mounts a crafted image. This might seem specific, but it's important to remember that such crafted images are the tools syzkaller uses for testing. The "malicious" part isn't a requirement; the specific setup could increase the chances of the bug surfacing, but any writeable mount can do this. The crafted image might create a situation where an inode group is one inode away from being empty, thus increasing the chance for reclamation. But it's easily replicable on any writeable mount.
I should double-check the lock order again. `_ocfs2_reclaim_suballoc_to_main` clearly shows that transaction locks are acquired *before* acquiring the `GLOBAL_BITMAP_SYSTEM_INODE` lock, representing the lock inversion.
Since `inode_lock` is a mutex, the deadlock is guaranteed. Path A holds the first lock, and awaits the transaction barrier. Path B has that lock and awaits the first.
My determination:
* **Exploitable:** False (it's a deadlock)
* **DenialOfService:** True
* **FilesystemTrigger:** True (can be triggered by mounting a normal or malicious image, as syzkaller did)
* **NetworkTrigger:** False
* **PeripheralTrigger:** False
* **RemoteTrigger:** False
* **Unprivileged:** True
* **UserNamespace:** False
* **VMGuestTrigger:** False
* **VMHostTrigger:** False
Let me reiterate, even if OCFS2 isn't commonly mounted, if a system administrator provides the mount and write access, an unprivileged user can trigger this.
I'll review the lockdep warning to confirm the lock ordering: The warning clearly indicates `inode_lock` (on the system inode) is acquired *after* transaction locks, and that's precisely the inversion. However, checking `ocfs2_start_trans`, it looks like the lock is a shared read lock, so I should investigate that further. Even if both paths use a shared read lock for `&journal->j_trans_barrier` they can still both attempt to acquire it, but that doesn't mean they block
|
| 35/2 |
2026/05/18 15:08 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/ocfs2/journal.c IncludeLines:true Name:ocfs2_start_trans]
Results: map[SourceCode: 353: handle_t *ocfs2_start_trans(struct ocfs2_super *osb, int max_buffs)
354: {
355: journal_t *journal = osb->journal->j_journal;
356: handle_t *handle;
357:
358: BUG_ON(!osb || !osb->journal->j_journal);
359:
360: if (ocfs2_is_hard_readonly(osb))
361: return ERR_PTR(-EROFS);
362:
363: BUG_ON(osb->journal->j_state == OCFS2_JOURNAL_FREE);
364: BUG_ON(max_buffs <= 0);
365:
366: /* Nested transaction? Just return the handle... */
367: if (journal_current_handle())
368: return jbd2_journal_start(journal, max_buffs);
369:
370: sb_start_intwrite(osb->sb);
371:
372: down_read(&osb->journal->j_trans_barrier);
373:
374: handle = jbd2_journal_start(journal, max_buffs);
375: if (IS_ERR(handle)) {
376: up_read(&osb->journal->j_trans_barrier);
377: sb_end_intwrite(osb->sb);
378:
379: mlog_errno(PTR_ERR(handle));
380:
381: if (is_journal_aborted(journal)) {
382: ocfs2_abort(osb->sb, "Detected aborted journal\n");
383: handle = ERR_PTR(-EROFS);
384: }
385: } else {
386: if (!ocfs2_mount_local(osb))
387: atomic_inc(&(osb->journal->j_num_trans));
388: }
389:
390: return handle;
391: }
SourceFile:fs/ocfs2/journal.c]
|
| 36/2 |
2026/05/18 15:08 |
llm |
expert |
0m
Model:
Tokens:
input: 57465
output: 66
thoughts: 4153
Thoughts: **Analysis of an OCFS2 Deadlock Vulnerability**
My thinking started with a lockdep report indicating a potential deadlock within the OCFS2 filesystem, specifically concerning the interaction between read and write locks on the superblock and inode locks. I realized that the OCFS2 code uses `sb_start_intwrite`, which takes a read lock, and the lockdep report seemed to highlight a situation where this read lock on `sb_internal#2` could create a circular dependency with an inode write lock (`inode_lock`). My initial thought was, since the read locks shouldn't block, how can this be a deadlock?
Diving deeper, the issue arose because `sb_internal#2` is a `percpu_rw_semaphore`. This meant the presence of a writer (e.g., `sync` or `freeze`) could block subsequent readers, which lockdep was clearly flagging. The code path I was examining, specifically the interaction between allocating new clusters/inodes (Path A) and reclaiming inode groups (Path B), was leading to a potential 3-way deadlock.
Path A, when allocating clusters for a new file or directory, takes a write lock on the `GLOBAL_BITMAP_SYSTEM_INODE` inode. This call eventually leads to starting a transaction, which requires `ocfs2_start_trans` and thus acquiring read locks on both the superblock (`sb_internal#2`) and a journal barrier (`&journal->j_trans_barrier`).
Path B, occurring during directory deletion or file deletion to the point of freeing the inode group, involves starting a transaction (which takes the read locks) and subsequently obtaining a write lock on `GLOBAL_BITMAP_SYSTEM_INODE`. The key, I realized, was that in one path, the inode lock could be held *before* the transaction was started, and in the other, the transaction could be started *before* the inode lock. The reverse order in the reclaim path constitutes a lock inversion.
This is where the deadlock occurs. If Path A holds the `inode_lock`, and a writer is blocked on `sb_internal#2` (because Path B already holds a read lock, and the writer comes in before the read lock is released), then Path B blocks on the write `inode_lock`, resulting in the lock inversion (ABBA).
I confirmed that this is a fully unprivileged deadlock using both normal operation and a syzkaller reproducer. I examined the syzkaller reproducer and confirmed it does trigger the lock inversion during `mkdirat` and deletion that the syz-executor does, even though the `rmdir` is not explicitly called in the reproducer, but in the cleanup function of the test harness. Because a normal user with permissions to create and remove files/directories can trigger the condition, this is a true Denial-of-Service vulnerability and exploitable by unprivileged users on a standard OCFS2 filesystem. The dimensions are clear: Exploitable: False (deadlock), DenialOfService: True, FilesystemTrigger: True, Unprivileged: True, NetworkTrigger, RemoteTrigger, VMGuestTrigger, VMHostTrigger, UserNamespace and PeripheralTrigger: False.
|
| 37/2 |
2026/05/18 15:09 |
tool |
set-results |
0m
Args: map[DenialOfService:true Exploitable:false FilesystemTrigger:true NetworkTrigger:false PeripheralTrigger:false RemoteTrigger:false Unprivileged:true UserNamespace:false VMGuestTrigger:false VMHostTrigger:false]
Results: map[DenialOfService:true Exploitable:false FilesystemTrigger:true NetworkTrigger:false PeripheralTrigger:false RemoteTrigger:false Unprivileged:true UserNamespace:false VMGuestTrigger:false VMHostTrigger:false]
|
| 38/2 |
2026/05/18 15:09 |
llm |
expert |
0m
Model:
Tokens:
input: 62416
output: 929
thoughts: 791
Thoughts: **Reasoning: ABBA Deadlock in ocfs2 Filesystem**
Okay, the results are in, and now it's time to solidify the reasoning behind this ocfs2 filesystem bug. It's a textbook ABBA deadlock, a classic circular locking dependency. The lockdep warning nails it down to a few critical locks: the global bitmap inode's `i_rwsem`, the `s_writers.rw_sem` (identified as `sb_internal#2`) used for `SB_FREEZE_FS` via `sb_start_intwrite`, and the journal transaction barrier rwsem (`&journal->j_trans_barrier`).
The deadlock manifests in two distinct code paths:
* **Path A (cluster allocation):** When allocating clusters, say during a `mkdir` operation, ocfs2 might resort to the global bitmap if the local allocator is depleted. This leads to `ocfs2_reserve_cluster_bitmap_bits` taking the global bitmap inode's `i_rwsem`. Subsequently, a journal transaction is started via `ocfs2_start_trans`, which grabs `sb_internal#2` (read) and the journal barrier (`&journal->j_trans_barrier`) (read). The lock order here is the critical sequence: `GLOBAL_BITMAP_SYSTEM_INODE` -> `sb_internal#2` -> `&journal->j_trans_barrier`.
* **Path B (inode freeing):** Conversely, if an inode is being deleted, like during an `rmdir` or `unlink`, `ocfs2_remove_inode` starts a transaction, getting `sb_internal#2` (read) and `&journal->j_trans_barrier` (read). If this deleted inode was the last one in its group, the group becomes empty and needs its space reclaimed to the main bitmap by `_ocfs2_reclaim_suballoc_to_main`. This step then grabs the global bitmap inode's `i_rwsem`. The lock order reverses: `sb_internal#2` -> `&journal->j_trans_barrier` -> `GLOBAL_BITMAP_SYSTEM_INODE`.
The problem is clear. Although these intermediate locks are acquired for read access in both paths, `sb_internal#2` and `&journal->j_trans_barrier` are `rw_semaphore`s. If a third thread tries to acquire them for write (e.g., during a filesystem freeze or a journal commit), it will block, waiting for the read locks to be released. Further read lock attempts will also block, completing the deadlock cycle.
In terms of impact, it's not an exploitable vulnerability for code execution. It's a deadlock, so no memory corruption or privilege escalation. However, it's a definite denial-of-service, as operations will hang. It can be maliciously triggered by crafting an ocfs2 image designed to hit this condition, like a filesystem with a specific inode group configuration and full local allocator. An unprivileged user with write access on a mounted filesystem can trigger the deadlock by concurrently creating and deleting directories/files. This won't work in user namespaces because the filesystem doesn't have the `FS_USERNS_MOUNT` flag.
|
| 39/1 |
2026/05/18 15:10 |
action |
format-explanation |
0m
Results: map[Explanation:**Analysis of the Bug Report**
The bug report indicates a "possible circular locking dependency detected" (an
ABBA deadlock) in the `ocfs2` filesystem. The lockdep warning highlights a lock
inversion between the global bitmap inode lock and the transaction barrier
locks.
**Detailed Mechanism:**
The deadlock involves the following locks:
1. `&ocfs2_sysfile_lock_key[GLOBAL_BITMAP_SYSTEM_INODE]` (the `i_rwsem` mutex of
the global bitmap inode)
2. `sb_internal#2` (the `s_writers.rw_sem` for `SB_FREEZE_FS`, taken via
`sb_start_intwrite`)
3. `&journal->j_trans_barrier` (the journal transaction barrier rwsem)
There are two conflicting code paths in `ocfs2` that acquire these locks in
reverse order:
* **Path A (Cluster Allocation - e.g., `mkdir`, `fallocate`, or `write`):**
When allocating clusters, if the local allocator is full or disabled, `ocfs2`
falls back to the global bitmap. It calls
`ocfs2_reserve_cluster_bitmap_bits()`, which acquires the `i_rwsem` of the
`GLOBAL_BITMAP_SYSTEM_INODE`. With this lock held, it subsequently starts a
journal transaction via `ocfs2_start_trans()`, which acquires `sb_internal#2`
(read) and `&journal->j_trans_barrier` (read).
*Lock Order:* `GLOBAL_BITMAP_SYSTEM_INODE` -> `sb_internal#2` ->
`&journal->j_trans_barrier`
* **Path B (Inode Deletion - e.g., `rmdir` or `unlink`):**
When an inode is deleted, `ocfs2_remove_inode()` first starts a transaction,
acquiring `sb_internal#2` (read) and `&journal->j_trans_barrier` (read). It
then proceeds to free the inode. If this inode happens to be the last
allocated inode in its suballocator group, the group becomes empty. `ocfs2`
then attempts to reclaim the group's space back to the main bitmap by calling
`_ocfs2_reclaim_suballoc_to_main()`. This function acquires the `i_rwsem` of
the `GLOBAL_BITMAP_SYSTEM_INODE`.
*Lock Order:* `sb_internal#2` -> `&journal->j_trans_barrier` ->
`GLOBAL_BITMAP_SYSTEM_INODE`
Although `sb_internal#2` and `&journal->j_trans_barrier` are acquired as read
locks in both paths, they are `rw_semaphore`s. If a third thread attempts to
acquire either of them for writing (e.g., during a filesystem freeze or a
journal commit), it will block waiting for the read locks to be released. Any
subsequent read lock attempts will then queue up behind the writer, completing
the 3-way deadlock cycle.
**Security Impact:**
* **Exploitable:** No. This is a pure concurrency logic bug (deadlock) and does
not result in memory corruption, out-of-bounds accesses, or privilege
escalation.
* **Denial Of Service:** Yes. Triggering the deadlock will hang the threads
involved and eventually hang the entire filesystem and any tasks attempting to
access it, resulting in a local Denial of Service (DoS).
* **Malicious Filesystem Trigger:** Yes. The syzkaller reproducer triggers this
by mounting a maliciously crafted `ocfs2` image designed to perfectly align the
conditions (e.g., an inode group with exactly one allocated inode and a full
local allocator) and then performing basic operations like `mkdirat`.
* **Accessible From Unprivileged Processes:** Yes. If a standard `ocfs2`
filesystem is mounted and an unprivileged user has write access to a directory
within it, they can trigger this deadlock by concurrently creating and deleting
directories/files to hit Path A and Path B simultaneously.
* **Accessible From User Namespaces:** No. The `ocfs2` filesystem lacks the
`FS_USERNS_MOUNT` flag, meaning it cannot be mounted by an unprivileged user
inside a user namespace. It requires `CAP_SYS_ADMIN` in the initial namespace to
mount.]
|