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