libsepol: Check for proper length of addr and mask buffers
PATCH 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.
--- 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 !=4 ) { +ERR (handle,"Wrong address size for IPv4 address" ); + goto err; + } +if (mask_bsize !=4 ) { +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 !=16 ) { +ERR (handle,"Wrong address size for IPv6 address" ); + goto err; + } +if (mask_bsize !=16 ) { +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 18 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]>--- libsepol/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 37
Quoted 4 lines
libsepol/src/nodes.c +1
-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 !=4 ) {
s/4/sizeof(tmp_node->u.node.addr)/ is a bit more general
libsepol/src/nodes.c static int node_from_record(sepol_handle_t *handle, const policydb_t *policydb, · line 41
Quoted 4 lines
libsepol/src/nodes.c +4
-0+ERR (handle,"Wrong address size for IPv4 address" ); + goto err; + } +if (mask_bsize !=4 ) {
s/4/sizeof(tmp_node->u.node.mask)/ is a bit more general
libsepol/src/nodes.c static int node_from_record(sepol_handle_t *handle, const policydb_t *policydb, · line 49
Quoted 8 lines
libsepol/src/nodes.c +4
-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 !=16 ) {
s/4/sizeof(tmp_node->u.node6.addr)/ is a bit more general
libsepol/src/nodes.c static int node_from_record(sepol_handle_t *handle, const policydb_t *policydb, · line 53
Quoted 4 lines
libsepol/src/nodes.c +4
-0+ERR (handle,"Wrong address size for IPv6 address" ); + goto err; + } +if (mask_bsize !=16 ) {
s/4/sizeof(tmp_node->u.node6.mask)/ is a bit more general
Quoted 10 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