Skip to contentSkip to conversation

libsepol: cil_resolve_ast: add in a CIL_SRC_INFO for the copied data

PATCH In review Rahul Sandhu 2 participants 3 messages May 31 – Jun 5 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libsepol: cil_resolve_ast: add in a CIL_SRC_INFO for the copied data

Ownership of the data copied in from an in statement currently resolves up to the parent block. This is because when looking up a corrosponding path with cil_tree_get_cil_path(), the chain is walked up until a valid match is found from cil_tree_get_next_path(). However, as the content that is inserted into the block does not originate from the same file as the file where the block is instantiated, insert a CIL_SRC_INFO node so that for said content it is a src_info node with the original file attached that is matched.

---
 libsepol/cil/src/cil_resolve_ast.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
libsepol/cil/src/cil_resolve_ast.c +23 -0
index 048b3aaa..af612f63 100644
@@ -2375,6 +2375,8 @@ int cil_resolve_in(struct cil_tree_node *current, struct cil_db *db)
 	struct cil_in *in = current->data;
 	struct cil_symtab_datum *block_datum = NULL;
 	struct cil_tree_node *block_node = NULL;
+	struct cil_tree_node *src_node = NULL;
+	struct cil_src_info *info = NULL;
 	int rc = SEPOL_ERR;
 
 	rc = cil_resolve_name(current, in->block_str, CIL_SYM_BLOCKS, db, &block_datum);
@@ -2395,6 +2397,27 @@ int cil_resolve_in(struct cil_tree_node *current, struct cil_db *db)
 		}
 	}
 
+	char *path = cil_tree_get_cil_path(current);
+	if (path != NULL) {
+		cil_src_info_init(&info);
+		info->kind = CIL_KEY_SRC_CIL;
+		info->path = path;
+
+		cil_tree_node_init(&src_node);
+		src_node->parent = block_node;
+		src_node->flavor = CIL_SRC_INFO;
+		src_node->data = info;
+
+		if (block_node->cl_head == NULL) {
+			block_node->cl_head = src_node;
+		} else {
+			block_node->cl_tail->next = src_node;
+		}
+		block_node->cl_tail = src_node;
+
+		block_node = src_node;
+	}
+
 	rc = cil_copy_ast(db, current, block_node);
 	if (rc != SEPOL_OK) {
 		cil_tree_log(current, CIL_ERR, "Failed to copy in-statement");
Signature · 1 line
2.54.0
Acked-by on v1 1/1
#1 lore raw
Quoted 11 lines · Rahul Sandhu

Ownership of the data copied in from an in statement currently resolves up to the parent block. This is because when looking up a corrosponding path with cil_tree_get_cil_path(), the chain is walked up until a valid match is found from cil_tree_get_next_path(). However, as the content that is inserted into the block does not originate from the same file as the file where the block is instantiated, insert a CIL_SRC_INFO node so that for said content it is a src_info node with the original file attached that is matched.

Unsurprisingly, the patch did not apply cleanly after the giant reformatting, but it was simple enough to make it work. I will handle the merge for this patch.
At any rate:

Quoted 48 lines
---
 libsepol/cil/src/cil_resolve_ast.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
libsepol/cil/src/cil_resolve_ast.c +23 -1
index 048b3aaa..af612f63 100644
@@ -2375,6 +2375,8 @@ int cil_resolve_in(struct cil_tree_node *current, struct cil_db *db)
        struct cil_in *in = current->data;
        struct cil_symtab_datum *block_datum = NULL;
        struct cil_tree_node *block_node = NULL;
+       struct cil_tree_node *src_node = NULL;
+       struct cil_src_info *info = NULL;
        int rc = SEPOL_ERR;
 
        rc = cil_resolve_name(current, in->block_str, CIL_SYM_BLOCKS, db, &block_datum);
@@ -2395,6 +2397,27 @@ int cil_resolve_in(struct cil_tree_node *current, struct cil_db *db)
                }
        }
 
+       char *path = cil_tree_get_cil_path(current);
+       if (path != NULL) {
+               cil_src_info_init(&info);
+               info->kind = CIL_KEY_SRC_CIL;
+               info->path = path;
+
+               cil_tree_node_init(&src_node);
+               src_node->parent = block_node;
+               src_node->flavor = CIL_SRC_INFO;
+               src_node->data = info;
+
+               if (block_node->cl_head == NULL) {
+                       block_node->cl_head = src_node;
+               } else {
+                       block_node->cl_tail->next = src_node;
+               }
+               block_node->cl_tail = src_node;
+
+               block_node = src_node;
+       }
+
        rc = cil_copy_ast(db, current, block_node);
        if (rc != SEPOL_OK) {
                cil_tree_log(current, CIL_ERR, "Failed to copy in-statement");
--

2.54.0

#2 lore raw
Quoted 12 lines · James Carter
Quoted 10 lines · Rahul Sandhu

Ownership of the data copied in from an in statement currently resolves up to the parent block. This is because when looking up a corrosponding path with cil_tree_get_cil_path(), the chain is walked up until a valid match is found from cil_tree_get_next_path(). However, as the content that is inserted into the block does not originate from the same file as the file where the block is instantiated, insert a CIL_SRC_INFO node so that for said content it is a src_info node with the original file attached that is matched.

Quoted 9 lines
Quoted 1 line

Unsurprisingly, the patch did not apply cleanly after the giant reformatting, but it was simple enough to make it work. I will handle the merge for this patch.
At any rate:

And it has been merged.
Thanks,
Jim

Quoted 48 lines
Quoted 48 lines
---
 libsepol/cil/src/cil_resolve_ast.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
libsepol/cil/src/cil_resolve_ast.c +23 -1
index 048b3aaa..af612f63 100644
@@ -2375,6 +2375,8 @@ int cil_resolve_in(struct cil_tree_node *current, struct cil_db *db)
        struct cil_in *in = current->data;
        struct cil_symtab_datum *block_datum = NULL;
        struct cil_tree_node *block_node = NULL;
+       struct cil_tree_node *src_node = NULL;
+       struct cil_src_info *info = NULL;
        int rc = SEPOL_ERR;
 
        rc = cil_resolve_name(current, in->block_str, CIL_SYM_BLOCKS, db, &block_datum);
@@ -2395,6 +2397,27 @@ int cil_resolve_in(struct cil_tree_node *current, struct cil_db *db)
                }
        }
 
+       char *path = cil_tree_get_cil_path(current);
+       if (path != NULL) {
+               cil_src_info_init(&info);
+               info->kind = CIL_KEY_SRC_CIL;
+               info->path = path;
+
+               cil_tree_node_init(&src_node);
+               src_node->parent = block_node;
+               src_node->flavor = CIL_SRC_INFO;
+               src_node->data = info;
+
+               if (block_node->cl_head == NULL) {
+                       block_node->cl_head = src_node;
+               } else {
+                       block_node->cl_tail->next = src_node;
+               }
+               block_node->cl_tail = src_node;
+
+               block_node = src_node;
+       }
+
        rc = cil_copy_ast(db, current, block_node);
        if (rc != SEPOL_OK) {
                cil_tree_log(current, CIL_ERR, "Failed to copy in-statement");
--

2.54.0