From: Stefan Berger Subject: [XEN][ACM] Check offset to be within the buffer's size Date: Fri, 23 Mar 2007 22:37:58 -0400 Message-ID: <1174703878.3380.3.camel@941e-2.watson.ibm.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-LEpe9pKqBEHEruvWP4Jj" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel List-Id: xen-devel@lists.xenproject.org --=-LEpe9pKqBEHEruvWP4Jj Content-Type: text/plain Content-Transfer-Encoding: 7bit This patch adds checks to make sure that offsets don't point beyond the end of the buffer. Signed-off-by: Stefan Berger --=-LEpe9pKqBEHEruvWP4Jj Content-Disposition: attachment; filename=acm_offset_check.diff Content-Type: text/x-patch; name=acm_offset_check.diff; charset=UTF-8 Content-Transfer-Encoding: 7bit Index: root/xen-unstable.hg/xen/acm/acm_policy.c =================================================================== --- root.orig/xen-unstable.hg/xen/acm/acm_policy.c +++ root/xen-unstable.hg/xen/acm/acm_policy.c @@ -62,6 +62,7 @@ int do_acm_set_policy(void *buf, u32 buf_size) { struct acm_policy_buffer *pol = (struct acm_policy_buffer *)buf; + uint32_t offset, length; /* some sanity checking */ if ((be32_to_cpu(pol->magic) != ACM_MAGIC) || (buf_size != be32_to_cpu(pol->len)) || @@ -92,22 +93,27 @@ do_acm_set_policy(void *buf, u32 buf_siz /* get bin_policy lock and rewrite policy (release old one) */ write_lock(&acm_bin_pol_rwlock); + offset = be32_to_cpu(pol->policy_reference_offset); + length = be32_to_cpu(pol->primary_buffer_offset) - offset; + /* set label reference name */ - if (acm_set_policy_reference(buf + be32_to_cpu(pol->policy_reference_offset), - be32_to_cpu(pol->primary_buffer_offset) - - be32_to_cpu(pol->policy_reference_offset))) + if ( (offset + length) > buf_size || + acm_set_policy_reference(buf + offset, length)) goto error_lock_free; /* set primary policy data */ - if (acm_primary_ops->set_binary_policy(buf + be32_to_cpu(pol->primary_buffer_offset), - be32_to_cpu(pol->secondary_buffer_offset) - - be32_to_cpu(pol->primary_buffer_offset))) + offset = be32_to_cpu(pol->primary_buffer_offset); + length = be32_to_cpu(pol->secondary_buffer_offset) - offset; + + if ( (offset + length) > buf_size || + acm_primary_ops->set_binary_policy(buf + offset, length)) goto error_lock_free; /* set secondary policy data */ - if (acm_secondary_ops->set_binary_policy(buf + be32_to_cpu(pol->secondary_buffer_offset), - be32_to_cpu(pol->len) - - be32_to_cpu(pol->secondary_buffer_offset))) + offset = be32_to_cpu(pol->secondary_buffer_offset); + length = be32_to_cpu(pol->len) - offset; + if ( (offset + length) > buf_size || + acm_secondary_ops->set_binary_policy(buf + offset, length)) goto error_lock_free; write_unlock(&acm_bin_pol_rwlock); --=-LEpe9pKqBEHEruvWP4Jj Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --=-LEpe9pKqBEHEruvWP4Jj--