Baokun Li
8a7e4f1962
cachefiles: fix memory leak in cachefiles_add_cache()
commit e21a2f17566cbd64926fb8f16323972f7a064444 upstream.
The following memory leak was reported after unbinding /dev/cachefiles:
==================================================================
unreferenced object 0xffff9b674176e3c0 (size 192):
comm "cachefilesd2", pid 680, jiffies 4294881224
hex dump (first 32 bytes):
01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
backtrace (crc ea38a44b):
[<ffffffff8eb8a1a5>] kmem_cache_alloc+0x2d5/0x370
[<ffffffff8e917f86>] prepare_creds+0x26/0x2e0
[<ffffffffc002eeef>] cachefiles_determine_cache_security+0x1f/0x120
[<ffffffffc00243ec>] cachefiles_add_cache+0x13c/0x3a0
[<ffffffffc0025216>] cachefiles_daemon_write+0x146/0x1c0
[<ffffffff8ebc4a3b>] vfs_write+0xcb/0x520
[<ffffffff8ebc5069>] ksys_write+0x69/0xf0
[<ffffffff8f6d4662>] do_syscall_64+0x72/0x140
[<ffffffff8f8000aa>] entry_SYSCALL_64_after_hwframe+0x6e/0x76
==================================================================
Put the reference count of cache_cred in cachefiles_daemon_unbind() to
fix the problem. And also put cache_cred in cachefiles_add_cache() error
branch to avoid memory leaks.
Fixes: 9ae326a69004 ("CacheFiles: A cache that backs onto a mounted filesystem")
CC: stable@vger.kernel.org
Signed-off-by: Baokun Li <libaokun1@huawei.com>
Link: https://lore.kernel.org/r/20240217081431.796809-1-libaokun1@huawei.com
Acked-by: David Howells <dhowells@redhat.com>
Reviewed-by: Jingbo Xu <jefflexu@linux.alibaba.com>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Christian Brauner <brauner@kernel.org>
Signed-off-by: Baokun Li <libaokun1@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit cb5466783793e66272624cf71925ae1d1ba32083)
Signed-off-by: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
2024-03-26 11:04:59 +00:00
..
2022-06-25 11:46:24 +02:00
2019-08-06 19:05:21 +02:00
2023-02-06 07:46:28 +01:00
2023-08-11 11:33:32 +02:00
2023-09-23 10:47:03 +02:00
2024-03-26 11:04:58 +00:00
2024-03-26 11:04:59 +00:00
2024-03-08 08:21:34 +00:00
2023-09-23 10:46:54 +02:00
2019-08-06 19:05:23 +02:00
2022-03-02 11:33:56 +01:00
2021-07-20 16:17:45 +02:00
2019-05-08 07:20:49 +02:00
2019-03-23 14:35:21 +01:00
2023-08-11 11:33:45 +02:00
2021-05-26 11:47:00 +02:00
2020-12-02 08:34:44 +01:00
2019-12-05 15:37:28 +01:00
2020-01-27 14:46:06 +01:00
2023-09-23 10:47:04 +02:00
2024-03-21 13:32:17 +00:00
2024-02-02 11:33:43 +00:00
2023-08-11 11:33:32 +02:00
2024-01-18 11:22:33 +00:00
2023-11-28 16:45:44 +00:00
2023-03-11 16:26:44 +01:00
2023-08-11 11:33:32 +02:00
2021-06-03 08:36:25 +02:00
2023-08-11 11:33:32 +02:00
2024-02-02 11:33:36 +00:00
2023-08-11 11:33:41 +02:00
2024-03-08 08:21:30 +00:00
2022-11-03 23:50:53 +09:00
2023-09-23 10:46:57 +02:00
2020-08-21 09:48:15 +02:00
2024-02-02 11:33:41 +00:00
2020-12-29 13:47:01 +01:00
2024-02-02 11:33:47 +00:00
2024-03-21 13:32:16 +00:00
2023-09-23 10:46:53 +02:00
2022-06-14 16:53:48 +02:00
2022-11-25 17:36:55 +01:00
2023-09-23 10:46:55 +02:00
2023-08-11 11:33:32 +02:00
2023-01-18 09:26:33 +01:00
2023-10-25 11:13:32 +02:00
2023-09-23 10:47:00 +02:00
2024-03-08 08:21:30 +00:00
2021-10-06 15:05:08 +02:00
2023-08-30 16:35:09 +02:00
2020-10-29 09:07:11 +01:00
2023-09-23 10:46:54 +02:00
2020-08-26 10:29:54 +02:00
2023-02-22 12:46:05 +01:00
2023-03-22 13:26:13 +01:00
2023-08-11 11:33:56 +02:00
2022-09-20 11:51:31 +02:00
2023-08-11 11:33:32 +02:00
2023-09-23 10:46:54 +02:00
2020-08-21 09:48:22 +02:00
2023-08-11 11:33:32 +02:00
2024-03-21 13:32:32 +00:00
2023-09-23 10:47:05 +02:00
2023-10-10 21:43:40 +02:00
2020-06-03 08:18:03 +02:00
2022-06-14 16:53:43 +02:00
2023-01-18 09:26:29 +01:00
2019-11-06 12:42:59 +01:00
2024-01-08 11:25:05 +01:00
2022-11-25 17:36:55 +01:00
2023-01-18 09:26:24 +01:00
2024-03-08 08:21:39 +00:00
2020-05-20 08:16:58 +02:00
2020-03-11 18:02:43 +01:00
2024-03-08 08:21:33 +00:00
2021-04-16 11:57:48 +02:00
2020-01-12 12:11:59 +01:00
2020-10-14 09:51:09 +02:00
2022-06-06 08:20:57 +02:00
2021-12-08 08:46:55 +01:00
2023-03-17 08:30:36 +01:00
2020-04-24 08:00:43 +02:00
2023-05-17 11:11:48 +02:00
2022-10-26 13:16:51 +02:00
2019-12-17 20:38:57 +01:00
2023-01-18 09:26:10 +01:00
2020-01-09 10:17:55 +01:00
2023-09-23 10:46:54 +02:00
2022-05-15 19:40:27 +02:00
2020-03-20 10:54:16 +01:00
2021-08-15 13:03:31 +02:00
2023-01-18 09:26:35 +01:00
2019-12-01 09:13:51 +01:00
2021-04-28 12:08:41 +02:00
2021-03-24 11:05:05 +01:00
2021-07-20 16:17:55 +02:00
2021-12-14 10:16:55 +01:00
2022-10-26 13:16:56 +02:00
2022-04-27 13:15:30 +02:00
2023-05-30 12:38:36 +01:00
2022-02-23 11:57:33 +01:00
2020-01-04 13:59:58 +01:00
2023-01-18 09:26:09 +01:00