checkpolicy: fix double free of fstype in define_genfs_context_helper
PATCH 1/1 checkpolicy: fix double free of fstype in define_genfs_context_helper
From: Md Shafiuzzaman <[email protected]>
When parsing a new filesystem type, define_genfs_context_helper() transfers ownership of fstype into a genfs struct linked into the policydb's genfs list, but does not clear the local fstype. A later goto fail then frees it, leaving a dangling pointer that policydb_destroy() frees again.
Clear fstype after the ownership transfer, mirroring the else branch.
--- checkpolicy/policy_define.c | 2 ++ 1 file changed, 2 insertions(+)
checkpolicy/policy_define.c +2 -0
@@ -6054,6 +6054,8 @@ static int define_genfs_context_helper(char *fstype, int has_type)return -1 ; } newgenfs->fstype = fstype; +/* ownership transferred into the genfs list; do not free on error */ + fstype =NULL ; newgenfs->next = genfs;if (genfs_p) genfs_p->next = newgenfs;
Signature · 1 line
2.54.0
Quoted 8 lines · shafiuzzaman-md
From: Md Shafiuzzaman <[email protected]>
When parsing a new filesystem type,
define_genfs_context_helper()transfers ownership of fstype into a genfs struct linked into the policydb's genfs list, but does not clear the local fstype. A later goto fail then frees it, leaving a dangling pointer thatpolicydb_destroy()frees again.
Quoted 4 lines
Clear fstype after the ownership transfer, mirroring the else branch.
Reported-by Md Shafiuzzaman <[email protected]>Signed-off-by Md Shafiuzzaman <[email protected]>
Quoted 20 lines
--- checkpolicy/policy_define.c | 2 ++ 1 file changed, 2 insertions(+)checkpolicy/policy_define.c +2
-1@@ -6054,6 +6054,8 @@ static int define_genfs_context_helper(char *fstype, int has_type)return -1 ; } newgenfs->fstype = fstype; +/* ownership transferred into the genfs list; do not free on error */ + fstype =NULL ; newgenfs->next = genfs;if (genfs_p) genfs_p->next = newgenfs; --2.54.0
Quoted 11 lines · Stephen Smalley
Quoted 8 lines · shafiuzzaman-md
From: Md Shafiuzzaman <[email protected]>
When parsing a new filesystem type,
define_genfs_context_helper()transfers ownership of fstype into a genfs struct linked into the policydb's genfs list, but does not clear the local fstype. A later goto fail then frees it, leaving a dangling pointer thatpolicydb_destroy()frees again.
Quoted 7 lines
Quoted 4 lines
Clear fstype after the ownership transfer, mirroring the else branch.
Reported-by Md Shafiuzzaman <[email protected]>Signed-off-by Md Shafiuzzaman <[email protected]>Acked-by Stephen Smalley <[email protected]>
This has been merged.
Thanks,
Jim
Quoted 21 lines
Quoted 20 lines
--- checkpolicy/policy_define.c | 2 ++ 1 file changed, 2 insertions(+)checkpolicy/policy_define.c +2
-1@@ -6054,6 +6054,8 @@ static int define_genfs_context_helper(char *fstype, int has_type)return -1 ; } newgenfs->fstype = fstype; +/* ownership transferred into the genfs list; do not free on error */ + fstype =NULL ; newgenfs->next = genfs;if (genfs_p) genfs_p->next = newgenfs; --2.54.0