From 430207c9cf87ca0a1e82fcb9915ad890a8e5720f Mon Sep 17 00:00:00 2001 From: Tudor Florea Date: Tue, 7 Jul 2015 00:26:20 +0200 Subject: curl: CVE-2014-3707 CVE-2014-3707, libcurl duphandle read out of bounds libcurl's function curl_easy_duphandle() has a bug that can lead to libcurl eventually sending off sensitive data that was not intended for sending. Reference http://curl.haxx.se/docs/adv_20141105.html Signed-off-by: Sona Sarmadi Signed-off-by: Tudor Florea --- meta/recipes-support/curl/curl/CVE-2014-3707.patch | 402 +++++++++++++++++++++ meta/recipes-support/curl/curl_7.35.0.bb | 1 + 2 files changed, 403 insertions(+) create mode 100644 meta/recipes-support/curl/curl/CVE-2014-3707.patch diff --git a/meta/recipes-support/curl/curl/CVE-2014-3707.patch b/meta/recipes-support/curl/curl/CVE-2014-3707.patch new file mode 100644 index 0000000000..9604fbd81b --- /dev/null +++ b/meta/recipes-support/curl/curl/CVE-2014-3707.patch @@ -0,0 +1,402 @@ +curl_easy_duphandle: CURLOPT_COPYPOSTFIELDS read out of + bounds + +When duplicating a handle, the data to post was duplicated using +strdup() when it could be binary and contain zeroes and it was not even +zero terminated! This caused read out of bounds crashes/segfaults. + +Since the lib/strdup.c file no longer is easily shared with the curl +tool with this change, it now uses its own version instead. + +Bug: http://curl.haxx.se/docs/adv_20141105.html +CVE: CVE-2014-3707 + +Reported-By: Symeon Paraschoudis + +Upstream-Status: Backport +Signed-off-by: Sona Sarmadi + +diff -ruN a/lib/formdata.c b/lib/formdata.c +--- a/lib/formdata.c 2014-01-05 23:07:54.000000000 +0100 ++++ b/lib/formdata.c 2015-05-18 09:13:49.767861474 +0200 +@@ -36,6 +36,7 @@ + #include "strequal.h" + #include "curl_memory.h" + #include "sendf.h" ++#include "strdup.h" + + #define _MPRINTF_REPLACE /* use our functions only */ + #include +@@ -214,46 +215,6 @@ + + /*************************************************************************** + * +- * memdup() +- * +- * Copies the 'source' data to a newly allocated buffer buffer (that is +- * returned). Uses buffer_length if not null, else uses strlen to determine +- * the length of the buffer to be copied +- * +- * Returns the new pointer or NULL on failure. +- * +- ***************************************************************************/ +-static char *memdup(const char *src, size_t buffer_length) +-{ +- size_t length; +- bool add = FALSE; +- char *buffer; +- +- if(buffer_length) +- length = buffer_length; +- else if(src) { +- length = strlen(src); +- add = TRUE; +- } +- else +- /* no length and a NULL src pointer! */ +- return strdup(""); +- +- buffer = malloc(length+add); +- if(!buffer) +- return NULL; /* fail */ +- +- memcpy(buffer, src, length); +- +- /* if length unknown do null termination */ +- if(add) +- buffer[length] = '\0'; +- +- return buffer; +-} +- +-/*************************************************************************** +- * + * FormAdd() + * + * Stores a formpost parameter and builds the appropriate linked list. +@@ -682,9 +643,13 @@ + (form == first_form) ) { + /* Note that there's small risk that form->name is NULL here if the + app passed in a bad combo, so we better check for that first. */ +- if(form->name) ++ if(form->name) { + /* copy name (without strdup; possibly contains null characters) */ +- form->name = memdup(form->name, form->namelength); ++ form->name = Curl_memdup(form->name, form->namelength? ++ form->namelength: ++ strlen(form->name)+1); ++ } ++ + if(!form->name) { + return_value = CURL_FORMADD_MEMORY; + break; +@@ -695,7 +660,9 @@ + HTTPPOST_PTRCONTENTS | HTTPPOST_PTRBUFFER | + HTTPPOST_CALLBACK)) ) { + /* copy value (without strdup; possibly contains null characters) */ +- form->value = memdup(form->value, form->contentslength); ++ form->value = Curl_memdup(form->value, form->contentslength? ++ form->contentslength: ++ strlen(form->value)+1); + if(!form->value) { + return_value = CURL_FORMADD_MEMORY; + break; +diff -ruN a/lib/strdup.c b/lib/strdup.c +--- a/lib/strdup.c 2013-09-09 00:11:15.000000000 +0200 ++++ b/lib/strdup.c 2015-05-18 09:05:27.641416906 +0200 +@@ -5,7 +5,7 @@ + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * +- * Copyright (C) 1998 - 2012, Daniel Stenberg, , et al. ++ * Copyright (C) 1998 - 2014, Daniel Stenberg, , et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms +@@ -19,12 +19,12 @@ + * KIND, either express or implied. + * + ***************************************************************************/ +-/* +- * This file is 'mem-include-scan' clean. See test 1132. +- */ + #include "curl_setup.h" +- + #include "strdup.h" ++#include "curl_memory.h" ++ ++/* The last #include file should be: */ ++#include "memdebug.h" + + #ifndef HAVE_STRDUP + char *curlx_strdup(const char *str) +@@ -50,3 +50,25 @@ + + } + #endif ++ ++/*************************************************************************** ++ * ++ * Curl_memdup(source, length) ++ * ++ * Copies the 'source' data to a newly allocated buffer (that is ++ * returned). Copies 'length' bytes. ++ * ++ * Returns the new pointer or NULL on failure. ++ * ++ ***************************************************************************/ ++char *Curl_memdup(const char *src, size_t length) ++{ ++ char *buffer = malloc(length); ++ if(!buffer) ++ return NULL; /* fail */ ++ ++ memcpy(buffer, src, length); ++ ++ /* if length unknown do null termination */ ++ return buffer; ++} +diff -ruN a/lib/strdup.h b/lib/strdup.h +--- a/lib/strdup.h 2013-09-09 00:11:15.000000000 +0200 ++++ b/lib/strdup.h 2015-05-18 09:05:27.645416733 +0200 +@@ -7,7 +7,7 @@ + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * +- * Copyright (C) 1998 - 2010, Daniel Stenberg, , et al. ++ * Copyright (C) 1998 - 2014, Daniel Stenberg, , et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms +@@ -26,5 +26,6 @@ + #ifndef HAVE_STRDUP + extern char *curlx_strdup(const char *str); + #endif ++char *Curl_memdup(const char *src, size_t buffer_length); + + #endif /* HEADER_CURL_STRDUP_H */ +diff -ruN a/lib/url.c b/lib/url.c +--- a/lib/url.c 2014-01-29 07:54:29.000000000 +0100 ++++ b/lib/url.c 2015-05-18 09:31:00.631682330 +0200 +@@ -125,6 +125,7 @@ + #include "multihandle.h" + #include "pipeline.h" + #include "dotdot.h" ++#include "strdup.h" + + #define _MPRINTF_REPLACE /* use our functions only */ + #include +@@ -270,8 +271,9 @@ + { + /* Free all dynamic strings stored in the data->set substructure. */ + enum dupstring i; +- for(i=(enum dupstring)0; i < STRING_LAST; i++) ++ for(i=(enum dupstring)0; i < STRING_LAST; i++) { + Curl_safefree(data->set.str[i]); ++ } + + if(data->change.referer_alloc) { + Curl_safefree(data->change.referer); +@@ -340,7 +342,7 @@ + + CURLcode Curl_dupset(struct SessionHandle *dst, struct SessionHandle *src) + { +- CURLcode r = CURLE_OK; ++ CURLcode result = CURLE_OK; + enum dupstring i; + + /* Copy src->set into dst->set first, then deal with the strings +@@ -351,14 +353,25 @@ + memset(dst->set.str, 0, STRING_LAST * sizeof(char *)); + + /* duplicate all strings */ +- for(i=(enum dupstring)0; i< STRING_LAST; i++) { +- r = setstropt(&dst->set.str[i], src->set.str[i]); +- if(r != CURLE_OK) +- break; ++ for(i=(enum dupstring)0; i< STRING_LASTZEROTERMINATED; i++) { ++ result = setstropt(&dst->set.str[i], src->set.str[i]); ++ if(result) ++ return result; ++ } ++ ++ /* duplicate memory areas pointed to */ ++ i = STRING_COPYPOSTFIELDS; ++ if(src->set.postfieldsize && src->set.str[i]) { ++ /* postfieldsize is curl_off_t, Curl_memdup() takes a size_t ... */ ++ dst->set.str[i] = Curl_memdup(src->set.str[i], ++ curlx_sotouz(src->set.postfieldsize)); ++ if(!dst->set.str[i]) ++ return CURLE_OUT_OF_MEMORY; ++ /* point to the new copy */ ++ dst->set.postfields = dst->set.str[i]; + } + +- /* If a failure occurred, freeing has to be performed externally. */ +- return r; ++ return CURLE_OK; + } + + /* +diff -ruN a/lib/urldata.h b/lib/urldata.h +--- a/lib/urldata.h 2014-01-26 22:16:50.000000000 +0100 ++++ b/lib/urldata.h 2015-05-18 09:05:27.649416562 +0200 +@@ -1332,7 +1332,6 @@ + STRING_KRB_LEVEL, /* krb security level */ + STRING_NETRC_FILE, /* if not NULL, use this instead of trying to find + $HOME/.netrc */ +- STRING_COPYPOSTFIELDS, /* if POST, set the fields' values here */ + STRING_PROXY, /* proxy to use */ + STRING_SET_RANGE, /* range, if used */ + STRING_SET_REFERER, /* custom string for the HTTP referer field */ +@@ -1374,7 +1373,15 @@ + + STRING_BEARER, /* , if used */ + +- /* -- end of strings -- */ ++ /* -- end of zero-terminated strings -- */ ++ ++ STRING_LASTZEROTERMINATED, ++ ++ /* -- below this are pointers to binary data that cannot be strdup'ed. ++ Each such pointer must be added manually to Curl_dupset() --- */ ++ ++ STRING_COPYPOSTFIELDS, /* if POST, set the fields' values here */ ++ + STRING_LAST /* not used, just an end-of-list marker */ + }; + +diff -ruN a/src/Makefile.inc b/src/Makefile.inc +--- a/src/Makefile.inc 2013-09-09 00:11:15.000000000 +0200 ++++ b/src/Makefile.inc 2015-05-18 09:38:28.124528175 +0200 +@@ -11,7 +11,6 @@ + # the official API, but we re-use the code here to avoid duplication. + CURLX_ONES = \ + ../lib/strtoofft.c \ +- ../lib/strdup.c \ + ../lib/rawstr.c \ + ../lib/nonblock.c + +@@ -46,6 +45,7 @@ + tool_panykey.c \ + tool_paramhlp.c \ + tool_parsecfg.c \ ++ tool_strdup.c \ + tool_setopt.c \ + tool_sleep.c \ + tool_urlglob.c \ +@@ -90,6 +90,7 @@ + tool_setopt.h \ + tool_setup.h \ + tool_sleep.h \ ++ tool_strdup.h \ + tool_urlglob.h \ + tool_util.h \ + tool_version.h \ +diff -ruN a/src/tool_setup.h b/src/tool_setup.h +--- a/src/tool_setup.h 2013-09-09 00:11:15.000000000 +0200 ++++ b/src/tool_setup.h 2015-05-18 09:05:27.649416562 +0200 +@@ -7,7 +7,7 @@ + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * +- * Copyright (C) 1998 - 2012, Daniel Stenberg, , et al. ++ * Copyright (C) 1998 - 2014, Daniel Stenberg, , et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms +@@ -67,8 +67,7 @@ + #endif + + #ifndef HAVE_STRDUP +-# include "strdup.h" +-# define strdup(ptr) curlx_strdup(ptr) ++# include "tool_strdup.h" + #endif + + #endif /* HEADER_CURL_TOOL_SETUP_H */ +diff -ruN a/src/tool_strdup.c b/src/tool_strdup.c +--- a/src/tool_strdup.c 1970-01-01 01:00:00.000000000 +0100 ++++ b/src/tool_strdup.c 2015-05-18 09:05:27.649416562 +0200 +@@ -0,0 +1,47 @@ ++/*************************************************************************** ++ * _ _ ____ _ ++ * Project ___| | | | _ \| | ++ * / __| | | | |_) | | ++ * | (__| |_| | _ <| |___ ++ * \___|\___/|_| \_\_____| ++ * ++ * Copyright (C) 1998 - 2014, Daniel Stenberg, , et al. ++ * ++ * This software is licensed as described in the file COPYING, which ++ * you should have received as part of this distribution. The terms ++ * are also available at http://curl.haxx.se/docs/copyright.html. ++ * ++ * You may opt to use, copy, modify, merge, publish, distribute and/or sell ++ * copies of the Software, and permit persons to whom the Software is ++ * furnished to do so, under the terms of the COPYING file. ++ * ++ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY ++ * KIND, either express or implied. ++ * ++ ***************************************************************************/ ++#include "strdup.h" ++ ++#ifndef HAVE_STRDUP ++char *strdup(const char *str) ++{ ++ size_t len; ++ char *newstr; ++ ++ if(!str) ++ return (char *)NULL; ++ ++ len = strlen(str); ++ ++ if(len >= ((size_t)-1) / sizeof(char)) ++ return (char *)NULL; ++ ++ newstr = malloc((len+1)*sizeof(char)); ++ if(!newstr) ++ return (char *)NULL; ++ ++ memcpy(newstr,str,(len+1)*sizeof(char)); ++ ++ return newstr; ++ ++} ++#endif +diff -ruN a/src/tool_strdup.h b/src/tool_strdup.h +--- a/src/tool_strdup.h 1970-01-01 01:00:00.000000000 +0100 ++++ b/src/tool_strdup.h 2015-05-18 09:05:27.653416391 +0200 +@@ -0,0 +1,30 @@ ++#ifndef HEADER_TOOL_STRDUP_H ++#define HEADER_TOOL_STRDUP_H ++/*************************************************************************** ++ * _ _ ____ _ ++ * Project ___| | | | _ \| | ++ * / __| | | | |_) | | ++ * | (__| |_| | _ <| |___ ++ * \___|\___/|_| \_\_____| ++ * ++ * Copyright (C) 1998 - 2014, Daniel Stenberg, , et al. ++ * ++ * This software is licensed as described in the file COPYING, which ++ * you should have received as part of this distribution. The terms ++ * are also available at http://curl.haxx.se/docs/copyright.html. ++ * ++ * You may opt to use, copy, modify, merge, publish, distribute and/or sell ++ * copies of the Software, and permit persons to whom the Software is ++ * furnished to do so, under the terms of the COPYING file. ++ * ++ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY ++ * KIND, either express or implied. ++ * ++ ***************************************************************************/ ++#include "tool_setup.h" ++ ++#ifndef HAVE_STRDUP ++extern char *strdup(const char *str); ++#endif ++ ++#endif /* HEADER_TOOL_STRDUP_H */ diff --git a/meta/recipes-support/curl/curl_7.35.0.bb b/meta/recipes-support/curl/curl_7.35.0.bb index 3021dec11f..5fa7277449 100644 --- a/meta/recipes-support/curl/curl_7.35.0.bb +++ b/meta/recipes-support/curl/curl_7.35.0.bb @@ -13,6 +13,7 @@ SRC_URI = "http://curl.haxx.se/download/curl-${PV}.tar.bz2 \ file://pkgconfig_fix.patch \ file://CVE-2014-3613.patch \ file://CVE-2014-3620.patch \ + file://CVE-2014-3707.patch \ " # curl likes to set -g0 in CFLAGS, so we stop it -- cgit v1.2.3-54-g00ecf