Skip to contentSkip to conversation

libsepol: Check for proper length of addr and mask buffers

PATCH Superseded James Carter 2 participants 2 messages Jun 16 SELinux security module

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 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.

---
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..0596f387 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.addr)) {
+			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.addr)) {
+			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
#1 lore raw
Quoted 6 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

nit: spelling (vaalue->value)

Quoted 14 lines

for the protocol and output an error if they are not.

---
v2: Use sizeof instead of 4 or 16

 libsepol/src/nodes.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
libsepol/src/nodes.c +0 -0
index e3ad36a8..0596f387 100644

libsepol/src/nodes.c static int node_from_record(sepol_handle_t *handle, const policydb_t *policydb, · line 41

Quoted 8 lines
libsepol/src/nodes.c +5 -0
@@ -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.addr)) {

Technically this should be node.mask rather than node.addr since that is what is being copied, but
they are the same of course.

libsepol/src/nodes.c static int node_from_record(sepol_handle_t *handle, const policydb_t *policydb, · line 53

Quoted 12 lines
libsepol/src/nodes.c +8 -0
+                       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.addr)) {

Ditto - should be node6.mask rather than node6.addr.

Quoted 9 lines
libsepol/src/nodes.c +3 -1
+                       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