From 30d3f845f7b57c38f2a809108648664059f51821 Mon Sep 17 00:00:00 2001 From: OnlyTomInSecond Date: Tue, 1 Aug 2023 18:14:50 +0800 Subject: [PATCH] Kernel: fix filp_open in kernel below 4.9 Use current_cred()->session_keyring to check whether session_keyring installed or not. --- kernel/kernel_compat.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/kernel/kernel_compat.c b/kernel/kernel_compat.c index 923b79981e7a..c4413a566efa 100644 --- a/kernel/kernel_compat.c +++ b/kernel/kernel_compat.c @@ -77,12 +77,10 @@ void ksu_android_ns_fs_check() struct file *ksu_filp_open_compat(const char *filename, int flags, umode_t mode) { #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 10, 0) - static bool keyring_installed = false; - if (init_session_keyring != NULL && !keyring_installed && + if (init_session_keyring != NULL && !current_cred()->session_keyring && (current->flags & PF_WQ_WORKER)) { pr_info("installing init session keyring for older kernel\n"); install_session_keyring(init_session_keyring); - keyring_installed = true; } #endif // switch mnt_ns even if current is not wq_worker, to ensure what we open is the correct file in android mnt_ns, rather than user created mnt_ns