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 EC97015A4B3 for ; Fri, 12 Jul 2024 12:21:40 +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=1720786901; cv=none; b=FvbHNV/U3W8/kA4+07Z8RJi9S0wsVgBK3YrqTTtIaP7VOVEVN59IrrQcTxm+lYOkS+ihwGE4wVFsnwjgjY0GMm4kyrMHv8A5erBnrvHGlddAgekIgH3mSfAcweGPe8dnEZiVHft6Y41AekUfDVwXiC7cgpuuVCi2WtmJt0/+wGI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720786901; c=relaxed/simple; bh=oPd4+vfS46Vk/n+NPorebM9j9Fd+/RIUXgqI0Qtt+dk=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=k7b6eMbi13E283jfq0KvQUisP0wla28aL4c8+Yircap3qvwtxSac0vUlbV07hTpEXzqqW0oc5cnYV9NL8Z+i9BJHcOieaF5/vxc5IkccGY1k1weZ1Lwb8uWfhbspiDwKkZ71NtKZfTfC93ORBLjDnwSUdSLgMcLT055DtNOnL4c= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=JEGw09+U; 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="JEGw09+U" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7084DC32782; Fri, 12 Jul 2024 12:21:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1720786900; bh=oPd4+vfS46Vk/n+NPorebM9j9Fd+/RIUXgqI0Qtt+dk=; h=From:To:Cc:Subject:Date:Reply-to:From; b=JEGw09+UN8woihu4Oypw0q/eLAOaNtVZrvBG9bYCX+M3tpUftUEyNvwsscPj2l4a2 3WmFbW6XOERz4ky3NjLJXB07IYlzoefCAaHy1oK1XKyr40IEh+4rCiFBnz+stx9bUk C35Ub5GnHNqIU77hwcwsdRRV5tt3hZeibJoxAkZg= From: Greg Kroah-Hartman To: linux-cve-announce@vger.kernel.org Cc: Greg Kroah-Hartman Subject: CVE-2024-39510: cachefiles: fix slab-use-after-free in cachefiles_ondemand_daemon_read() Date: Fri, 12 Jul 2024 14:21:16 +0200 Message-ID: <2024071206-CVE-2024-39510-9f8c@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=4367; i=gregkh@linuxfoundation.org; h=from:subject:message-id; bh=oPd4+vfS46Vk/n+NPorebM9j9Fd+/RIUXgqI0Qtt+dk=; b=owGbwMvMwCRo6H6F97bub03G02pJDGkT5Tcln76R9MSVpflVt9r99Q18eWbVHQvfrGpb7sOdX DpNZurjjlgWBkEmBlkxRZYv23iO7q84pOhlaHsaZg4rE8gQBi5OAZiI3G+GBQs6Fq+Z1XE1eI64 xEvzMomt4YFaPAwLLq/d72K7PKby7dvMxYlxqin1D0wWAwA= 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_ondemand_daemon_read() We got the following issue in a fuzz test of randomly issuing the restore command: ================================================================== BUG: KASAN: slab-use-after-free in cachefiles_ondemand_daemon_read+0xb41/0xb60 Read of size 8 at addr ffff888122e84088 by task ondemand-04-dae/963 CPU: 13 PID: 963 Comm: ondemand-04-dae Not tainted 6.8.0-dirty #564 Call Trace: kasan_report+0x93/0xc0 cachefiles_ondemand_daemon_read+0xb41/0xb60 vfs_read+0x169/0xb50 ksys_read+0xf5/0x1e0 Allocated by task 116: kmem_cache_alloc+0x140/0x3a0 cachefiles_lookup_cookie+0x140/0xcd0 fscache_cookie_state_machine+0x43c/0x1230 [...] Freed by task 792: kmem_cache_free+0xfe/0x390 cachefiles_put_object+0x241/0x480 fscache_cookie_state_machine+0x5c8/0x1230 [...] ================================================================== Following is the process that triggers the issue: mount | daemon_thread1 | daemon_thread2 ------------------------------------------------------------ cachefiles_withdraw_cookie cachefiles_ondemand_clean_object(object) cachefiles_ondemand_send_req REQ_A = kzalloc(sizeof(*req) + data_len) wait_for_completion(&REQ_A->done) cachefiles_daemon_read cachefiles_ondemand_daemon_read REQ_A = cachefiles_ondemand_select_req msg->object_id = req->object->ondemand->ondemand_id ------ restore ------ cachefiles_ondemand_restore xas_for_each(&xas, req, ULONG_MAX) xas_set_mark(&xas, CACHEFILES_REQ_NEW) cachefiles_daemon_read cachefiles_ondemand_daemon_read REQ_A = cachefiles_ondemand_select_req copy_to_user(_buffer, msg, n) xa_erase(&cache->reqs, id) complete(&REQ_A->done) ------ close(fd) ------ cachefiles_ondemand_fd_release cachefiles_put_object cachefiles_put_object kmem_cache_free(cachefiles_object_jar, object) REQ_A->object->ondemand->ondemand_id // object UAF !!! When we see the request within xa_lock, req->object must not have been freed yet, so grab the reference count of object before xa_unlock to avoid the above issue. The Linux kernel CVE team has assigned CVE-2024-39510 to this issue. Affected and fixed versions =========================== Issue introduced in 6.8 with commit 0a7e54c1959c and fixed in 6.9.6 with commit 93064676a282 Issue introduced in 6.8 with commit 0a7e54c1959c and fixed in 6.10-rc4 with commit da4a82741606 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-39510 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/ondemand.c include/trace/events/cachefiles.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/cb55625f8eb9d2de8be4da0c4580d48cbb32058e https://git.kernel.org/stable/c/3958679c49152391209b32be3357193300a51abd https://git.kernel.org/stable/c/93064676a2820420a2d37d7c8289f277fe20793d https://git.kernel.org/stable/c/da4a827416066191aafeeccee50a8836a826ba10