libsepol: Check for proper length of addr and mask buffers
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
@@ -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
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.
Signed-off-by James Carter <[email protected]>
Quoted 41 lines
---
v3: Usesizeof(tmp_node->u.node.mask)andsizeof(tmp_node->u.node6.mask)
v2: Use sizeof instead of 4 or 16libsepol/src/nodes.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)libsepol/src/nodes.c +16
-1@@ -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
Stephen Smalley
maintainerQuoted 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.
Signed-off-by James Carter <[email protected]>Acked-by Stephen Smalley <[email protected]>
Merged.