lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <159611042455.535980.12021168777274312453.stgit@localhost.localdomain>
Date:   Thu, 30 Jul 2020 15:00:24 +0300
From:   Kirill Tkhai <ktkhai@...tuozzo.com>
To:     viro@...iv.linux.org.uk, adobriyan@...il.com, davem@...emloft.net,
        ebiederm@...ssion.com, akpm@...ux-foundation.org,
        christian.brauner@...ntu.com, areber@...hat.com, serge@...lyn.com,
        linux-kernel@...r.kernel.org, linux-fsdevel@...r.kernel.org,
        ktkhai@...tuozzo.com
Subject: [PATCH 12/23] user: Free user_ns one RCU grace period after final
 counter put

This is needed to link user_ns into ns_idr in next patch.

Signed-off-by: Kirill Tkhai <ktkhai@...tuozzo.com>
---
 include/linux/user_namespace.h |    5 ++++-
 kernel/user_namespace.c        |    9 ++++++++-
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
index 64cf8ebdc4ec..58fede304201 100644
--- a/include/linux/user_namespace.h
+++ b/include/linux/user_namespace.h
@@ -79,7 +79,10 @@ struct user_namespace {
 #ifdef CONFIG_PERSISTENT_KEYRINGS
 	struct key		*persistent_keyring_register;
 #endif
-	struct work_struct	work;
+	union {
+		struct work_struct	work;
+		struct rcu_head		rcu;
+	};
 #ifdef CONFIG_SYSCTL
 	struct ctl_table_set	set;
 	struct ctl_table_header *sysctls;
diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
index 7c2bbe8f3e45..367a942bb484 100644
--- a/kernel/user_namespace.c
+++ b/kernel/user_namespace.c
@@ -171,6 +171,13 @@ int unshare_userns(unsigned long unshare_flags, struct cred **new_cred)
 	return err;
 }
 
+static void free_user_ns_rcu(struct rcu_head *head)
+{
+	struct user_namespace *ns = container_of(head, struct user_namespace,
+						 rcu);
+	kmem_cache_free(user_ns_cachep, ns);
+}
+
 static void free_user_ns(struct work_struct *work)
 {
 	struct user_namespace *parent, *ns =
@@ -194,7 +201,7 @@ static void free_user_ns(struct work_struct *work)
 		retire_userns_sysctls(ns);
 		key_free_user_ns(ns);
 		ns_free_inum(&ns->ns);
-		kmem_cache_free(user_ns_cachep, ns);
+		call_rcu(&ns->rcu, free_user_ns_rcu);
 		dec_user_namespaces(ucounts);
 		ns = parent;
 	} while (refcount_dec_and_test(&parent->ns.count));


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ