Skip to contentSkip to conversation

libsepol: Check for proper length of addr and mask buffers

PATCH In review James Carter 2 participants 3 messages Jun 16 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 libsepol: Check for proper length of addr and mask buffers

When creating an ocontext node the addr and mask buffers lengths are not being checked that they are the correct value for the protocol.

Verify that the addr and mask buffer lengths are the correct vaalue for the protocol and output an error if they are not.

---
v3: Use sizeof(tmp_node->u.node.mask) and sizeof(tmp_node->u.node6.mask)
v2: Use sizeof instead of 4 or 16

 libsepol/src/nodes.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
libsepol/src/nodes.c +16 -0
index e3ad36a8..5471d701 100644
@@ -34,10 +34,26 @@ static int node_from_record(sepol_handle_t *handle, const policydb_t *policydb,
 
 	switch (proto) {
 	case SEPOL_PROTO_IP4:
+		if (addr_bsize != sizeof(tmp_node->u.node.addr)) {
+			ERR(handle, "Wrong address size for IPv4 address");
+			goto err;
+		}
+		if (mask_bsize != sizeof(tmp_node->u.node.mask)) {
+			ERR(handle, "Wrong address size for IPv4 mask");
+			goto err;
+		}
 		memcpy(&tmp_node->u.node.addr, addr_buf, addr_bsize);
 		memcpy(&tmp_node->u.node.mask, mask_buf, mask_bsize);
 		break;
 	case SEPOL_PROTO_IP6:
+		if (addr_bsize != sizeof(tmp_node->u.node6.addr)) {
+			ERR(handle, "Wrong address size for IPv6 address");
+			goto err;
+		}
+		if (mask_bsize != sizeof(tmp_node->u.node6.mask)) {
+			ERR(handle, "Wrong address size for IPv6 mask");
+			goto err;
+		}
 		memcpy(tmp_node->u.node6.addr, addr_buf, addr_bsize);
 		memcpy(tmp_node->u.node6.mask, mask_buf, mask_bsize);
 		break;
Signature · 1 line
2.54.0
maintainer Acked-by on v3 1/1
#1 lore raw
Quoted 9 lines · James Carter

When creating an ocontext node the addr and mask buffers lengths are not being checked that they are the correct value for the protocol.

Verify that the addr and mask buffer lengths are the correct vaalue for the protocol and output an error if they are not.

Quoted 41 lines

---
v3: Use sizeof(tmp_node->u.node.mask) and sizeof(tmp_node->u.node6.mask)
v2: Use sizeof instead of 4 or 16

 libsepol/src/nodes.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
libsepol/src/nodes.c +16 -1
index e3ad36a8..5471d701 100644
@@ -34,10 +34,26 @@ static int node_from_record(sepol_handle_t *handle, const policydb_t *policydb,
 
        switch (proto) {
        case SEPOL_PROTO_IP4:
+               if (addr_bsize != sizeof(tmp_node->u.node.addr)) {
+                       ERR(handle, "Wrong address size for IPv4 address");
+                       goto err;
+               }
+               if (mask_bsize != sizeof(tmp_node->u.node.mask)) {
+                       ERR(handle, "Wrong address size for IPv4 mask");
+                       goto err;
+               }
                memcpy(&tmp_node->u.node.addr, addr_buf, addr_bsize);
                memcpy(&tmp_node->u.node.mask, mask_buf, mask_bsize);
                break;
        case SEPOL_PROTO_IP6:
+               if (addr_bsize != sizeof(tmp_node->u.node6.addr)) {
+                       ERR(handle, "Wrong address size for IPv6 address");
+                       goto err;
+               }
+               if (mask_bsize != sizeof(tmp_node->u.node6.mask)) {
+                       ERR(handle, "Wrong address size for IPv6 mask");
+                       goto err;
+               }
                memcpy(tmp_node->u.node6.addr, addr_buf, addr_bsize);
                memcpy(tmp_node->u.node6.mask, mask_buf, mask_bsize);
                break;
--

2.54.0

maintainer
#2 lore raw
Quoted 7 lines · Stephen Smalley
Quoted 5 lines · James Carter

When creating an ocontext node the addr and mask buffers lengths are not being checked that they are the correct value for the protocol.

Quoted 6 lines
Quoted 4 lines

Verify that the addr and mask buffer lengths are the correct vaalue for the protocol and output an error if they are not.

Merged.