SELinux: Fix lsm_get_self_attr()
PATCH 1/2 SELinux: Fix lsm_get_self_attr()
selinux_lsm_getattr() may not initialize the value's pointer in some case. As for proc_pid_attr_read(), initialize this pointer to NULL in selinux_getselfattr() to avoid an UAF in the kfree() call.
--- security/selinux/hooks.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
security/selinux/hooks.c +1 -1
@@ -6559,7 +6559,7 @@ static int selinux_getselfattr(unsigned int attr, struct lsm_ctx __user *ctx, size_t *size, u32 flags) { int rc; -char *val; +char *val =NULL ;int val_len; val_len =selinux_lsm_getattr (attr, current, &val);
Signature · 1 line
2.43.0
PATCH 2/2 AppArmor: Fix lsm_get_self_attr()
aa_getprocattr() may not initialize the value's pointer in some case. As for proc_pid_attr_read(), initialize this pointer to NULL in apparmor_getselfattr() to avoid an UAF in the kfree() call.
--- security/apparmor/lsm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
security/apparmor/lsm.c +1 -1
@@ -784,7 +784,7 @@ static int apparmor_getselfattr(unsigned int attr, struct lsm_ctx __user *lx,int error = -ENOENT ;struct aa_task_ctx *ctx =task_ctx (current);struct aa_label *label =NULL ; -char *value; +char *value =NULL ;switch (attr) {case LSM_ATTR_CURRENT :
Signature · 1 line
2.43.0
Paul Moore
maintainerRe: [PATCH 2/2] AppArmor: Fix lsm_get_self_attr()
Quoted 11 lines · Mickaël Salaün
aa_getprocattr()may not initialize the value's pointer in some case. As forproc_pid_attr_read(), initialize this pointer to NULL inapparmor_getselfattr()to avoid an UAF in thekfree()call.Cc Casey Schaufler <[email protected]>Cc John Johansen <[email protected]>Cc Paul Moore <[email protected]>Fixes 223981db9baf ("AppArmor: Add selfattr hooks")Signed-off-by Mickaël Salaün <[email protected]>
Quoted 3 lines
--- security/apparmor/lsm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
If you like John, I can send this up to Linus with the related SELinux fix, I would just need an ACK from you.
Quoted 15 lines
security/apparmor/lsm.c +1
-2@@ -784,7 +784,7 @@ static int apparmor_getselfattr(unsigned int attr, struct lsm_ctx __user *lx,int error = -ENOENT ;struct aa_task_ctx *ctx =task_ctx (current);struct aa_label *label =NULL ; -char *value; +char *value =NULL ;switch (attr) {case LSM_ATTR_CURRENT : --2.43.0
Signature · 1 line
paul-moore.com
Re: [PATCH 2/2] AppArmor: Fix lsm_get_self_attr()
Quoted 16 lines · Paul Moore
Quoted 11 lines · Mickaël Salaün
aa_getprocattr()may not initialize the value's pointer in some case. As forproc_pid_attr_read(), initialize this pointer to NULL inapparmor_getselfattr()to avoid an UAF in thekfree()call.Cc Casey Schaufler <[email protected]>Cc John Johansen <[email protected]>Cc Paul Moore <[email protected]>Fixes 223981db9baf ("AppArmor: Add selfattr hooks")Signed-off-by Mickaël Salaün <[email protected]>Quoted 3 lines
--- security/apparmor/lsm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 2 lines
If you like John, I can send this up to Linus with the related SELinux fix, I would just need an ACK from you.
This patch looks good to me, and while we've still got at least two (maybe three?) more weeks before v6.8 is tagged, I think it would be good to get this up to Linus ASAP. I'll hold off for another day, but if we don't see any comment from John I'll go ahead and merge this and send it up to Linus with the SELinux fix; I'm sure John wouldn't be happy if v6.8 went out the door without this fix.
Quoted 15 lines
Quoted 15 lines
security/apparmor/lsm.c +1
-2@@ -784,7 +784,7 @@ static int apparmor_getselfattr(unsigned int attr, struct lsm_ctx __user *lx,int error = -ENOENT ;struct aa_task_ctx *ctx =task_ctx (current);struct aa_label *label =NULL ; -char *value; +char *value =NULL ;switch (attr) {case LSM_ATTR_CURRENT : --2.43.0
Signature · 1 line
paul-moore.com
Paul Moore
maintainerRe: [PATCH 2/2] AppArmor: Fix lsm_get_self_attr()
Quoted 20 lines · Paul Moore
Quoted 16 lines · Paul Moore
Quoted 11 lines · Mickaël Salaün
aa_getprocattr()may not initialize the value's pointer in some case. As forproc_pid_attr_read(), initialize this pointer to NULL inapparmor_getselfattr()to avoid an UAF in thekfree()call.Cc Casey Schaufler <[email protected]>Cc John Johansen <[email protected]>Cc Paul Moore <[email protected]>Fixes 223981db9baf ("AppArmor: Add selfattr hooks")Signed-off-by Mickaël Salaün <[email protected]>Quoted 3 lines
--- security/apparmor/lsm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Quoted 2 lines
If you like John, I can send this up to Linus with the related SELinux fix, I would just need an ACK from you.
Quoted 8 lines
Reviewed-by Paul Moore <[email protected]>This patch looks good to me, and while we've still got at least two (maybe three?) more weeks before v6.8 is tagged, I think it would be good to get this up to Linus ASAP. I'll hold off for another day, but if we don't see any comment from John I'll go ahead and merge this and send it up to Linus with the SELinux fix; I'm sure John wouldn't be happy if v6.8 went out the door without this fix.
I just merged this into lsm/stable-6.8 and once the automated build/test has done it's thing and come back clean I'll send this, along with the associated SELinux fix, up to Linus. Thanks all.
John, if this commit is problematic please let me know and I'll send a fix or a revert.
Signature · 1 line
paul-moore.com
Paul Moore
maintainerRe: [PATCH 2/2] AppArmor: Fix lsm_get_self_attr()
Quoted 30 lines · Paul Moore
Quoted 20 lines · Paul Moore
Quoted 16 lines · Paul Moore
Quoted 11 lines · Mickaël Salaün
aa_getprocattr()may not initialize the value's pointer in some case. As forproc_pid_attr_read(), initialize this pointer to NULL inapparmor_getselfattr()to avoid an UAF in thekfree()call.Cc Casey Schaufler <[email protected]>Cc John Johansen <[email protected]>Cc Paul Moore <[email protected]>Fixes 223981db9baf ("AppArmor: Add selfattr hooks")Signed-off-by Mickaël Salaün <[email protected]>Quoted 3 lines
--- security/apparmor/lsm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Quoted 2 lines
If you like John, I can send this up to Linus with the related SELinux fix, I would just need an ACK from you.
Quoted 8 lines
Reviewed-by Paul Moore <[email protected]>This patch looks good to me, and while we've still got at least two (maybe three?) more weeks before v6.8 is tagged, I think it would be good to get this up to Linus ASAP. I'll hold off for another day, but if we don't see any comment from John I'll go ahead and merge this and send it up to Linus with the SELinux fix; I'm sure John wouldn't be happy if v6.8 went out the door without this fix.
Quoted 3 lines
I just merged this into lsm/stable-6.8 and once the automated build/test has done it's thing and come back clean I'll send this, along with the associated SELinux fix, up to Linus. Thanks all.
In off-list discussions with Mickaël today it was noted that this patch also needs a fixup to the commit description so I've replaced it with the following:
"In apparmor_getselfattr() when an invalid AppArmor
attribute is requested, or a value hasn't been explicitly set for the requested attribute, the label passed to aa_put_label() is not properly initialized which can cause problems when the pointer value is non-NULL and AppArmor attempts to drop a reference on the bogus label object."
I've updated the commit in lsm/stable-6.8 and I'll be sending it to Linus shortly.
Quoted 2 lines
John, if this commit is problematic please let me know and I'll send a fix or a revert.
Signature · 1 line
paul-moore.com
Paul Moore
maintainerRe: [PATCH 2/2] AppArmor: Fix lsm_get_self_attr()
Quoted 46 lines · Paul Moore
Quoted 30 lines · Paul Moore
Quoted 20 lines · Paul Moore
Quoted 16 lines · Paul Moore
Quoted 11 lines · Mickaël Salaün
aa_getprocattr()may not initialize the value's pointer in some case. As forproc_pid_attr_read(), initialize this pointer to NULL inapparmor_getselfattr()to avoid an UAF in thekfree()call.Cc Casey Schaufler <[email protected]>Cc John Johansen <[email protected]>Cc Paul Moore <[email protected]>Fixes 223981db9baf ("AppArmor: Add selfattr hooks")Signed-off-by Mickaël Salaün <[email protected]>Quoted 3 lines
--- security/apparmor/lsm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Quoted 2 lines
If you like John, I can send this up to Linus with the related SELinux fix, I would just need an ACK from you.
Quoted 8 lines
Reviewed-by Paul Moore <[email protected]>This patch looks good to me, and while we've still got at least two (maybe three?) more weeks before v6.8 is tagged, I think it would be good to get this up to Linus ASAP. I'll hold off for another day, but if we don't see any comment from John I'll go ahead and merge this and send it up to Linus with the SELinux fix; I'm sure John wouldn't be happy if v6.8 went out the door without this fix.
Quoted 3 lines
I just merged this into lsm/stable-6.8 and once the automated build/test has done it's thing and come back clean I'll send this, along with the associated SELinux fix, up to Linus. Thanks all.
In off-list discussions with Mickaël today it was noted that this patch also needs a fixup to the commit description so I've replaced it with the following:
"In
apparmor_getselfattr()when an invalid AppArmor
attribute is requested, or a value hasn't been explicitly set for the requested attribute, the label passed toaa_put_label()is not properly initialized which can cause problems when the pointer value is non-NULL and AppArmor attempts to drop a reference on the bogus label object."
Quoted 5 lines
I've updated the commit in lsm/stable-6.8 and I'll be sending it to Linus shortly.
Quoted 2 lines
John, if this commit is problematic please let me know and I'll send a fix or a revert.
I also just realized that both this patch and the SELinux have the stable kernel marking which shouldn't be necessary as the LSM syscalls are only present in the v6.8-rcX kernels. I'm going to drop the stable tagging, but leave the 'Fixes:' tag of course.
Signature · 1 line
paul-moore.com
Re: [PATCH 2/2] AppArmor: Fix lsm_get_self_attr()
Quoted 50 lines · Paul Moore
Quoted 49 lines · Paul Moore
Quoted 30 lines · Paul Moore
Quoted 20 lines · Paul Moore
Quoted 16 lines · Paul Moore
Quoted 11 lines · Mickaël Salaün
aa_getprocattr()may not initialize the value's pointer in some case. As forproc_pid_attr_read(), initialize this pointer to NULL inapparmor_getselfattr()to avoid an UAF in thekfree()call.Cc Casey Schaufler <[email protected]>Cc John Johansen <[email protected]>Cc Paul Moore <[email protected]>Fixes 223981db9baf ("AppArmor: Add selfattr hooks")Signed-off-by Mickaël Salaün <[email protected]>Quoted 3 lines
--- security/apparmor/lsm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Quoted 2 lines
If you like John, I can send this up to Linus with the related SELinux fix, I would just need an ACK from you.
Quoted 8 lines
Reviewed-by Paul Moore <[email protected]>This patch looks good to me, and while we've still got at least two (maybe three?) more weeks before v6.8 is tagged, I think it would be good to get this up to Linus ASAP. I'll hold off for another day, but if we don't see any comment from John I'll go ahead and merge this and send it up to Linus with the SELinux fix; I'm sure John wouldn't be happy if v6.8 went out the door without this fix.
Quoted 3 lines
I just merged this into lsm/stable-6.8 and once the automated build/test has done it's thing and come back clean I'll send this, along with the associated SELinux fix, up to Linus. Thanks all.
In off-list discussions with Mickaël today it was noted that this patch also needs a fixup to the commit description so I've replaced it with the following:
"In
apparmor_getselfattr()when an invalid AppArmor
attribute is requested, or a value hasn't been explicitly set for the requested attribute, the label passed toaa_put_label()is not properly initialized which can cause problems when the pointer value is non-NULL and AppArmor attempts to drop a reference on the bogus label object."I've updated the commit in lsm/stable-6.8 and I'll be sending it to Linus shortly.
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines
John, if this commit is problematic please let me know and I'll send a fix or a revert.
I also just realized that both this patch and the SELinux have the stable kernel marking which shouldn't be necessary as the LSM syscalls are only present in the v6.8-rcX kernels. I'm going to drop the stable tagging, but leave the 'Fixes:' tag of course.
Looks good, thanks!
Quoted 4 lines
Signature · 2 lines
-- paul-moore.com
John Johansen
maintainerRe: [PATCH 2/2] AppArmor: Fix lsm_get_self_attr()
In reply to Paul MooreQuoted 30 lines · Paul Moore
Quoted 20 lines · Paul Moore
Quoted 16 lines · Paul Moore
Quoted 11 lines · Mickaël Salaün
aa_getprocattr()may not initialize the value's pointer in some case. As forproc_pid_attr_read(), initialize this pointer to NULL inapparmor_getselfattr()to avoid an UAF in thekfree()call.Cc Casey Schaufler <[email protected]>Cc John Johansen <[email protected]>Cc Paul Moore <[email protected]>Fixes 223981db9baf ("AppArmor: Add selfattr hooks")Signed-off-by Mickaël Salaün <[email protected]>Quoted 3 lines
--- security/apparmor/lsm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Quoted 2 lines
If you like John, I can send this up to Linus with the related SELinux fix, I would just need an ACK from you.
Quoted 8 lines
Reviewed-by Paul Moore <[email protected]>This patch looks good to me, and while we've still got at least two (maybe three?) more weeks before v6.8 is tagged, I think it would be good to get this up to Linus ASAP. I'll hold off for another day, but if we don't see any comment from John I'll go ahead and merge this and send it up to Linus with the SELinux fix; I'm sure John wouldn't be happy if v6.8 went out the door without this fix.
Quoted 7 lines
I just merged this into lsm/stable-6.8 and once the automated build/test has done it's thing and come back clean I'll send this, along with the associated SELinux fix, up to Linus. Thanks all.
John, if this commit is problematic please let me know and I'll send a fix or a revert.
sorry, I am still trying to dig out of my backlog. This is good, you can certainly have my ACK, I know its already in tree so no point in adding it there but wanted to just make sure its on list
Paul Moore
maintainerRe: [PATCH 2/2] AppArmor: Fix lsm_get_self_attr()
Quoted 35 lines · John Johansen
Quoted 34 lines · Paul Moore
Quoted 20 lines · Paul Moore
Quoted 16 lines · Paul Moore
Quoted 11 lines · Mickaël Salaün
aa_getprocattr()may not initialize the value's pointer in some case. As forproc_pid_attr_read(), initialize this pointer to NULL inapparmor_getselfattr()to avoid an UAF in thekfree()call.Cc Casey Schaufler <[email protected]>Cc John Johansen <[email protected]>Cc Paul Moore <[email protected]>Fixes 223981db9baf ("AppArmor: Add selfattr hooks")Signed-off-by Mickaël Salaün <[email protected]>Quoted 3 lines
--- security/apparmor/lsm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Quoted 2 lines
If you like John, I can send this up to Linus with the related SELinux fix, I would just need an ACK from you.
Quoted 8 lines
Reviewed-by Paul Moore <[email protected]>This patch looks good to me, and while we've still got at least two (maybe three?) more weeks before v6.8 is tagged, I think it would be good to get this up to Linus ASAP. I'll hold off for another day, but if we don't see any comment from John I'll go ahead and merge this and send it up to Linus with the SELinux fix; I'm sure John wouldn't be happy if v6.8 went out the door without this fix.
I just merged this into lsm/stable-6.8 and once the automated build/test has done it's thing and come back clean I'll send this, along with the associated SELinux fix, up to Linus. Thanks all.
Quoted 6 lines
Quoted 2 lines
John, if this commit is problematic please let me know and I'll send a fix or a revert.
sorry, I am still trying to dig out of my backlog. This is good, you can certainly have my ACK, I know its already in tree so no point in adding it there but wanted to just make sure its on list
No worries, reviews are still appreciated; just because a patch has made its way up to Linus is no guarantee there isn't something wrong with it ;)
Signature · 1 line
paul-moore.com
These bugs have been found with syzkaller. I just sent a PR to add support for the new LSM syscalls:
https://github.com/google/syzkaller/pull/4524
Quoted 29 lines · Mickaël Salaün
selinux_lsm_getattr()may not initialize the value's pointer in some case. As forproc_pid_attr_read(), initialize this pointer to NULL inselinux_getselfattr()to avoid an UAF in thekfree()call.Cc Casey Schaufler <[email protected]>Cc Paul Moore <[email protected]>Fixes 762c934317e6 ("SELinux: Add selfattr hooks")Signed-off-by Mickaël Salaün <[email protected]>--- security/selinux/hooks.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)security/selinux/hooks.c +1
-1@@ -6559,7 +6559,7 @@ static int selinux_getselfattr(unsigned int attr, struct lsm_ctx __user *ctx, size_t *size, u32 flags) { int rc; -char *val; +char *val =NULL ;int val_len; val_len =selinux_lsm_getattr (attr, current, &val);Signature · 1 line
2.43.0
Paul Moore
maintainerQuoted 3 lines · Mickaël Salaün
These bugs have been found with syzkaller. I just sent a PR to add support for the new LSM syscalls:
https://github.com/google/syzkaller/pull/4524
Thanks :)
Signature · 1 line
paul-moore.com
Quoted 3 lines · Mickaël Salaün
selinux_lsm_getattr()may not initialize the value's pointer in some case. As forproc_pid_attr_read(), initialize this pointer to NULL inselinux_getselfattr()to avoid an UAF in thekfree()call.
Not UAF but NULL pointer dereference (both patches)...
Quoted 6 lines · Mickaël Salaün
Quoted 3 lines · Mickaël Salaün
selinux_lsm_getattr()may not initialize the value's pointer in some case. As forproc_pid_attr_read(), initialize this pointer to NULL inselinux_getselfattr()to avoid an UAF in thekfree()call.Not UAF but NULL pointer dereference (both patches)...
Well, that may be the result (as observed with the kfree() call), but the cause is obviously an uninitialized pointer.
Paul Moore
maintainerQuoted 11 lines · Mickaël Salaün
Quoted 6 lines · Mickaël Salaün
Quoted 3 lines · Mickaël Salaün
selinux_lsm_getattr()may not initialize the value's pointer in some case. As forproc_pid_attr_read(), initialize this pointer to NULL inselinux_getselfattr()to avoid an UAF in thekfree()call.Not UAF but NULL pointer dereference (both patches)...
Well, that may be the result (as observed with the
kfree()call), but the cause is obviously an uninitialized pointer.
Adding the SELinux list to the CC line; SELinux folks the original post is here:
* https://lore.kernel.org/all/[email protected]
Thanks for finding this and testing the patch, based on our off-list discussion, do you mind if I add a Suggested-by? Looking at this a bit more I think we'll want to make a few changes to selinux_lsm_getattr() later, but this patch is a good one for stable as it not only fixes the bug, but it is a trivial one-liner with very low risk.
I do think we need to tweak the commit description a bit, what do you think of the following?
"selinux_getselfattr() doesn't properly initialize the string
pointer it passes to selinux_lsm_getattr() which can cause a problem when an attribute hasn't been explicitly set; selinux_lsm_getattr() returns 0/success, but does not set or initialize the string label/attribute. Failure to properly initialize the string causes problems later in selinux_getselfattr() when the function attempts to kfree() the string."
Signature · 1 line
paul-moore.com
Quoted 13 lines · Paul Moore
Quoted 11 lines · Mickaël Salaün
Quoted 6 lines · Mickaël Salaün
Quoted 3 lines · Mickaël Salaün
selinux_lsm_getattr()may not initialize the value's pointer in some case. As forproc_pid_attr_read(), initialize this pointer to NULL inselinux_getselfattr()to avoid an UAF in thekfree()call.Not UAF but NULL pointer dereference (both patches)...
Well, that may be the result (as observed with the
kfree()call), but the cause is obviously an uninitialized pointer.
Quoted 6 lines
Adding the SELinux list to the CC line; SELinux folks the original post is here:
* https://lore.kernel.org/all/[email protected]
Thanks for finding this and testing the patch, based on our off-list discussion, do you mind if I add a Suggested-by? Looking at this a
Sure! I was in a hurry and didn't give it the attention it needed...
Quoted 8 lines
bit more I think we'll want to make a few changes to
selinux_lsm_getattr()later, but this patch is a good one for stable as it not only fixes the bug, but it is a trivial one-liner with very low risk.I do think we need to tweak the commit description a bit, what do you think of the following?
Quoted 8 lines
"
selinux_getselfattr()doesn't properly initialize the string
pointer it passes toselinux_lsm_getattr()which can cause a problem when an attribute hasn't been explicitly set;selinux_lsm_getattr()returns 0/success, but does not set or initialize the string label/attribute. Failure to properly initialize the string causes problems later inselinux_getselfattr()when the function attempts tokfree()the string."
Much better!
Paul Moore
maintainerQuoted 40 lines · Mickaël Salaün
Quoted 13 lines · Paul Moore
Quoted 11 lines · Mickaël Salaün
Quoted 6 lines · Mickaël Salaün
Quoted 3 lines · Mickaël Salaün
selinux_lsm_getattr()may not initialize the value's pointer in some case. As forproc_pid_attr_read(), initialize this pointer to NULL inselinux_getselfattr()to avoid an UAF in thekfree()call.Not UAF but NULL pointer dereference (both patches)...
Well, that may be the result (as observed with the
kfree()call), but the cause is obviously an uninitialized pointer.Quoted 6 lines
Adding the SELinux list to the CC line; SELinux folks the original post is here:
* https://lore.kernel.org/all/[email protected]
Thanks for finding this and testing the patch, based on our off-list discussion, do you mind if I add a Suggested-by? Looking at this a
Sure! I was in a hurry and didn't give it the attention it needed...
Quoted 8 lines
bit more I think we'll want to make a few changes to
selinux_lsm_getattr()later, but this patch is a good one for stable as it not only fixes the bug, but it is a trivial one-liner with very low risk.I do think we need to tweak the commit description a bit, what do you think of the following?
Quoted 8 lines
"
selinux_getselfattr()doesn't properly initialize the string
pointer it passes toselinux_lsm_getattr()which can cause a problem when an attribute hasn't been explicitly set;selinux_lsm_getattr()returns 0/success, but does not set or initialize the string label/attribute. Failure to properly initialize the string causes problems later inselinux_getselfattr()when the function attempts tokfree()the string."
Quoted 1 line
Much better!
Great :) I just went ahead and merged this into the lsm/stable-6.8 branch to get this some testing in linux-next, although I'm going to be *shocked* if this commit causes a regression. I'll send this up to Linus early next week, and if John wants me to send the AppArmor patch I'll do that at the same time.
Signature · 1 line
paul-moore.com