Blame SOURCES/edk2-CryptoPkg-Crt-turn-strchr-into-a-function-CVE-2019-1.patch

6009e6
From 697cb1880b624f83bc9e926c3614d070eb365f06 Mon Sep 17 00:00:00 2001
6009e6
From: Laszlo Ersek <lersek@redhat.com>
6009e6
Date: Mon, 2 Dec 2019 12:31:47 +0100
6009e6
Subject: [PATCH 3/9] CryptoPkg/Crt: turn strchr() into a function
6009e6
 (CVE-2019-14553)
6009e6
MIME-Version: 1.0
6009e6
Content-Type: text/plain; charset=UTF-8
6009e6
Content-Transfer-Encoding: 8bit
6009e6
6009e6
RH-Author: Laszlo Ersek <lersek@redhat.com>
6009e6
Message-id: <20191117220052.15700-4-lersek@redhat.com>
6009e6
Patchwork-id: 92458
6009e6
O-Subject: [RHEL-8.2.0 edk2 PATCH 3/9] CryptoPkg/Crt: turn strchr() into a function (CVE-2019-14553)
6009e6
Bugzilla: 1536624
6009e6
RH-Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
6009e6
RH-Acked-by: Vitaly Kuznetsov <vkuznets@redhat.com>
6009e6
6009e6
According to the ISO C standard, strchr() is a function. We #define it as
6009e6
a macro. Unfortunately, our macro evaluates the first argument ("str")
6009e6
twice. If the expression passed for "str" has side effects, the behavior
6009e6
may be undefined.
6009e6
6009e6
In a later patch in this series, we're going to resurrect "inet_pton.c"
6009e6
(originally from the StdLib package), which calls strchr() just like that:
6009e6
6009e6
  strchr((xdigits = xdigits_l), ch)
6009e6
  strchr((xdigits = xdigits_u), ch)
6009e6
6009e6
To enable this kind of function call, turn strchr() into a function.
6009e6
6009e6
Cc: David Woodhouse <dwmw2@infradead.org>
6009e6
Cc: Jian J Wang <jian.j.wang@intel.com>
6009e6
Cc: Jiaxin Wu <jiaxin.wu@intel.com>
6009e6
Cc: Sivaraman Nainar <sivaramann@amiindia.co.in>
6009e6
Cc: Xiaoyu Lu <xiaoyux.lu@intel.com>
6009e6
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=960
6009e6
CVE: CVE-2019-14553
6009e6
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
6009e6
Reviewed-by: Philippe Mathieu-Daude <philmd@redhat.com>
6009e6
Reviewed-by: Jian J Wang <jian.j.wang@intel.com>
6009e6
Reviewed-by: Jiaxin Wu <jiaxin.wu@intel.com>
6009e6
(cherry picked from commit eb520d94dba7369d1886cd5522d5a2c36fb02209)
6009e6
---
6009e6
 CryptoPkg/Library/BaseCryptLib/SysCall/CrtWrapper.c | 5 +++++
6009e6
 CryptoPkg/Library/Include/CrtLibSupport.h           | 2 +-
6009e6
 2 files changed, 6 insertions(+), 1 deletion(-)
6009e6
6009e6
diff --git a/CryptoPkg/Library/BaseCryptLib/SysCall/CrtWrapper.c b/CryptoPkg/Library/BaseCryptLib/SysCall/CrtWrapper.c
6009e6
index 71a2ef3..42235ab 100644
6009e6
--- a/CryptoPkg/Library/BaseCryptLib/SysCall/CrtWrapper.c
6009e6
+++ b/CryptoPkg/Library/BaseCryptLib/SysCall/CrtWrapper.c
6009e6
@@ -115,6 +115,11 @@ QuickSortWorker (
6009e6
 // -- String Manipulation Routines --
6009e6
 //
6009e6
 
6009e6
+char *strchr(const char *str, int ch)
6009e6
+{
6009e6
+  return ScanMem8 (str, AsciiStrSize (str), (UINT8)ch);
6009e6
+}
6009e6
+
6009e6
 /* Scan a string for the last occurrence of a character */
6009e6
 char *strrchr (const char *str, int c)
6009e6
 {
6009e6
diff --git a/CryptoPkg/Library/Include/CrtLibSupport.h b/CryptoPkg/Library/Include/CrtLibSupport.h
6009e6
index 5806f50..b90da20 100644
6009e6
--- a/CryptoPkg/Library/Include/CrtLibSupport.h
6009e6
+++ b/CryptoPkg/Library/Include/CrtLibSupport.h
6009e6
@@ -147,6 +147,7 @@ int            isupper     (int);
6009e6
 int            tolower     (int);
6009e6
 int            strcmp      (const char *, const char *);
6009e6
 int            strncasecmp (const char *, const char *, size_t);
6009e6
+char           *strchr     (const char *, int);
6009e6
 char           *strrchr    (const char *, int);
6009e6
 unsigned long  strtoul     (const char *, char **, int);
6009e6
 long           strtol      (const char *, char **, int);
6009e6
@@ -188,7 +189,6 @@ void           abort       (void);
6009e6
 #define strcpy(strDest,strSource)         AsciiStrCpyS(strDest,MAX_STRING_SIZE,strSource)
6009e6
 #define strncpy(strDest,strSource,count)  AsciiStrnCpyS(strDest,MAX_STRING_SIZE,strSource,(UINTN)count)
6009e6
 #define strcat(strDest,strSource)         AsciiStrCatS(strDest,MAX_STRING_SIZE,strSource)
6009e6
-#define strchr(str,ch)                    ScanMem8((VOID *)(str),AsciiStrSize(str),(UINT8)ch)
6009e6
 #define strncmp(string1,string2,count)    (int)(AsciiStrnCmp(string1,string2,(UINTN)(count)))
6009e6
 #define strcasecmp(str1,str2)             (int)AsciiStriCmp(str1,str2)
6009e6
 #define sprintf(buf,...)                  AsciiSPrint(buf,MAX_STRING_SIZE,__VA_ARGS__)
6009e6
-- 
6009e6
1.8.3.1
6009e6