kernel/nsproxy: Minor nsproxy code simplification
cover kernel/nsproxy: Minor nsproxy code simplification
The first patch removes an unnecessary guard by the same logic as commit 5caa2d89b7f1 ("kernel/nsproxy: remove unnecessary guards").
The second patch fixes the total ordering of resource acquisition in validate_nsset().
The third patch implements usage of the cleanup helper added by commit d057c108155a ("nsproxy: add a cleanup helper for nsproxy").
Joel Savitz (3):
kernel/nsproxy: remove unnecessary guard in validate_nsset() kernel/nsproxy: fix put_*() call ordering in validate_nsset() kernel/nsproxy: utilize cleanup helper for nsproxy references
kernel/nsproxy.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-)
Signature · 1 line
2.45.2
PATCH 1/3 kernel/nsproxy: remove unnecessary guard in validate_nsset()
By the same logic as commit 5caa2d89b7f1 ("kernel/nsproxy: remove unnecessary guards"), remove the guard around put_pid_ns() in validate_nsset() as put_pid_ns() already performs the NULL check.
--- kernel/nsproxy.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
kernel/nsproxy.c +1 -2
@@ -481,8 +481,7 @@ static int validate_nsset(struct nsset *nsset, struct pid *pid)#endif out: -if (pid_ns) -put_pid_ns (pid_ns); +put_pid_ns (pid_ns);if (nsp)put_nsproxy (nsp);put_user_ns (user_ns);
Signature · 1 line
2.45.2
PATCH 2/3 kernel/nsproxy: fix put_*() call ordering in validate_nsset()
In reply to Joel SavitzThe calls to get_nsproxy(), get_pid_ns(), and get_user_ns() happen in that order, so call their respective put_*() functions in the reverse order.
--- kernel/nsproxy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/nsproxy.c +1 -1
@@ -481,10 +481,10 @@ static int validate_nsset(struct nsset *nsset, struct pid *pid)#endif out: +put_user_ns (user_ns);put_pid_ns (pid_ns);if (nsp)put_nsproxy (nsp); -put_user_ns (user_ns);return ret; }
Signature · 1 line
2.45.2
PATCH 3/3 kernel/nsproxy: utilize cleanup helper for nsproxy references
In reply to Joel SavitzA cleanup helper for nsproxy references was added by commit d057c108155a ("nsproxy: add a cleanup helper for nsproxy") however it is only used in commit 5b08bd408534 ("pidfs: allow retrieval of namespace file descriptors").
Simplify nsproxy code by using this cleanup helper.
--- kernel/nsproxy.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)
kernel/nsproxy.c +2 -7
@@ -228,7 +228,7 @@ int unshare_nsproxy_namespaces(unsigned long unshare_flags,void switch_task_namespaces (struct task_struct *p,struct nsproxy *new) { -struct nsproxy *ns; + struct nsproxy *ns __free(put_nsproxy) = NULL;might_sleep ();
@@ -236,9 +236,6 @@ void switch_task_namespaces(struct task_struct *p, struct nsproxy *new) ns = p->nsproxy; p->nsproxy = new;task_unlock (p); - -if (ns) -put_nsproxy (ns); }void exit_task_namespaces (struct task_struct *p)
@@ -368,7 +365,7 @@ static int validate_nsset(struct nsset *nsset, struct pid *pid)unsigned flags = nsset->flags;struct user_namespace *user_ns =NULL ;struct pid_namespace *pid_ns =NULL ; -struct nsproxy *nsp; + struct nsproxy *nsp __free(put_nsproxy) = NULL;struct task_struct *tsk;/* Take a "snapshot" of the target task's namespaces. */
@@ -483,8 +480,6 @@ static int validate_nsset(struct nsset *nsset, struct pid *pid) out:put_user_ns (user_ns);put_pid_ns (pid_ns); -if (nsp) -put_nsproxy (nsp);return ret; }
Signature · 1 line
2.45.2
Quoted 15 lines · Joel Savitz
The first patch removes an unnecessary guard by the same logic as commit
5caa2d89b7f1("kernel/nsproxy: remove unnecessary guards").The second patch fixes the total ordering of resource acquisition in
validate_nsset().The third patch implements usage of the cleanup helper added by commit
d057c108155a("nsproxy: add a cleanup helper for nsproxy").Joel Savitz (3):
kernel/nsproxy: remove unnecessary guard invalidate_nsset()kernel/nsproxy: fix put_*() call ordering invalidate_nsset()kernel/nsproxy: utilize cleanup helper for nsproxy references
Quoted 6 lines
kernel/nsproxy.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-)--
2.45.2
ping
Quoted 17 lines · Joel Savitz
Quoted 15 lines · Joel Savitz
The first patch removes an unnecessary guard by the same logic as commit
5caa2d89b7f1("kernel/nsproxy: remove unnecessary guards").The second patch fixes the total ordering of resource acquisition in
validate_nsset().The third patch implements usage of the cleanup helper added by commit
d057c108155a("nsproxy: add a cleanup helper for nsproxy").Joel Savitz (3):
kernel/nsproxy: remove unnecessary guard invalidate_nsset()kernel/nsproxy: fix put_*() call ordering invalidate_nsset()kernel/nsproxy: utilize cleanup helper for nsproxy references
Quoted 8 lines
Quoted 6 lines
kernel/nsproxy.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-)--
2.45.2ping
ping 2
Quoted 22 lines · Joel Savitz
Quoted 20 lines · Joel Savitz
Quoted 18 lines · Joel Savitz
The first patch removes an unnecessary guard by the same logic as commit
5caa2d89b7f1("kernel/nsproxy: remove unnecessary guards").The second patch fixes the total ordering of resource acquisition in
validate_nsset().The third patch implements usage of the cleanup helper added by commit
d057c108155a("nsproxy: add a cleanup helper for nsproxy").Joel Savitz (3):
kernel/nsproxy: remove unnecessary guard invalidate_nsset()kernel/nsproxy: fix put_*() call ordering invalidate_nsset()kernel/nsproxy: utilize cleanup helper for nsproxy referenceskernel/nsproxy.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-)
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
--
2.45.2ping
ping 2
ping 3
Quoted 28 lines · Joel Savitz
Quoted 26 lines · Joel Savitz
Quoted 24 lines · Joel Savitz
Quoted 21 lines · Joel Savitz
The first patch removes an unnecessary guard by the same logic as commit
5caa2d89b7f1("kernel/nsproxy: remove unnecessary guards").The second patch fixes the total ordering of resource acquisition in
validate_nsset().The third patch implements usage of the cleanup helper added by commit
d057c108155a("nsproxy: add a cleanup helper for nsproxy").Joel Savitz (3):
kernel/nsproxy: remove unnecessary guard invalidate_nsset()kernel/nsproxy: fix put_*() call ordering invalidate_nsset()kernel/nsproxy: utilize cleanup helper for nsproxy referenceskernel/nsproxy.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-)--
2.45.2
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
ping
ping 2
ping 3
ping 4
Christian Brauner
AppliedQuoted 10 lines · Joel Savitz
The first patch removes an unnecessary guard by the same logic as commit
5caa2d89b7f1("kernel/nsproxy: remove unnecessary guards").The second patch fixes the total ordering of resource acquisition in
validate_nsset().The third patch implements usage of the cleanup helper added by commit
d057c108155a("nsproxy: add a cleanup helper for nsproxy").[...]
Applied to the kernel-6.17.nsproxy branch of the vfs/vfs.git tree. Patches in the kernel-6.17.nsproxy branch should appear in linux-next soon.
Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.
It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git branch: kernel-6.17.nsproxy
[1/3] kernel/nsproxy: remove unnecessary guard in validate_nsset()
https://git.kernel.org/vfs/vfs/c/e07195e0a5c3 [2/3] kernel/nsproxy: fix put_*() call ordering in validate_nsset() https://git.kernel.org/vfs/vfs/c/17e48a8cfd75 [3/3] kernel/nsproxy: utilize cleanup helper for nsproxy references https://git.kernel.org/vfs/vfs/c/04555045c014