apparmor: Fix label reference leak in aa_unix_file_perm()
Subsystems (3)
PATCH 1/1 apparmor: Fix label reference leak in aa_unix_file_perm()
The inner block in aa_unix_file_perm() re-declares plabel, shadowing the outer variable that is released at the out label. The reference taken by aa_get_label_rcu() is thus lost when the block exits, and aa_put_label() at out is a no-op on the still NULL outer plabel, leaking one label per permission check on a non-filesystem unix socket.
Drop the shadowing declaration so the outer plabel is used and released.
--- security/apparmor/af_unix.c | 1 - 1 file changed, 1 deletion(-)
security/apparmor/af_unix.c +0 -1
@@ -758,7 +758,6 @@ int aa_unix_file_perm(const struct cred *subj_cred, struct aa_label *label,unix_fs_perm (op, request, subj_cred, label, is_unix_fs(peer_sk) ? &peer_path : NULL)); }else if (!is_sk_fs) { -struct aa_label *plabel;struct aa_sk_ctx *pctx =aa_sock (peer_sk);rcu_read_lock ();
Signature · 1 line
2.34.1
Ryan Lee
NAKQuoted 29 lines · Wentao Liang
The inner block in
aa_unix_file_perm()re-declares plabel, shadowing the outer variable that is released at the out label. The reference taken byaa_get_label_rcu()is thus lost when the block exits, andaa_put_label()at out is a no-op on the still NULL outer plabel, leaking one label per permission check on a non-filesystem unix socket.Drop the shadowing declaration so the outer plabel is used and released.
Fixes 88fec3526e84 ("apparmor: make sure unix socket labeling is correctly updated.")Signed-off-by Wentao Liang <[email protected]>--- security/apparmor/af_unix.c | 1 - 1 file changed, 1 deletion(-)security/apparmor/af_unix.c +0
-2@@ -758,7 +758,6 @@ int aa_unix_file_perm(const struct cred *subj_cred, struct aa_label *label,unix_fs_perm (op, request, subj_cred, label, is_unix_fs(peer_sk) ? &peer_path : NULL)); }else if (!is_sk_fs) { -struct aa_label *plabel;struct aa_sk_ctx *pctx =aa_sock (peer_sk);rcu_read_lock (); --
Quoted 3 lines
2.34.1
NACK: this exact patch has been proposed before, and unfortunately exposes an additional latent bug around plabel handling that results in a use-after-free if the shadowed declaration is removed without additional fixes.
I can try to dig out the relevant exchange from the AppArmor mailing list later, if you'd be interested.
Ryan
John Johansen
maintainerQuoted 39 lines · Ryan Lee
Quoted 29 lines · Wentao Liang
The inner block in
aa_unix_file_perm()re-declares plabel, shadowing the outer variable that is released at the out label. The reference taken byaa_get_label_rcu()is thus lost when the block exits, andaa_put_label()at out is a no-op on the still NULL outer plabel, leaking one label per permission check on a non-filesystem unix socket.Drop the shadowing declaration so the outer plabel is used and released.
Fixes 88fec3526e84 ("apparmor: make sure unix socket labeling is correctly updated.")Signed-off-by Wentao Liang <[email protected]>--- security/apparmor/af_unix.c | 1 - 1 file changed, 1 deletion(-)security/apparmor/af_unix.c +0
-2@@ -758,7 +758,6 @@ int aa_unix_file_perm(const struct cred *subj_cred, struct aa_label *label,unix_fs_perm (op, request, subj_cred, label, is_unix_fs(peer_sk) ? &peer_path : NULL)); }else if (!is_sk_fs) { -struct aa_label *plabel;struct aa_sk_ctx *pctx =aa_sock (peer_sk);rcu_read_lock (); --Quoted 3 lines
2.34.1
NACK: this exact patch has been proposed before, and unfortunately exposes an additional latent bug around plabel handling that results in a use-after-free if the shadowed declaration is removed without additional fixes.
Quoted 3 lines
I can try to dig out the relevant exchange from the AppArmor mailing list later, if you'd be interested.
The series Ryan is referring to is in Linus's tree, so you should see the fix rolling out to stable kernels as well soon.
6d25e7b47616c apparmor: fix refcount leak when updating the sk_ctx b1aea2c196077 apparmor: fix race in unix socket mediation when peer_path is used 4483efe4f2151 apparmor: fix shadowing of plabel that prevents cache from being updated
Quoted 1 line
Ryan
Quoted 43 lines · John Johansen
Quoted 39 lines · Ryan Lee
Quoted 29 lines · Wentao Liang
The inner block in
aa_unix_file_perm()re-declares plabel, shadowing the outer variable that is released at the out label. The reference taken byaa_get_label_rcu()is thus lost when the block exits, andaa_put_label()at out is a no-op on the still NULL outer plabel, leaking one label per permission check on a non-filesystem unix socket.Drop the shadowing declaration so the outer plabel is used and released.
Fixes 88fec3526e84 ("apparmor: make sure unix socket labeling is correctly updated.")Signed-off-by Wentao Liang <[email protected]>--- security/apparmor/af_unix.c | 1 - 1 file changed, 1 deletion(-)security/apparmor/af_unix.c +0
-2@@ -758,7 +758,6 @@ int aa_unix_file_perm(const struct cred *subj_cred, struct aa_label *label,unix_fs_perm (op, request, subj_cred, label, is_unix_fs(peer_sk) ? &peer_path : NULL)); }else if (!is_sk_fs) { -struct aa_label *plabel;struct aa_sk_ctx *pctx =aa_sock (peer_sk);rcu_read_lock (); --Quoted 3 lines
2.34.1
NACK: this exact patch has been proposed before, and unfortunately exposes an additional latent bug around plabel handling that results in a use-after-free if the shadowed declaration is removed without additional fixes.
Quoted 3 lines
I can try to dig out the relevant exchange from the AppArmor mailing list later, if you'd be interested.
Quoted 6 lines
The series Ryan is referring to is in Linus's tree, so you should see the fix rolling out to stable kernels as well soon.
6d25e7b47616capparmor: fix refcount leak when updating thesk_ctxb1aea2c196077apparmor: fix race in unix socket mediation whenpeer_pathis used4483efe4f2151apparmor: fix shadowing of plabel that prevents cache from being updated
These are all in stable released kernels already for many weeks, so how is any of this still being reported?
confused,
greg k-h
John Johansen
maintainerQuoted 51 lines · Greg KH
Quoted 43 lines · John Johansen
Quoted 39 lines · Ryan Lee
Quoted 29 lines · Wentao Liang
The inner block in
aa_unix_file_perm()re-declares plabel, shadowing the outer variable that is released at the out label. The reference taken byaa_get_label_rcu()is thus lost when the block exits, andaa_put_label()at out is a no-op on the still NULL outer plabel, leaking one label per permission check on a non-filesystem unix socket.Drop the shadowing declaration so the outer plabel is used and released.
Fixes 88fec3526e84 ("apparmor: make sure unix socket labeling is correctly updated.")Signed-off-by Wentao Liang <[email protected]>--- security/apparmor/af_unix.c | 1 - 1 file changed, 1 deletion(-)security/apparmor/af_unix.c +0
-2@@ -758,7 +758,6 @@ int aa_unix_file_perm(const struct cred *subj_cred, struct aa_label *label,unix_fs_perm (op, request, subj_cred, label, is_unix_fs(peer_sk) ? &peer_path : NULL)); }else if (!is_sk_fs) { -struct aa_label *plabel;struct aa_sk_ctx *pctx =aa_sock (peer_sk);rcu_read_lock (); --Quoted 3 lines
2.34.1
NACK: this exact patch has been proposed before, and unfortunately exposes an additional latent bug around plabel handling that results in a use-after-free if the shadowed declaration is removed without additional fixes.
Quoted 3 lines
I can try to dig out the relevant exchange from the AppArmor mailing list later, if you'd be interested.
Quoted 6 lines
The series Ryan is referring to is in Linus's tree, so you should see the fix rolling out to stable kernels as well soon.
6d25e7b47616capparmor: fix refcount leak when updating thesk_ctxb1aea2c196077apparmor: fix race in unix socket mediation whenpeer_pathis used4483efe4f2151apparmor: fix shadowing of plabel that prevents cache from being updated
Quoted 5 lines
These are all in stable released kernels already for many weeks, so how is any of this still being reported?
confused,
I don't know, my guess is either using a distro kernel, or not having updated
to a newer stable kernel. I should not have said "stable", I should have said in updated kernels.
Hi John,
Sorry for the very late reply, and sorry for the confusion. You are right, this was already fixed by 4483efe4f2151; I was working from an outdated tree.
Please drop this patch, I am not sending a v2.
Thanks,
Wentao