diff mbox series

selinux: keep context struct members in sync

Message ID 20230511123148.722343-1-cgzones@googlemail.com (mailing list archive)
State Accepted
Delegated to: Paul Moore
Headers show
Series selinux: keep context struct members in sync | expand

Commit Message

Christian Göttsche May 11, 2023, 12:31 p.m. UTC
Commit 53f3517ae087 ("selinux: do not leave dangling pointer behind")
reset the `str` field of the `context` struct in an OOM error branch.
In this struct the fields `str` and `len` are coupled and should be kept
in sync.  Set the length to zero according to the string be set to NULL.

Fixes: 53f3517ae087 ("selinux: do not leave dangling pointer behind")
Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
---
 security/selinux/ss/context.h | 1 +
 1 file changed, 1 insertion(+)

Comments

Paul Moore May 18, 2023, 5:39 p.m. UTC | #1
On May 11, 2023 =?UTF-8?q?Christian=20G=C3=B6ttsche?= <cgzones@googlemail.com> wrote:
> 
> Commit 53f3517ae087 ("selinux: do not leave dangling pointer behind")
> reset the `str` field of the `context` struct in an OOM error branch.
> In this struct the fields `str` and `len` are coupled and should be kept
> in sync.  Set the length to zero according to the string be set to NULL.
> 
> Fixes: 53f3517ae087 ("selinux: do not leave dangling pointer behind")
> Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
> ---
>  security/selinux/ss/context.h | 1 +
>  1 file changed, 1 insertion(+)

Merged into selinux/next, thanks.

--
paul-moore.com
diff mbox series

Patch

diff --git a/security/selinux/ss/context.h b/security/selinux/ss/context.h
index 44179977f434..aed704b8c642 100644
--- a/security/selinux/ss/context.h
+++ b/security/selinux/ss/context.h
@@ -168,6 +168,7 @@  static inline int context_cpy(struct context *dst, const struct context *src)
 	if (rc) {
 		kfree(dst->str);
 		dst->str = NULL;
+		dst->len = 0;
 		return rc;
 	}
 	return 0;