Skip to content

Commit

Permalink
libsepol/cil: Fix anonymous IP address call arguments
Browse files Browse the repository at this point in the history
A named IP address (using an ipaddr rule) could be passed as an
argument, but trying to pass an actual IP address caused an error.

As an exmample, consider the following portion of a policy.
  (macro m4 ((ipaddr ip)(ipaddr nm))
    (nodecon ip nm (USER ROLE TYPE ((s0) (s0))))
  )
  (ipaddr nm1 255.255.255.0)
  (ipaddr ip1 1.2.3.4)
  (call m4 (ip1 nm1)) ; This works
  (call m4 (1.2.3.4 255.255.255.0)) ; This doesn't

Allow actual IP addresses to be passed as a call argument. Now the
second call works as well.

Signed-off-by: James Carter <jwcart2@gmail.com>
Acked-by: Nicolas Iooss <nicolas.iooss@m4x.org>
  • Loading branch information
jwcart2 committed Jun 22, 2021
1 parent 6bff61c commit 9ac9d2d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
4 changes: 0 additions & 4 deletions libsepol/cil/src/cil_build_ast.c
Expand Up @@ -5642,10 +5642,6 @@ int cil_fill_ipaddr(struct cil_tree_node *addr_node, struct cil_ipaddr *addr)
goto exit;
}

if (addr_node->cl_head != NULL || addr_node->next != NULL) {
goto exit;
}

if (strchr(addr_node->data, '.') != NULL) {
addr->family = AF_INET;
} else {
Expand Down
23 changes: 10 additions & 13 deletions libsepol/cil/src/cil_resolve_ast.c
Expand Up @@ -3024,33 +3024,30 @@ static int cil_build_call_args(struct cil_tree_node *call_node, struct cil_call
break;
}
case CIL_IPADDR: {
if (arg_node->cl_head != NULL) {
if (arg_node->data == NULL) {
cil_tree_log(call_node, CIL_ERR, "Invalid macro parameter");
cil_destroy_args(arg);
rc = SEPOL_ERR;
goto exit;
} else if (strchr(arg_node->data, '.') || strchr(arg_node->data, ':')) {
struct cil_ipaddr *ipaddr = NULL;
struct cil_tree_node *addr_node = NULL;
cil_ipaddr_init(&ipaddr);

rc = cil_fill_ipaddr(arg_node->cl_head, ipaddr);
rc = cil_fill_ipaddr(arg_node, ipaddr);
if (rc != SEPOL_OK) {
cil_log(CIL_ERR, "Failed to create anonymous ip address, rc: %d\n", rc);
cil_tree_log(call_node, CIL_ERR, "Failed to create anonymous ip address");
cil_destroy_ipaddr(ipaddr);
cil_destroy_args(arg);
goto exit;
}
cil_tree_node_init(&addr_node);
addr_node->flavor = CIL_IPADDR;
addr_node->data = ipaddr;
cil_list_append(((struct cil_symtab_datum*)ipaddr)->nodes,
CIL_LIST_ITEM, addr_node);
arg->arg = (struct cil_symtab_datum*)ipaddr;
} else if (arg_node->data == NULL) {
cil_tree_log(call_node, CIL_ERR, "Invalid macro parameter");
cil_destroy_args(arg);
rc = SEPOL_ERR;
goto exit;
cil_list_append(DATUM(ipaddr)->nodes, CIL_LIST_ITEM, addr_node);
arg->arg = DATUM(ipaddr);
} else {
arg->arg_str = arg_node->data;
}

break;
}
case CIL_CLASS:
Expand Down

0 comments on commit 9ac9d2d

Please sign in to comment.