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 92C1E1E892 for ; Mon, 29 Jul 2024 14:58:15 +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=1722265095; cv=none; b=A0FoortTxlOVVF9qy6qQ0Niw8hEPgcraJP9rMeXkbBKe1sRXw46YumNqwJ/bP+6ovFkhrgsP5rbc0wlS1SG9cjCNEaHqo1lAZDELT9hBK4ntjF7/2lrkBxD9giLK06f5pq/mHTy+94gSiHmd+WcLy/JEkgaOP3EkUas6Tb6OKBo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722265095; c=relaxed/simple; bh=i3m3RWlTeOTIhUXAepv0K9fR6xRAJ+mzOcHLqFlIMvE=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=pGAZ9bR/ISmhPWyiZJnQhxcZ5/nGCuBfyRxFu7Rw/t2Blc3zMqnHj6eNqga5tb+5U9f18EFI87RiiB1VOlCohx5HbeYrPYOvh4QZpIAFQqOs8JkCl0AynBvALAGMhiF4RqRrM5vA1hsW7s0JNxDjgt5YE7H7dXnlwgivwm7fdds= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=aDi8oGNn; 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="aDi8oGNn" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 969F5C32786; Mon, 29 Jul 2024 14:58:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1722265095; bh=i3m3RWlTeOTIhUXAepv0K9fR6xRAJ+mzOcHLqFlIMvE=; h=From:To:Cc:Subject:Date:Reply-to:From; b=aDi8oGNnTEfzKF/GIdxCdAYxDGqUY9UObedsFlOcNh29thBJ7Og7svdMhWiSfiRzH RSXWfTbgMpWRViSF+IMWpNXY2mUhGeRww0uUJKU6VKx9oQTQSdtXpCpfJIKmFCNWqi PwGMk/DCFBrfj/BgSYQH2z87gVUPMIInvaJYR8JI= From: Greg Kroah-Hartman To: linux-cve-announce@vger.kernel.org Cc: Greg Kroah-Hartman Subject: CVE-2024-41058: cachefiles: fix slab-use-after-free in fscache_withdraw_volume() Date: Mon, 29 Jul 2024 16:58:04 +0200 Message-ID: <2024072905-CVE-2024-41058-4593@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=5076; i=gregkh@linuxfoundation.org; h=from:subject:message-id; bh=i3m3RWlTeOTIhUXAepv0K9fR6xRAJ+mzOcHLqFlIMvE=; b=owGbwMvMwCRo6H6F97bub03G02pJDGnL1/49fYazdPPvP5O+XDJsS7uw/6P6lEO1q5qfz2+L3 atg4vN7RkcsC4MgE4OsmCLLl208R/dXHFL0MrQ9DTOHlQlkCAMXpwBMRPINw4K9/u3lFzaKTvy5 68YcvqJau+cbxEMZ5uc+XLrw6W3Wo1G2eV3nb5WU+PQ0igMA 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 fscache_withdraw_volume() We got the following issue in our fault injection stress test: ================================================================== BUG: KASAN: slab-use-after-free in fscache_withdraw_volume+0x2e1/0x370 Read of size 4 at addr ffff88810680be08 by task ondemand-04-dae/5798 CPU: 0 PID: 5798 Comm: ondemand-04-dae Not tainted 6.8.0-dirty #565 Call Trace: kasan_check_range+0xf6/0x1b0 fscache_withdraw_volume+0x2e1/0x370 cachefiles_withdraw_volume+0x31/0x50 cachefiles_withdraw_cache+0x3ad/0x900 cachefiles_put_unbind_pincount+0x1f6/0x250 cachefiles_daemon_release+0x13b/0x290 __fput+0x204/0xa00 task_work_run+0x139/0x230 Allocated by task 5820: __kmalloc+0x1df/0x4b0 fscache_alloc_volume+0x70/0x600 __fscache_acquire_volume+0x1c/0x610 erofs_fscache_register_volume+0x96/0x1a0 erofs_fscache_register_fs+0x49a/0x690 erofs_fc_fill_super+0x6c0/0xcc0 vfs_get_super+0xa9/0x140 vfs_get_tree+0x8e/0x300 do_new_mount+0x28c/0x580 [...] Freed by task 5820: kfree+0xf1/0x2c0 fscache_put_volume.part.0+0x5cb/0x9e0 erofs_fscache_unregister_fs+0x157/0x1b0 erofs_kill_sb+0xd9/0x1c0 deactivate_locked_super+0xa3/0x100 vfs_get_super+0x105/0x140 vfs_get_tree+0x8e/0x300 do_new_mount+0x28c/0x580 [...] ================================================================== Following is the process that triggers the issue: mount failed | daemon exit ------------------------------------------------------------ deactivate_locked_super cachefiles_daemon_release erofs_kill_sb erofs_fscache_unregister_fs fscache_relinquish_volume __fscache_relinquish_volume fscache_put_volume(fscache_volume, fscache_volume_put_relinquish) zero = __refcount_dec_and_test(&fscache_volume->ref, &ref); cachefiles_put_unbind_pincount cachefiles_daemon_unbind cachefiles_withdraw_cache cachefiles_withdraw_volumes list_del_init(&volume->cache_link) fscache_free_volume(fscache_volume) cache->ops->free_volume cachefiles_free_volume list_del_init(&cachefiles_volume->cache_link); kfree(fscache_volume) cachefiles_withdraw_volume fscache_withdraw_volume fscache_volume->n_accesses // fscache_volume UAF !!! The fscache_volume in cache->volumes must not have been freed yet, but its reference count may be 0. So use the new fscache_try_get_volume() helper function try to get its reference count. If the reference count of fscache_volume is 0, fscache_put_volume() is freeing it, so wait for it to be removed from cache->volumes. If its reference count is not 0, call cachefiles_withdraw_volume() with reference count protection to avoid the above issue. The Linux kernel CVE team has assigned CVE-2024-41058 to this issue. Affected and fixed versions =========================== Issue introduced in 5.17 with commit fe2140e2f57f and fixed in 6.1.101 with commit 90f17e47f1e2 Issue introduced in 5.17 with commit fe2140e2f57f and fixed in 6.6.42 with commit 9dd7f5663899 Issue introduced in 5.17 with commit fe2140e2f57f and fixed in 6.9.11 with commit 38b88d544216 Issue introduced in 5.17 with commit fe2140e2f57f and fixed in 6.10 with commit 522018a0de6b 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-41058 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 include/trace/events/fscache.h 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/90f17e47f1e209c6a3c92a1d038a0a80c95c460e https://git.kernel.org/stable/c/9dd7f5663899ea13a6a73216106d9c13c37453e3 https://git.kernel.org/stable/c/38b88d544216f806d93a273a62ff8ebe82254003 https://git.kernel.org/stable/c/522018a0de6b6fcce60c04f86dfc5f0e4b6a1b36