CVE-2024-47741: btrfs: fix race setting file private on concurrent lseek using same fd
In the Linux kernel, the following vulnerability has been resolved:
btrfs: fix race setting file private on concurrent lseek using same fd
When doing concurrent lseek(2) system calls against the same file descriptor, using multiple threads belonging to the same process, we have a short time window where a race happens and can result in a memory leak.
The race happens like this:
1) A program opens a file descriptor for a file and then spawns two threads (with the pthreads library for example), lets call them task A and task B;
2) Task A calls lseek with SEEKDATA or SEEKHOLE and ends up at file.c:finddesiredextent() while holding a read lock on the inode;
3) At the start of finddesiredextent(), it extracts the file's privatedata pointer into a local variable named 'private', which has a value of NULL;
4) Task B also calls lseek with SEEKDATA or SEEKHOLE, locks the inode in shared mode and enters file.c:finddesiredextent(), where it also extracts file->privatedata into its local variable 'private', which has a NULL value;
5) Because it saw a NULL file private, task A allocates a private structure and assigns to the file structure;
6) Task B also saw a NULL file private so it also allocates its own file private and then assigns it to the same file structure, since both tasks are using the same file descriptor.
At this point we leak the private structure allocated by task A.
Besides the memory leak, there's also the detail that both tasks end up using the same cached state record in the private structure (struct btrfsfileprivate::llseekcachedstate), which can result in a use-after-free problem since one task can free it while the other is still using it (only one task took a reference count on it). Also, sharing the cached state is not a good idea since it could result in incorrect results in the future - right now it should not be a problem because it end ups being used only in extent-io-tree.c:countrangebits() where we do range validation before using the cached state.
Fix this by protecting the private assignment and check of a file while holding the inode's spinlock and keep track of the task that allocated the private, so that it's used only by that task in order to prevent user-after-free issues with the cached state record as well as potentially using it incorrectly in the future.
Other sources
This CVE was automatically created from a reference found in an email or other text. If you are reading this, then this CVE entry is probably erroneous, since this text should be replaced by the official CVE description automatically.
— Launchpad
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade
debian/linuxto a version that resolves this vulnerability.Fixed in 5.10.223-1Fixed in 5.10.234-1Fixed in 6.1.129-1Fixed in 6.1.135-1Fixed in 6.12.25-1Fixed in 6.12.27-1
Event History
Frequently Asked Questions
What is the severity of CVE-2024-47741?
CVE-2024-47741 is categorized as a medium severity vulnerability in the Linux kernel.
How do I fix CVE-2024-47741?
To fix CVE-2024-47741, update the Linux kernel to a version that includes the security fix, specifically above 6.6.54, or between 6.7 and 6.10.13, or between 6.11 and 6.11.2.
Which Linux kernel versions are affected by CVE-2024-47741?
CVE-2024-47741 affects Linux kernel versions between 6.2 and 6.6.54, between 6.7 and 6.10.13, and between 6.11 and 6.11.2.
What does CVE-2024-47741 affect in the Linux kernel?
CVE-2024-47741 affects the btrfs filesystem by introducing a race condition during concurrent lseek system calls on the same file descriptor.
Is CVE-2024-47741 a local or remote vulnerability?
CVE-2024-47741 is considered a local vulnerability as it requires multiple threads belonging to the same process to exploit.