FAILED: patch "[PATCH] ucounts: Proper error handling in set_cred_ucounts" failed to apply to 5.10-stable tree
Subsystems (2)
[email protected]
maintainerThe patch below does not apply to the 5.10-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 34dc2fd6e6908499b669c7b45320cddf38b332e1 Mon Sep 17 00:00:00 2001
From: "Eric W. Biederman" <[email protected]>
Date: Sat, 16 Oct 2021 12:47:51 -0500
Subject: [PATCH] ucounts: Proper error handling in set_cred_ucounts
Instead of leaking the ucounts in new if alloc_ucounts fails, store the result of alloc_ucounts into a temporary variable, which is later assigned to new->ucounts.
Fixes 905ae01c4ae2 ("Add a reference to ucounts for each cred")
Tested-by Yu Zhao <[email protected]>
Reviewed-by Alexey Gladkov <[email protected]>
Signed-off-by "Eric W. Biederman" <[email protected]>
kernel/cred.c +3 -2
@@ -669,7 +669,7 @@ int set_cred_ucounts(struct cred *new) {struct task_struct *task = current;const struct cred *old = task->real_cred; -struct ucounts *old_ucounts = new->ucounts; +struct ucounts *new_ucounts, *old_ucounts = new->ucounts;if (new->user == old->user && new->user_ns == old->user_ns)return 0 ;
@@ -681,9 +681,10 @@ int set_cred_ucounts(struct cred *new)if (old_ucounts && old_ucounts->ns == new->user_ns &&uid_eq (old_ucounts->uid, new->euid))return 0 ; -if (!(new->ucounts =alloc_ucounts (new->user_ns, new->euid))) +if (!(new_ucounts =alloc_ucounts (new->user_ns, new->euid)))return -EAGAIN ; + new->ucounts = new_ucounts;if (old_ucounts)put_ucounts (old_ucounts);