Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D176E1E892 for ; Mon, 29 Jul 2024 14:58:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722265098; cv=none; b=siErmEL9trReq7jc2nNml6pmfp3wOTtJotoWO9Vno196BAUldanBVanduhWWBhKBD3V86UMEOWk+US10YJVquDHywIVzo8ESNkmU9foVAEXuVLQ25ZHHQVqOezvT5qhbUkpHtm6Z2ZhyrFZns5iN3v2U8x1pii6URRrWoih6bd8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722265098; c=relaxed/simple; bh=mnJWBaNqUVICKqLihTN81l7Qbm0nx5sNfKL9y1iXgSM=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=fZd2JAXIgJOBIG+oPVJS/W+TykCeBAXlJp6zy4EAzjTg5rN2sPAJO/0+mo2Er/MZLSn9PYZMOPta8KycftbCSU+yk3FEwTCFiU4ZSNpzpjUOQbTfco2ZQXv0LueGfB1qkQ8eh9Bv/Kj0Bt5kLmtQl8MUV/FpDjMZva0y6dUZQ7Y= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=FvY7ceD5; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="FvY7ceD5" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F2729C32786; Mon, 29 Jul 2024 14:58:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1722265098; bh=mnJWBaNqUVICKqLihTN81l7Qbm0nx5sNfKL9y1iXgSM=; h=From:To:Cc:Subject:Date:Reply-to:From; b=FvY7ceD5tdqE7G2zVAtiPTBxjr3vk8kGeL4TQij1AV766QBNzL0/4/D12BLrWzNSR WwwxOOTr4A5PvRpj7PTtPiASlqHdKR7oPG8DMsX/FgC7Rr6Q28OzI1YXEMszj9++U5 1HkdC6ccvHMX0ocfyM+NrxmEnW6f0J5OrR0Fd1d4= From: Greg Kroah-Hartman To: linux-cve-announce@vger.kernel.org Cc: Greg Kroah-Hartman Subject: CVE-2024-41057: cachefiles: fix slab-use-after-free in cachefiles_withdraw_cookie() Date: Mon, 29 Jul 2024 16:58:03 +0200 Message-ID: <2024072902-CVE-2024-41057-1d06@gregkh> X-Mailer: git-send-email 2.45.2 Precedence: bulk X-Mailing-List: linux-cve-announce@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Reply-to: , X-Developer-Signature: v=1; a=openpgp-sha256; l=5234; i=gregkh@linuxfoundation.org; h=from:subject:message-id; bh=mnJWBaNqUVICKqLihTN81l7Qbm0nx5sNfKL9y1iXgSM=; b=owGbwMvMwCRo6H6F97bub03G02pJDGnL1/6u2/7+0Pe6zSJRVxRXNwTsFP9fMPmKqOHeL08C4 i6JNVxV7IhlYRBkYpAVU2T5so3n6P6KQ4pehranYeawMoEMYeDiFICJpD1lmMM9i92mTXox1+UD p5UlNH9l91UrNDDMs3rE6j+tQ+WHiYbKiT89u9hkyzd9BgA= X-Developer-Key: i=gregkh@linuxfoundation.org; a=openpgp; fpr=F4B60CC5BF78C2214A313DCB3147D40DDB2DFB29 Content-Transfer-Encoding: 8bit Description =========== In the Linux kernel, the following vulnerability has been resolved: cachefiles: fix slab-use-after-free in cachefiles_withdraw_cookie() We got the following issue in our fault injection stress test: ================================================================== BUG: KASAN: slab-use-after-free in cachefiles_withdraw_cookie+0x4d9/0x600 Read of size 8 at addr ffff888118efc000 by task kworker/u78:0/109 CPU: 13 PID: 109 Comm: kworker/u78:0 Not tainted 6.8.0-dirty #566 Call Trace: kasan_report+0x93/0xc0 cachefiles_withdraw_cookie+0x4d9/0x600 fscache_cookie_state_machine+0x5c8/0x1230 fscache_cookie_worker+0x91/0x1c0 process_one_work+0x7fa/0x1800 [...] Allocated by task 117: kmalloc_trace+0x1b3/0x3c0 cachefiles_acquire_volume+0xf3/0x9c0 fscache_create_volume_work+0x97/0x150 process_one_work+0x7fa/0x1800 [...] Freed by task 120301: kfree+0xf1/0x2c0 cachefiles_withdraw_cache+0x3fa/0x920 cachefiles_put_unbind_pincount+0x1f6/0x250 cachefiles_daemon_release+0x13b/0x290 __fput+0x204/0xa00 task_work_run+0x139/0x230 do_exit+0x87a/0x29b0 [...] ================================================================== Following is the process that triggers the issue: p1 | p2 ------------------------------------------------------------ fscache_begin_lookup fscache_begin_volume_access fscache_cache_is_live(fscache_cache) cachefiles_daemon_release cachefiles_put_unbind_pincount cachefiles_daemon_unbind cachefiles_withdraw_cache fscache_withdraw_cache fscache_set_cache_state(cache, FSCACHE_CACHE_IS_WITHDRAWN); cachefiles_withdraw_objects(cache) fscache_wait_for_objects(fscache) atomic_read(&fscache_cache->object_count) == 0 fscache_perform_lookup cachefiles_lookup_cookie cachefiles_alloc_object refcount_set(&object->ref, 1); object->volume = volume fscache_count_object(vcookie->cache); atomic_inc(&fscache_cache->object_count) cachefiles_withdraw_volumes cachefiles_withdraw_volume fscache_withdraw_volume __cachefiles_free_volume kfree(cachefiles_volume) fscache_cookie_state_machine cachefiles_withdraw_cookie cache = object->volume->cache; // cachefiles_volume UAF !!! After setting FSCACHE_CACHE_IS_WITHDRAWN, wait for all the cookie lookups to complete first, and then wait for fscache_cache->object_count == 0 to avoid the cookie exiting after the volume has been freed and triggering the above issue. Therefore call fscache_withdraw_volume() before calling cachefiles_withdraw_objects(). This way, after setting FSCACHE_CACHE_IS_WITHDRAWN, only the following two cases will occur: 1) fscache_begin_lookup fails in fscache_begin_volume_access(). 2) fscache_withdraw_volume() will ensure that fscache_count_object() has been executed before calling fscache_wait_for_objects(). The Linux kernel CVE team has assigned CVE-2024-41057 to this issue. Affected and fixed versions =========================== Issue introduced in 5.17 with commit fe2140e2f57f and fixed in 6.1.101 with commit 8de253177112 Issue introduced in 5.17 with commit fe2140e2f57f and fixed in 6.6.42 with commit 9e67589a4a7b Issue introduced in 5.17 with commit fe2140e2f57f and fixed in 6.9.11 with commit ef81340401e8 Issue introduced in 5.17 with commit fe2140e2f57f and fixed in 6.10 with commit 5d8f80578907 Please see https://www.kernel.org for a full list of currently supported kernel versions by the kernel community. Unaffected versions might change over time as fixes are backported to older supported kernel versions. The official CVE entry at https://cve.org/CVERecord/?id=CVE-2024-41057 will be updated if fixes are backported, please check that for the most up to date information about this issue. Affected files ============== The file(s) affected by this issue are: fs/cachefiles/cache.c fs/cachefiles/volume.c Mitigation ========== The Linux kernel CVE team recommends that you update to the latest stable kernel version for this, and many other bugfixes. Individual changes are never tested alone, but rather are part of a larger kernel release. Cherry-picking individual commits is not recommended or supported by the Linux kernel community at all. If however, updating to the latest release is impossible, the individual changes to resolve this issue can be found at these commits: https://git.kernel.org/stable/c/8de253177112a47c9af157d23ae934779188b4e1 https://git.kernel.org/stable/c/9e67589a4a7b7e5660b524d1d5fe61242bcbcc11 https://git.kernel.org/stable/c/ef81340401e8a371d6b17f69e76d861920972cfe https://git.kernel.org/stable/c/5d8f805789072ea7fd39504694b7bd17e5f751c4