OpenVZ / Virtuozzo kernel development (devel@openvz.org)
 help / color / mirror / Atom feed
From: Vladimir Riabchun <vladimir.riabchun@virtuozzo.com>
To: vasileios.almpanis@virtuozzo.com, ptikhomirov@virtuozzo.com,
	Konstantin Khorenko <khorenko@virtuozzo.com>
Cc: devel@openvz.org
Subject: [Devel] [PATCH hci-8.1 v8 3/6] ve: Defer ve creds drop until ve is completely destroyed
Date: Mon, 16 Nov 2026 20:20:41 +0100	[thread overview]
Message-ID: <20261116-ovl-use-orig-ve-v8-3-dfe427bfd902@virtuozzo.com> (raw)
In-Reply-To: <20261116-ovl-use-orig-ve-v8-0-dfe427bfd902@virtuozzo.com>

We may have a case, when VE is dead, but there are some users of it,
overlayfs superblock for example.

This user may want to use VE creds, so we need to keep ve->init_cred alive.
Drop creds in ve_destroy. We need to drop ve_nsproxy early because
ploop waits for refcount going to zero, dropping ve_nsproxy in destroy
causes CT suspend/resume hangs.

This commit changes ve->init_cred == NULL meaning. Now it means
that VE is not started. Dead VE keeps its cred.

https://virtuozzo.atlassian.net/browse/VSTOR-142405
Signed-off-by: Vladimir Riabchun <vladimir.riabchun@virtuozzo.com>
---
 kernel/capability.c      | 4 ++--
 kernel/ve/ve.c           | 4 ++++
 net/netlink/af_netlink.c | 2 +-
 3 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/kernel/capability.c b/kernel/capability.c
index 6de4dcba2283..68c3d5288ba7 100644
--- a/kernel/capability.c
+++ b/kernel/capability.c
@@ -395,7 +395,7 @@ bool ve_capable(int cap)
 	rcu_read_lock();
 	cred = ve->init_cred;
 
-	if (cred == NULL) /* ve isn't running */
+	if (cred == NULL) /* ve isn't started */
 		cred = ve0.init_cred;
 
 	ret = ns_capable(cred->user_ns, cap);
@@ -413,7 +413,7 @@ bool ve_capable_noaudit(int cap)
 	rcu_read_lock();
 	cred = ve->init_cred;
 
-	if (cred == NULL) /* ve isn't running */
+	if (cred == NULL) /* ve isn't started */
 		cred = ve0.init_cred;
 
 	ret = ns_capable_noaudit(cred->user_ns, cap);
diff --git a/kernel/ve/ve.c b/kernel/ve/ve.c
index d3f02fe118ca..de7fe776d4e6 100644
--- a/kernel/ve/ve.c
+++ b/kernel/ve/ve.c
@@ -378,7 +378,10 @@ static void ve_drop_context(struct ve_struct *ve)
 	rcu_assign_pointer(ve->ve_nsproxy, NULL);
 	synchronize_rcu();
 	put_nsproxy(ve_nsproxy);
+}
 
+static void ve_drop_cred(struct ve_struct *ve)
+{
 	put_cred(ve->init_cred);
 	ve->init_cred = NULL;
 }
@@ -919,6 +922,7 @@ static void ve_destroy(struct cgroup_subsys_state *css)
 {
 	struct ve_struct *ve = css_to_ve(css);
 
+	ve_drop_cred(ve);
 	free_ve_devmnts(ve);
 
 	kmapset_unlink(&ve->sysfs_perms_key, &sysfs_ve_perms_set);
diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
index f686e6ea30ce..c4a25ec2a15e 100644
--- a/net/netlink/af_netlink.c
+++ b/net/netlink/af_netlink.c
@@ -887,7 +887,7 @@ bool netlink_ve_capable(const struct sk_buff *skb, int cap)
 {
 	struct cred *cred = get_exec_env()->init_cred;
 
-	if (cred == NULL) /* ve isn't running */
+	if (cred == NULL) /* ve isn't started */
 		cred = ve0.init_cred;
 
 	return netlink_ns_capable(skb, cred->user_ns, cap);

-- 
2.52.0

_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

  parent reply	other threads:[~2026-11-16 19:22 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16 19:20 [Devel] [PATCH hci-8.1 v8 0/6] Fix kernel crash in overlayfs Vladimir Riabchun
2026-11-16 19:20 ` [Devel] [PATCH hci-8.1 v8 1/6] ve: Remove STOPPED state Vladimir Riabchun
2026-11-16 19:25   ` no-reply
2026-11-16 19:20 ` [Devel] [PATCH hci-8.1 v8 2/6] ve: Introduce override_ve/revert_ve helpers Vladimir Riabchun
2026-11-16 19:27   ` no-reply
2026-11-16 20:05     ` Vladimir Riabchun
2026-11-16 19:20 ` Vladimir Riabchun [this message]
2026-11-16 19:27   ` [Devel] [PATCH hci-8.1 v8 3/6] ve: Defer ve creds drop until ve is completely destroyed no-reply
2026-11-16 19:20 ` [Devel] [PATCH hci-8.1 v8 4/6] ovl: Keep creator VE in overlayfs superblock Vladimir Riabchun
2026-11-16 19:28   ` no-reply
2026-11-17 14:49   ` Konstantin Khorenko
2026-11-16 19:20 ` [Devel] [PATCH hci-8.1 v8 5/6] ovl: Fix leaking fd references in ovl_copyfile Vladimir Riabchun
2026-11-16 19:28   ` no-reply
2026-11-16 20:03     ` Vladimir Riabchun
2026-11-16 19:20 ` [Devel] [PATCH hci-8.1 v8 6/6] ve/overlayfs: Override VE together with creds Vladimir Riabchun
2026-11-16 19:36   ` no-reply
2026-11-16 20:03     ` Vladimir Riabchun
2026-11-17 14:49 ` [Devel] [PATCH hci-8.1 v8 0/6] Fix kernel crash in overlayfs Konstantin Khorenko
2026-11-17 14:49 ` Konstantin Khorenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261116-ovl-use-orig-ve-v8-3-dfe427bfd902@virtuozzo.com \
    --to=vladimir.riabchun@virtuozzo.com \
    --cc=devel@openvz.org \
    --cc=khorenko@virtuozzo.com \
    --cc=ptikhomirov@virtuozzo.com \
    --cc=vasileios.almpanis@virtuozzo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox