From: "Jan Beulich" Subject: [PATCH 1/2] Revert "lzo: properly check for overruns" Date: Mon, 03 Nov 2014 15:01:59 +0000 Message-ID: <5457A6F702000078000447A6@mail.emea.novell.com> References: <5457A3AD020000780004478B@mail.emea.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part04310AF7.1__=" Return-path: Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1XlJ8v-0003lW-0h for xen-devel@lists.xenproject.org; Mon, 03 Nov 2014 15:02:05 +0000 In-Reply-To: <5457A3AD020000780004478B@mail.emea.novell.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel Cc: Ian Campbell , Keir Fraser , Ian Jackson , Tim Deegan List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__Part04310AF7.1__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline This reverts commit 504f70b6 ("lzo: properly check for overruns"). As analysed by Willem Pinckaers, this fix is still incomplete on certain rare corner cases, and it is easier to restart from the original code. Reported-by: Willem Pinckaers Signed-off-by: Willy Tarreau [original Linux commit: af958a38] Signed-off-by: Jan Beulich --- a/xen/common/lzo.c +++ b/xen/common/lzo.c @@ -375,31 +375,11 @@ int lzo1x_1_compress(const unsigned char * Richard Purdie */ =20 -#define HAVE_IP(t, x) \ - (((size_t)(ip_end - ip) >=3D (size_t)(t + x)) && \ - (((t + x) >=3D t) && ((t + x) >=3D x))) - -#define HAVE_OP(t, x) \ - (((size_t)(op_end - op) >=3D (size_t)(t + x)) && \ - (((t + x) >=3D t) && ((t + x) >=3D x))) - -#define NEED_IP(t, x) \ - do { \ - if (!HAVE_IP(t, x)) \ - goto input_overrun; \ - } while (0) - -#define NEED_OP(t, x) \ - do { \ - if (!HAVE_OP(t, x)) \ - goto output_overrun; \ - } while (0) - -#define TEST_LB(m_pos) \ - do { \ - if ((m_pos) < out) \ - goto lookbehind_overrun; \ - } while (0) +#define HAVE_IP(x) ((size_t)(ip_end - ip) >=3D (size_t)(x)) +#define HAVE_OP(x) ((size_t)(op_end - op) >=3D (size_t)(x)) +#define NEED_IP(x) if (!HAVE_IP(x)) goto input_overrun +#define NEED_OP(x) if (!HAVE_OP(x)) goto output_overrun +#define TEST_LB(m_pos) if ((m_pos) < out) goto lookbehind_overrun =20 int lzo1x_decompress_safe(const unsigned char *in, size_t in_len, unsigned char *out, size_t *out_len) @@ -434,14 +414,14 @@ int lzo1x_decompress_safe(const unsigned while (unlikely(*ip =3D=3D 0)) { t +=3D 255; ip++; - NEED_IP(1, 0); + NEED_IP(1); } t +=3D 15 + *ip++; } t +=3D 3; copy_literal_run: #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) - if (likely(HAVE_IP(t, 15) && HAVE_OP(t, 15))) { + if (likely(HAVE_IP(t + 15) && HAVE_OP(t + 15))) { const unsigned char *ie =3D ip + t; unsigned char *oe =3D op + t; do { @@ -457,8 +437,8 @@ int lzo1x_decompress_safe(const unsigned } else #endif { - NEED_OP(t, 0); - NEED_IP(t, 3); + NEED_OP(t); + NEED_IP(t + 3); do { *op++ =3D *ip++; } while (--t > 0); @@ -471,7 +451,7 @@ int lzo1x_decompress_safe(const unsigned m_pos -=3D t >> 2; m_pos -=3D *ip++ << 2; TEST_LB(m_pos); - NEED_OP(2, 0); + NEED_OP(2); op[0] =3D m_pos[0]; op[1] =3D m_pos[1]; op +=3D 2; @@ -495,10 +475,10 @@ int lzo1x_decompress_safe(const unsigned while (unlikely(*ip =3D=3D 0)) { t +=3D 255; ip++; - NEED_IP(1, 0); + NEED_IP(1); } t +=3D 31 + *ip++; - NEED_IP(2, 0); + NEED_IP(2); } m_pos =3D op - 1; next =3D get_unaligned_le16(ip); @@ -513,10 +493,10 @@ int lzo1x_decompress_safe(const unsigned while (unlikely(*ip =3D=3D 0)) { t +=3D 255; ip++; - NEED_IP(1, 0); + NEED_IP(1); } t +=3D 7 + *ip++; - NEED_IP(2, 0); + NEED_IP(2); } next =3D get_unaligned_le16(ip); ip +=3D 2; @@ -530,7 +510,7 @@ int lzo1x_decompress_safe(const unsigned #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) if (op - m_pos >=3D 8) { unsigned char *oe =3D op + t; - if (likely(HAVE_OP(t, 15))) { + if (likely(HAVE_OP(t + 15))) { do { COPY8(op, m_pos); op +=3D 8; @@ -540,7 +520,7 @@ int lzo1x_decompress_safe(const unsigned m_pos +=3D 8; } while (op < oe); op =3D oe; - if (HAVE_IP(6, 0)) { + if (HAVE_IP(6)) { state =3D next; COPY4(op, ip); op +=3D next; @@ -548,7 +528,7 @@ int lzo1x_decompress_safe(const unsigned continue; } } else { - NEED_OP(t, 0); + NEED_OP(t); do { *op++ =3D *m_pos++; } while (op < oe); @@ -557,7 +537,7 @@ int lzo1x_decompress_safe(const unsigned #endif { unsigned char *oe =3D op + t; - NEED_OP(t, 0); + NEED_OP(t); op[0] =3D m_pos[0]; op[1] =3D m_pos[1]; op +=3D 2; @@ -570,15 +550,15 @@ int lzo1x_decompress_safe(const unsigned state =3D next; t =3D next; #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) - if (likely(HAVE_IP(6, 0) && HAVE_OP(4, 0))) { + if (likely(HAVE_IP(6) && HAVE_OP(4))) { COPY4(op, ip); op +=3D t; ip +=3D t; } else #endif { - NEED_IP(t, 3); - NEED_OP(t, 0); + NEED_IP(t + 3); + NEED_OP(t); while (t > 0) { *op++ =3D *ip++; t--; --=__Part04310AF7.1__= Content-Type: text/plain; name="lzo-revert-504f70b6.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="lzo-revert-504f70b6.patch" Revert "lzo: properly check for overruns"=0A=0AThis reverts commit = 504f70b6 ("lzo: properly check for overruns").=0A=0AAs analysed by Willem = Pinckaers, this fix is still incomplete on=0Acertain rare corner cases, = and it is easier to restart from the=0Aoriginal code.=0A=0AReported-by: = Willem Pinckaers =0ASigned-off-by: Willy Tarreau = =0A[original Linux commit: af958a38]=0ASigned-off-by: Jan = Beulich =0A=0A--- a/xen/common/lzo.c=0A+++ b/xen/common/= lzo.c=0A@@ -375,31 +375,11 @@ int lzo1x_1_compress(const unsigned char=0A = * Richard Purdie =0A */=0A =0A-#define HAVE_IP(t,= x) \=0A- (((size_t)(ip_end - ip) >=3D = (size_t)(t + x)) && \=0A- (((t + x) >=3D t) && ((t + x) >=3D = x)))=0A-=0A-#define HAVE_OP(t, x) \=0A- = (((size_t)(op_end - op) >=3D (size_t)(t + x)) && \=0A- (((t + x) >=3D = t) && ((t + x) >=3D x)))=0A-=0A-#define NEED_IP(t, x) \=0A- = do { \=0A- if (!HAVE_IP(t, x)) = \=0A- goto input_overrun; \=0A- } while (0)=0A-=0A-#d= efine NEED_OP(t, x) \=0A- do { = \=0A- if (!HAVE_OP(t, x)) \=0A- goto = output_overrun; \=0A- } while (0)=0A-=0A-#define TEST_LB(m_pos) = \=0A- do { \=0A- if = ((m_pos) < out) \=0A- goto lookbehind_overrun; \=0A- = } while (0)=0A+#define HAVE_IP(x) ((size_t)(ip_end - ip) >=3D = (size_t)(x))=0A+#define HAVE_OP(x) ((size_t)(op_end - op) >=3D = (size_t)(x))=0A+#define NEED_IP(x) if (!HAVE_IP(x)) goto input_overrun= =0A+#define NEED_OP(x) if (!HAVE_OP(x)) goto output_overrun=0A+#define = TEST_LB(m_pos) if ((m_pos) < out) goto lookbehind_overrun=0A =0A int = lzo1x_decompress_safe(const unsigned char *in, size_t in_len,=0A = unsigned char *out, size_t *out_len)=0A@@ -434,14 +414,14 = @@ int lzo1x_decompress_safe(const unsigned=0A while = (unlikely(*ip =3D=3D 0)) {=0A t +=3D 255;=0A = ip++;=0A- NEED_IP(1, 0);=0A+ = NEED_IP(1);=0A }=0A = t +=3D 15 + *ip++;=0A }=0A t +=3D 3;=0A = copy_literal_run:=0A #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)= =0A- if (likely(HAVE_IP(t, 15) && HAVE_OP(t, 15))) {=0A+ = if (likely(HAVE_IP(t + 15) && HAVE_OP(t + 15))) {=0A = const unsigned char *ie =3D ip + t;=0A = unsigned char *oe =3D op + t;=0A do {=0A@@ -457,8 = +437,8 @@ int lzo1x_decompress_safe(const unsigned=0A } = else=0A #endif=0A {=0A- NEED_OP(t, = 0);=0A- NEED_IP(t, 3);=0A+ NEED_OP(t)= ;=0A+ NEED_IP(t + 3);=0A do {=0A = *op++ =3D *ip++;=0A } while (--t = > 0);=0A@@ -471,7 +451,7 @@ int lzo1x_decompress_safe(const unsigned=0A = m_pos -=3D t >> 2;=0A m_pos -=3D *ip++ << = 2;=0A TEST_LB(m_pos);=0A- NEED_OP(2, = 0);=0A+ NEED_OP(2);=0A op[0] =3D = m_pos[0];=0A op[1] =3D m_pos[1];=0A op = +=3D 2;=0A@@ -495,10 +475,10 @@ int lzo1x_decompress_safe(const unsigned=0A= while (unlikely(*ip =3D=3D 0)) {=0A t = +=3D 255;=0A ip++;=0A- NEED_IP(1, = 0);=0A+ NEED_IP(1);=0A }=0A = t +=3D 31 + *ip++;=0A- NEED_IP(2, 0);=0A+ = NEED_IP(2);=0A }=0A m_pos =3D op - 1;=0A = next =3D get_unaligned_le16(ip);=0A@@ -513,10 +493,10 @@ int lzo1x_decom= press_safe(const unsigned=0A while (unlikely(*ip =3D=3D = 0)) {=0A t +=3D 255;=0A ip++;=0A- = NEED_IP(1, 0);=0A+ NEED_IP(1);=0A = }=0A t +=3D 7 + *ip++;=0A- = NEED_IP(2, 0);=0A+ NEED_IP(2);=0A }=0A = next =3D get_unaligned_le16(ip);=0A ip +=3D 2;=0A@@ -530,7 = +510,7 @@ int lzo1x_decompress_safe(const unsigned=0A #if defined(CONFIG_HA= VE_EFFICIENT_UNALIGNED_ACCESS)=0A if (op - m_pos >=3D 8) {=0A = unsigned char *oe =3D op + t;=0A- if (likely(HAVE_OP(t, = 15))) {=0A+ if (likely(HAVE_OP(t + 15))) {=0A = do {=0A COPY8(op, m_pos);=0A op = +=3D 8;=0A@@ -540,7 +520,7 @@ int lzo1x_decompress_safe(const unsigned=0A = m_pos +=3D 8;=0A } while (op < oe);=0A = op =3D oe;=0A- if (HAVE_IP(6, 0)) {=0A+ = if (HAVE_IP(6)) {=0A state =3D next;=0A = COPY4(op, ip);=0A op +=3D next;=0A@@ = -548,7 +528,7 @@ int lzo1x_decompress_safe(const unsigned=0A = continue;=0A }=0A } else {=0A- = NEED_OP(t, 0);=0A+ NEED_OP(t);=0A do = {=0A *op++ =3D *m_pos++;=0A } while = (op < oe);=0A@@ -557,7 +537,7 @@ int lzo1x_decompress_safe(const = unsigned=0A #endif=0A {=0A unsigned char *oe =3D op + = t;=0A- NEED_OP(t, 0);=0A+ NEED_OP(t);=0A = op[0] =3D m_pos[0];=0A op[1] =3D m_pos[1];=0A op = +=3D 2;=0A@@ -570,15 +550,15 @@ int lzo1x_decompress_safe(const unsigned=0A= state =3D next;=0A t =3D next;=0A #if defined(CONFIG_HAVE_= EFFICIENT_UNALIGNED_ACCESS)=0A- if (likely(HAVE_IP(6, 0) && = HAVE_OP(4, 0))) {=0A+ if (likely(HAVE_IP(6) && HAVE_OP(4))) {=0A = COPY4(op, ip);=0A op +=3D t;=0A ip +=3D = t;=0A } else=0A #endif=0A {=0A- NEED_IP(t, = 3);=0A- NEED_OP(t, 0);=0A+ NEED_IP(t + 3);=0A+ = NEED_OP(t);=0A while (t > 0) {=0A *op++ = =3D *ip++;=0A t--;=0A --=__Part04310AF7.1__= 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.xen.org http://lists.xen.org/xen-devel --=__Part04310AF7.1__=--