CVE-2024-46734

In the Linux kernel, the following vulnerability has been resolved: btrfs: fix race between direct IO write and fsync when using same fd If we have 2 threads that are using the same file descriptor and one of them is doing direct IO writes while the other is doing fsync, we have a race where we can end up either: 1) Attempt a fsync without holding the inode's lock, triggering an assertion failures when assertions are enabled; 2) Do an invalid memory access from the fsync task because the file private points to memory allocated on stack by the direct IO task and it may be used by the fsync task after the stack was destroyed. The race happens like this: 1) A user space program opens a file descriptor with O_DIRECT; 2) The program spawns 2 threads using libpthread for example; 3) One of the threads uses the file descriptor to do direct IO writes, while the other calls fsync using the same file descriptor. 4) Call task A the thread doing direct IO writes and task B the thread doing fsyncs; 5) Task A does a direct IO write, and at btrfs_direct_write() sets the file's private to an on stack allocated private with the member 'fsync_skip_inode_lock' set to true; 6) Task B enters btrfs_sync_file() and sees that there's a private structure associated to the file which has 'fsync_skip_inode_lock' set to true, so it skips locking the inode's VFS lock; 7) Task A completes the direct IO write, and resets the file's private to NULL since it had no prior private and our private was stack allocated. Then it unlocks the inode's VFS lock; 8) Task B enters btrfs_get_ordered_extents_for_logging(), then the assertion that checks the inode's VFS lock is held fails, since task B never locked it and task A has already unlocked it. The stack trace produced is the following: assertion failed: inode_is_locked(&inode->vfs_inode), in fs/btrfs/ordered-data.c:983 ------------[ cut here ]------------ kernel BUG at fs/btrfs/ordered-data.c:983! Oops: invalid opcode: 0000 [#1] PREEMPT SMP PTI CPU: 9 PID: 5072 Comm: worker Tainted: G U OE 6.10.5-1-default #1 openSUSE Tumbleweed 69f48d427608e1c09e60ea24c6c55e2ca1b049e8 Hardware name: Acer Predator PH315-52/Covini_CFS, BIOS V1.12 07/28/2020 RIP: 0010:btrfs_get_ordered_extents_for_logging.cold+0x1f/0x42 [btrfs] Code: 50 d6 86 c0 e8 (...) RSP: 0018:ffff9e4a03dcfc78 EFLAGS: 00010246 RAX: 0000000000000054 RBX: ffff9078a9868e98 RCX: 0000000000000000 RDX: 0000000000000000 RSI: ffff907dce4a7800 RDI: ffff907dce4a7800 RBP: ffff907805518800 R08: 0000000000000000 R09: ffff9e4a03dcfb38 R10: ffff9e4a03dcfb30 R11: 0000000000000003 R12: ffff907684ae7800 R13: 0000000000000001 R14: ffff90774646b600 R15: 0000000000000000 FS: 00007f04b96006c0(0000) GS:ffff907dce480000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007f32acbfc000 CR3: 00000001fd4fa005 CR4: 00000000003726f0 Call Trace: <TASK> ? __die_body.cold+0x14/0x24 ? die+0x2e/0x50 ? do_trap+0xca/0x110 ? do_error_trap+0x6a/0x90 ? btrfs_get_ordered_extents_for_logging.cold+0x1f/0x42 [btrfs bb26272d49b4cdc847cf3f7faadd459b62caee9a] ? exc_invalid_op+0x50/0x70 ? btrfs_get_ordered_extents_for_logging.cold+0x1f/0x42 [btrfs bb26272d49b4cdc847cf3f7faadd459b62caee9a] ? asm_exc_invalid_op+0x1a/0x20 ? btrfs_get_ordered_extents_for_logging.cold+0x1f/0x42 [btrfs bb26272d49b4cdc847cf3f7faadd459b62caee9a] ? btrfs_get_ordered_extents_for_logging.cold+0x1f/0x42 [btrfs bb26272d49b4cdc847cf3f7faadd459b62caee9a] btrfs_sync_file+0x21a/0x4d0 [btrfs bb26272d49b4cdc847cf3f7faadd459b62caee9a] ? __seccomp_filter+0x31d/0x4f0 __x64_sys_fdatasync+0x4f/0x90 do_syscall_64+0x82/0x160 ? do_futex+0xcb/0x190 ? __x64_sys_futex+0x10e/0x1d0 ? switch_fpu_return+0x4f/0xd0 ? syscall_exit_to_user_mode+0x72/0x220 ? do_syscall_64+0x8e/0x160 ? syscall_exit_to_user_mod ---truncated---
Configurations

Configuration 1 (hide)

OR cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:*
cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:*
cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:*
cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:*
cpe:2.3:o:linux:linux_kernel:6.11:rc2:*:*:*:*:*:*
cpe:2.3:o:linux:linux_kernel:6.11:rc3:*:*:*:*:*:*
cpe:2.3:o:linux:linux_kernel:6.11:rc4:*:*:*:*:*:*
cpe:2.3:o:linux:linux_kernel:6.11:rc5:*:*:*:*:*:*
cpe:2.3:o:linux:linux_kernel:6.11:rc6:*:*:*:*:*:*

History

19 Sep 2025, 18:52

Type Values Removed Values Added
CPE cpe:2.3:o:linux:linux_kernel:6.11:rc5:*:*:*:*:*:*
cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:*
cpe:2.3:o:linux:linux_kernel:6.11:rc6:*:*:*:*:*:*
cpe:2.3:o:linux:linux_kernel:6.11:rc4:*:*:*:*:*:*
cpe:2.3:o:linux:linux_kernel:6.11:rc3:*:*:*:*:*:*
cpe:2.3:o:linux:linux_kernel:6.11:rc2:*:*:*:*:*:*
First Time Linux
Linux linux Kernel
References () https://git.kernel.org/stable/c/01681aa609b5f110502f56c4e3b2938efcf4a5bc - () https://git.kernel.org/stable/c/01681aa609b5f110502f56c4e3b2938efcf4a5bc - Patch
References () https://git.kernel.org/stable/c/7b5595f33c3c273613b590892a578d78186bb400 - () https://git.kernel.org/stable/c/7b5595f33c3c273613b590892a578d78186bb400 - Patch
References () https://git.kernel.org/stable/c/cd3087582e4fa36e89be4e6f859e75a4400292b4 - () https://git.kernel.org/stable/c/cd3087582e4fa36e89be4e6f859e75a4400292b4 - Patch
References () https://git.kernel.org/stable/c/cd9253c23aedd61eb5ff11f37a36247cd46faf86 - () https://git.kernel.org/stable/c/cd9253c23aedd61eb5ff11f37a36247cd46faf86 - Patch
References () https://git.kernel.org/stable/c/d116a0b0e02f395cedfb8c725bd67480aa7c428c - () https://git.kernel.org/stable/c/d116a0b0e02f395cedfb8c725bd67480aa7c428c - Patch
CWE CWE-362
CVSS v2 : unknown
v3 : unknown
v2 : unknown
v3 : 4.7

20 Sep 2024, 12:30

Type Values Removed Values Added
Summary
  • (es) En el kernel de Linux, se ha resuelto la siguiente vulnerabilidad: btrfs: arregla la ejecución entre la escritura de E/S directa y fsync cuando se usa el mismo fd Si tenemos 2 subprocesos que usan el mismo descriptor de archivo y uno de ellos está haciendo escrituras de E/S directas mientras que el otro está haciendo fsync, tenemos una ejecución en la que podemos terminar: 1) Intentar un fsync sin mantener el bloqueo del inodo, lo que desencadena fallas de aserción cuando las aserciones están habilitadas; 2) Hacer un acceso a memoria no válido desde la tarea fsync porque el archivo privado apunta a la memoria asignada en la pila por la tarea de E/S directa y puede ser utilizada por la tarea fsync después de que la pila se haya destruido. La ejecución sucede así: 1) Un programa de espacio de usuario abre un descriptor de archivo con O_DIRECT; 2) El programa genera 2 subprocesos usando libpthread, por ejemplo; 3) Uno de los subprocesos usa el descriptor de archivo para hacer escrituras de E/S directas, mientras que el otro llama a fsync usando el mismo descriptor de archivo. 4) Llama a la tarea A, el hilo que realiza las escrituras de E/S directas, y a la tarea B, el hilo que realiza las fsyncs; 5) La tarea A realiza una escritura de E/S directa y, en btrfs_direct_write(), establece el privado del archivo en un privado asignado en la pila con el miembro 'fsync_skip_inode_lock' establecido en verdadero; 6) La tarea B ingresa a btrfs_sync_file() y ve que hay una estructura privada asociada al archivo que tiene 'fsync_skip_inode_lock' establecido en verdadero, por lo que omite el bloqueo del bloqueo VFS del inodo; 7) La tarea A completa la escritura de E/S directa y restablece el privado del archivo a NULL, ya que no tenía ningún privado anterior y nuestro privado estaba asignado en la pila. Luego, desbloquea el bloqueo VFS del inodo; 8) La tarea B ingresa a btrfs_get_ordered_extents_for_logging(), luego la aserción que verifica que el bloqueo VFS del inodo se mantenga falla, ya que la tarea B nunca lo bloqueó y la tarea A ya lo desbloqueó. El seguimiento de la pila producido es el siguiente: aserción fallida: inode_is_locked(&amp;inode-&gt;vfs_inode), en fs/btrfs/ordered-data.c:983 ------------[ corte aquí ]------------ ¡ERROR del kernel en fs/btrfs/ordered-data.c:983! Ups: código de operación no válido: 0000 [#1] PREEMPT SMP PTI CPU: 9 PID: 5072 Comm: worker Contaminado: GU OE 6.10.5-1-default #1 openSUSE Tumbleweed 69f48d427608e1c09e60ea24c6c55e2ca1b049e8 Nombre del hardware: Acer Predator PH315-52/Covini_CFS, BIOS V1.12 28/07/2020 RIP: 0010:btrfs_get_ordered_extents_for_logging.cold+0x1f/0x42 [btrfs] Código: 50 d6 86 c0 e8 (...) RSP: 0018:ffff9e4a03dcfc78 EFLAGS: 00010246 RAX: 0000000000000054 RBX: ffff9078a9868e98 RCX: 0000000000000000 RDX: 0000000000000000 RSI: ffff907dce4a7800 RDI: ffff907dce4a7800 RBP: ffff907805518800 R08: 0000000000000000 R09: ffff9e4a03dcfb38 R10: ffff9e4a03dcfb30 R11: 0000000000000003 R12: ffff907684ae7800 R13: 0000000000000001 R14: ffff90774646b600 R15: 0000000000000000 FS: 00007f04b96006c0(0000) GS:ffff907dce480000(0000) knlGS:000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007f32acbfc000 CR3: 00000001fd4fa005 CR4: 00000000003726f0 Seguimiento de llamadas: ? btrfs_obtener_extensiones_ordenadas_para_registro.cold+0x1f/0x42 [btrfs bb26272d49b4cdc847cf3f7faadd459b62caee9a] ? exc_op_inválida+0x50/0x70 ? btrfs_obtener_extensiones_ordenadas_para_registro.cold+0x1f/0x42 [btrfs bb26272d49b4cdc847cf3f7faadd459b62caee9a] ? btrfs_obtener_extensiones_ordenadas_para_registro.cold+0x1f/0x42 [btrfs bb26272d49b4cdc847cf3f7faadd459b62caee9a] btrfs_archivo_de_sincronización+0x21a/0x4d0 [btrfs bb26272d49b4cdc847cf3f7faadd459b62caee9a] ? __seccomp_filter+0x31d/0x4f0 __x64_sys_fdatasync+0x4f/0x90 do_syscall_64+0x82/0x160 ? do_futex+0xcb/0x190 ? __x64_sys_futex+0x10e/0x1d0 ? switch_fpu_return+0x4f/0xd0 ? syscall_salir_al_modo_usuario+0x72/0x220 ? do_syscall_64+0x8e/0x160 ? syscall_salir_al_modo_usuario ---truncado---

18 Sep 2024, 08:15

Type Values Removed Values Added
New CVE

Information

Published : 2024-09-18 08:15

Updated : 2025-09-19 18:52


NVD link : CVE-2024-46734

Mitre link : CVE-2024-46734

CVE.ORG link : CVE-2024-46734


JSON object : View

Products Affected

linux

  • linux_kernel
CWE
CWE-362

Concurrent Execution using Shared Resource with Improper Synchronization ('Race Condition')