diff options
| author | Vinay Kumar <vinay.m.engg@gmail.com> | 2021-07-02 04:22:38 -0700 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2021-07-20 19:05:45 +0100 |
| commit | db00b0a059013a19b333fd291bde8cee71fc6a11 (patch) | |
| tree | 8fdcfb2a65d4d717b550615d18b8151f7de5741e /meta/recipes-devtools | |
| parent | 8d4748254e020954cdb7e6c866bb0ab0f2407db5 (diff) | |
| download | poky-db00b0a059013a19b333fd291bde8cee71fc6a11.tar.gz | |
binutils: Fix CVE-2021-20197
Source: git://sourceware.org/git/binutils-gdb.git
Tracking -- https://sourceware.org/bugzilla/show_bug.cgi?id=26945
Backported upstream commit id d3edaa91d4cf7202ec14342410194841e2f67f12
and its dependent commits 8e03235147a9e774d3ba084e93c2da1aa94d1cec and
8b69e61d4be276bb862698aaafddc3e779d23c8f to binutils-2.36 source.
Upstream-Status: Backport [https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=8e03235147a9e774d3ba084e93c2da1aa94d1cec]
Upstream-Status: Backport [https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=d3edaa91d4cf7202ec14342410194841e2f67f12]
Upstream-Status: Backport [https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=8b69e61d4be276bb862698aaafddc3e779d23c8f]
(From OE-Core rev: f5f831c3a76456bce543d42d0f14411b28770b45)
Signed-off-by: Vinay Kumar <vinay.m.engg@gmail.com>
Signed-off-by: Anuj Mittal <anuj.mittal@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/recipes-devtools')
4 files changed, 545 insertions, 0 deletions
diff --git a/meta/recipes-devtools/binutils/binutils-2.36.inc b/meta/recipes-devtools/binutils/binutils-2.36.inc index 2968291889..9d770db5a8 100644 --- a/meta/recipes-devtools/binutils/binutils-2.36.inc +++ b/meta/recipes-devtools/binutils/binutils-2.36.inc | |||
| @@ -41,5 +41,8 @@ SRC_URI = "\ | |||
| 41 | file://0014-Fix-rpath-in-libtool-when-sysroot-is-enabled.patch \ | 41 | file://0014-Fix-rpath-in-libtool-when-sysroot-is-enabled.patch \ |
| 42 | file://0015-sync-with-OE-libtool-changes.patch \ | 42 | file://0015-sync-with-OE-libtool-changes.patch \ |
| 43 | file://0016-Check-for-clang-before-checking-gcc-version.patch \ | 43 | file://0016-Check-for-clang-before-checking-gcc-version.patch \ |
| 44 | file://0001-CVE-2021-20197.patch \ | ||
| 45 | file://0002-CVE-2021-20197.patch \ | ||
| 46 | file://0003-CVE-2021-20197.patch \ | ||
| 44 | " | 47 | " |
| 45 | S = "${WORKDIR}/git" | 48 | S = "${WORKDIR}/git" |
diff --git a/meta/recipes-devtools/binutils/binutils/0001-CVE-2021-20197.patch b/meta/recipes-devtools/binutils/binutils/0001-CVE-2021-20197.patch new file mode 100644 index 0000000000..2b4eaba26d --- /dev/null +++ b/meta/recipes-devtools/binutils/binutils/0001-CVE-2021-20197.patch | |||
| @@ -0,0 +1,201 @@ | |||
| 1 | From 8e03235147a9e774d3ba084e93c2da1aa94d1cec Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Siddhesh Poyarekar <siddhesh@gotplt.org> | ||
| 3 | Date: Mon, 22 Feb 2021 20:45:50 +0530 | ||
| 4 | Subject: [PATCH] binutils: Avoid renaming over existing files | ||
| 5 | |||
| 6 | Renaming over existing files needs additional care to restore | ||
| 7 | permissions and ownership, which may not always succeed. | ||
| 8 | Additionally, other properties of the file such as extended attributes | ||
| 9 | may be lost, making the operation flaky. | ||
| 10 | |||
| 11 | For predictable results, resort to rename() only if the file does not | ||
| 12 | exist, otherwise copy the file contents into the existing file. This | ||
| 13 | ensures that no additional tricks are needed to retain file | ||
| 14 | properties. | ||
| 15 | |||
| 16 | This also allows dropping of the redundant set_times on the tmpfile in | ||
| 17 | objcopy/strip since now we no longer rename over existing files. | ||
| 18 | |||
| 19 | binutils/ | ||
| 20 | |||
| 21 | * ar.c (write_archive): Adjust call to SMART_RENAME. | ||
| 22 | * arsup.c (ar_save): Likewise. | ||
| 23 | * objcopy (strip_main): Don't set times on temporary file and | ||
| 24 | adjust call to SMART_RENAME. | ||
| 25 | (copy_main): Likewise. | ||
| 26 | * rename.c [!S_ISLNK]: Remove definitions. | ||
| 27 | (try_preserve_permissions): Remove function. | ||
| 28 | (smart_rename): Replace PRESERVE_DATES argument with | ||
| 29 | TARGET_STAT. Use rename system call only if TO does not exist. | ||
| 30 | * bucomm.h (smart_rename): Adjust declaration. | ||
| 31 | |||
| 32 | (cherry picked from commit 3685de750e6a091663a0abe42528cad29e960e35) | ||
| 33 | |||
| 34 | Upstream-Status: Backport [https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=8e03235147a9e774d3ba084e93c2da1aa94d1cec] | ||
| 35 | CVE: CVE-2021-20197 | ||
| 36 | Signed-off-by: Vinay Kumar <vinay.m.engg@gmail.com> | ||
| 37 | --- | ||
| 38 | binutils/ar.c | 2 +- | ||
| 39 | binutils/arsup.c | 2 +- | ||
| 40 | binutils/bucomm.h | 3 ++- | ||
| 41 | binutils/objcopy.c | 8 ++----- | ||
| 42 | binutils/rename.c | 55 +++++++++------------------------------------- | ||
| 43 | 6 files changed, 29 insertions(+), 54 deletions(-) | ||
| 44 | |||
| 45 | diff --git a/binutils/ar.c b/binutils/ar.c | ||
| 46 | index 45a34e3a6cf..3a91708b51c 100644 | ||
| 47 | --- a/binutils/ar.c | ||
| 48 | +++ b/binutils/ar.c | ||
| 49 | @@ -1308,7 +1308,7 @@ write_archive (bfd *iarch) | ||
| 50 | /* We don't care if this fails; we might be creating the archive. */ | ||
| 51 | bfd_close (iarch); | ||
| 52 | |||
| 53 | - if (smart_rename (new_name, old_name, 0) != 0) | ||
| 54 | + if (smart_rename (new_name, old_name, NULL) != 0) | ||
| 55 | xexit (1); | ||
| 56 | free (old_name); | ||
| 57 | free (new_name); | ||
| 58 | diff --git a/binutils/arsup.c b/binutils/arsup.c | ||
| 59 | index 5403a0c5d74..0a1f63f6456 100644 | ||
| 60 | --- a/binutils/arsup.c | ||
| 61 | +++ b/binutils/arsup.c | ||
| 62 | @@ -351,7 +351,7 @@ ar_save (void) | ||
| 63 | |||
| 64 | bfd_close (obfd); | ||
| 65 | |||
| 66 | - smart_rename (ofilename, real_name, 0); | ||
| 67 | + smart_rename (ofilename, real_name, NULL); | ||
| 68 | obfd = 0; | ||
| 69 | free (ofilename); | ||
| 70 | } | ||
| 71 | diff --git a/binutils/bucomm.h b/binutils/bucomm.h | ||
| 72 | index 91f6a5b228f..aa7e33d8cd1 100644 | ||
| 73 | --- a/binutils/bucomm.h | ||
| 74 | +++ b/binutils/bucomm.h | ||
| 75 | @@ -71,7 +71,8 @@ extern void print_version (const char *); | ||
| 76 | /* In rename.c. */ | ||
| 77 | extern void set_times (const char *, const struct stat *); | ||
| 78 | |||
| 79 | -extern int smart_rename (const char *, const char *, int); | ||
| 80 | +extern int smart_rename (const char *, const char *, struct stat *); | ||
| 81 | + | ||
| 82 | |||
| 83 | /* In libiberty. */ | ||
| 84 | void *xmalloc (size_t); | ||
| 85 | diff --git a/binutils/objcopy.c b/binutils/objcopy.c | ||
| 86 | index eab3b6db585..07a872b5a80 100644 | ||
| 87 | --- a/binutils/objcopy.c | ||
| 88 | +++ b/binutils/objcopy.c | ||
| 89 | @@ -4861,12 +4861,10 @@ strip_main (int argc, char *argv[]) | ||
| 90 | output_target, NULL); | ||
| 91 | if (status == 0) | ||
| 92 | { | ||
| 93 | - if (preserve_dates) | ||
| 94 | - set_times (tmpname, &statbuf); | ||
| 95 | if (output_file != tmpname) | ||
| 96 | status = (smart_rename (tmpname, | ||
| 97 | output_file ? output_file : argv[i], | ||
| 98 | - preserve_dates) != 0); | ||
| 99 | + preserve_dates ? &statbuf : NULL) != 0); | ||
| 100 | if (status == 0) | ||
| 101 | status = hold_status; | ||
| 102 | } | ||
| 103 | @@ -5931,11 +5929,9 @@ copy_main (int argc, char *argv[]) | ||
| 104 | output_target, input_arch); | ||
| 105 | if (status == 0) | ||
| 106 | { | ||
| 107 | - if (preserve_dates) | ||
| 108 | - set_times (tmpname, &statbuf); | ||
| 109 | if (tmpname != output_filename) | ||
| 110 | status = (smart_rename (tmpname, input_filename, | ||
| 111 | - preserve_dates) != 0); | ||
| 112 | + preserve_dates ? &statbuf : NULL) != 0); | ||
| 113 | } | ||
| 114 | else | ||
| 115 | unlink_if_ordinary (tmpname); | ||
| 116 | diff --git a/binutils/rename.c b/binutils/rename.c | ||
| 117 | index 65ad5bf52c4..f471b45fd3f 100644 | ||
| 118 | --- a/binutils/rename.c | ||
| 119 | +++ b/binutils/rename.c | ||
| 120 | @@ -122,20 +122,13 @@ set_times (const char *destination, const struct stat *statbuf) | ||
| 121 | non_fatal (_("%s: cannot set time: %s"), destination, strerror (errno)); | ||
| 122 | } | ||
| 123 | |||
| 124 | -#ifndef S_ISLNK | ||
| 125 | -#ifdef S_IFLNK | ||
| 126 | -#define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK) | ||
| 127 | -#else | ||
| 128 | -#define S_ISLNK(m) 0 | ||
| 129 | -#define lstat stat | ||
| 130 | -#endif | ||
| 131 | -#endif | ||
| 132 | - | ||
| 133 | -/* Rename FROM to TO, copying if TO is a link. | ||
| 134 | - Return 0 if ok, -1 if error. */ | ||
| 135 | +/* Rename FROM to TO, copying if TO exists. TARGET_STAT has the file status | ||
| 136 | + that, if non-NULL, is used to fix up timestamps after rename. Return 0 if | ||
| 137 | + ok, -1 if error. */ | ||
| 138 | |||
| 139 | int | ||
| 140 | -smart_rename (const char *from, const char *to, int preserve_dates ATTRIBUTE_UNUSED) | ||
| 141 | +smart_rename (const char *from, const char *to, | ||
| 142 | + struct stat *target_stat ATTRIBUTE_UNUSED) | ||
| 143 | { | ||
| 144 | bfd_boolean exists; | ||
| 145 | struct stat s; | ||
| 146 | @@ -158,38 +151,10 @@ smart_rename (const char *from, const char *to, int preserve_dates ATTRIBUTE_UNU | ||
| 147 | unlink (from); | ||
| 148 | } | ||
| 149 | #else | ||
| 150 | - /* Use rename only if TO is not a symbolic link and has | ||
| 151 | - only one hard link, and we have permission to write to it. */ | ||
| 152 | - if (! exists | ||
| 153 | - || (!S_ISLNK (s.st_mode) | ||
| 154 | - && S_ISREG (s.st_mode) | ||
| 155 | - && (s.st_mode & S_IWUSR) | ||
| 156 | - && s.st_nlink == 1) | ||
| 157 | - ) | ||
| 158 | + /* Avoid a full copy and use rename if TO does not exist. */ | ||
| 159 | + if (!exists) | ||
| 160 | { | ||
| 161 | - ret = rename (from, to); | ||
| 162 | - if (ret == 0) | ||
| 163 | - { | ||
| 164 | - if (exists) | ||
| 165 | - { | ||
| 166 | - /* Try to preserve the permission bits and ownership of | ||
| 167 | - TO. First get the mode right except for the setuid | ||
| 168 | - bit. Then change the ownership. Then fix the setuid | ||
| 169 | - bit. We do the chmod before the chown because if the | ||
| 170 | - chown succeeds, and we are a normal user, we won't be | ||
| 171 | - able to do the chmod afterward. We don't bother to | ||
| 172 | - fix the setuid bit first because that might introduce | ||
| 173 | - a fleeting security problem, and because the chown | ||
| 174 | - will clear the setuid bit anyhow. We only fix the | ||
| 175 | - setuid bit if the chown succeeds, because we don't | ||
| 176 | - want to introduce an unexpected setuid file owned by | ||
| 177 | - the user running objcopy. */ | ||
| 178 | - chmod (to, s.st_mode & 0777); | ||
| 179 | - if (chown (to, s.st_uid, s.st_gid) >= 0) | ||
| 180 | - chmod (to, s.st_mode & 07777); | ||
| 181 | - } | ||
| 182 | - } | ||
| 183 | - else | ||
| 184 | + if ((ret = rename (from, to)) != 0) | ||
| 185 | { | ||
| 186 | /* We have to clean up here. */ | ||
| 187 | non_fatal (_("unable to rename '%s'; reason: %s"), to, strerror (errno)); | ||
| 188 | @@ -202,8 +167,8 @@ smart_rename (const char *from, const char *to, int preserve_dates ATTRIBUTE_UNU | ||
| 189 | if (ret != 0) | ||
| 190 | non_fatal (_("unable to copy file '%s'; reason: %s"), to, strerror (errno)); | ||
| 191 | |||
| 192 | - if (preserve_dates) | ||
| 193 | - set_times (to, &s); | ||
| 194 | + if (target_stat != NULL) | ||
| 195 | + set_times (to, target_stat); | ||
| 196 | unlink (from); | ||
| 197 | } | ||
| 198 | #endif /* _WIN32 && !__CYGWIN32__ */ | ||
| 199 | -- | ||
| 200 | 2.31.1 | ||
| 201 | |||
diff --git a/meta/recipes-devtools/binutils/binutils/0002-CVE-2021-20197.patch b/meta/recipes-devtools/binutils/binutils/0002-CVE-2021-20197.patch new file mode 100644 index 0000000000..3771f571eb --- /dev/null +++ b/meta/recipes-devtools/binutils/binutils/0002-CVE-2021-20197.patch | |||
| @@ -0,0 +1,170 @@ | |||
| 1 | From d3edaa91d4cf7202ec14342410194841e2f67f12 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Alan Modra <amodra@gmail.com> | ||
| 3 | Date: Fri, 26 Feb 2021 11:30:32 +1030 | ||
| 4 | Subject: [PATCH] Reinstate various pieces backed out from smart_rename changes | ||
| 5 | |||
| 6 | In the interests of a stable release various last minute smart_rename | ||
| 7 | patches were backed out of the 2.36 branch. The main reason to | ||
| 8 | reinstate some of those backed out changes here is to make necessary | ||
| 9 | followup fixes to commit 8e03235147a9 simple cherry-picks from | ||
| 10 | mainline. A secondary reason is that ar -M support isn't fixed for | ||
| 11 | pr26945 without this patch. | ||
| 12 | |||
| 13 | PR 26945 | ||
| 14 | * ar.c: Don't include libbfd.h. | ||
| 15 | (write_archive): Replace xmalloc+strcpy with xstrdup. | ||
| 16 | * arsup.c (temp_name, real_ofd): New static variables. | ||
| 17 | (ar_open): Use make_tempname and bfd_fdopenw. | ||
| 18 | (ar_save): Adjust to suit ar_open changes. | ||
| 19 | * objcopy.c: Don't include libbfd.h. | ||
| 20 | * rename.c: Rename and reorder variables. | ||
| 21 | |||
| 22 | (cherry picked from commit 95b91a043aeaeb546d2fea556d84a2de1e917770) | ||
| 23 | |||
| 24 | Upstream-Status: Backport [https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=d3edaa91d4cf7202ec14342410194841e2f67f12] | ||
| 25 | CVE: CVE-2021-20197 | ||
| 26 | Signed-off-by: Vinay Kumar <vinay.m.engg@gmail.com> | ||
| 27 | --- | ||
| 28 | binutils/ar.c | 4 +--- | ||
| 29 | binutils/arsup.c | 37 +++++++++++++++++++++++++------------ | ||
| 30 | binutils/objcopy.c | 1 - | ||
| 31 | binutils/rename.c | 6 +++--- | ||
| 32 | 5 files changed, 42 insertions(+), 19 deletions(-) | ||
| 33 | |||
| 34 | diff --git a/binutils/ar.c b/binutils/ar.c | ||
| 35 | index 3a91708b51c..44df48c5c67 100644 | ||
| 36 | --- a/binutils/ar.c | ||
| 37 | +++ b/binutils/ar.c | ||
| 38 | @@ -25,7 +25,6 @@ | ||
| 39 | |||
| 40 | #include "sysdep.h" | ||
| 41 | #include "bfd.h" | ||
| 42 | -#include "libbfd.h" | ||
| 43 | #include "libiberty.h" | ||
| 44 | #include "progress.h" | ||
| 45 | #include "getopt.h" | ||
| 46 | @@ -1255,8 +1254,7 @@ write_archive (bfd *iarch) | ||
| 47 | bfd *contents_head = iarch->archive_next; | ||
| 48 | int ofd = -1; | ||
| 49 | |||
| 50 | - old_name = (char *) xmalloc (strlen (bfd_get_filename (iarch)) + 1); | ||
| 51 | - strcpy (old_name, bfd_get_filename (iarch)); | ||
| 52 | + old_name = xstrdup (bfd_get_filename (iarch)); | ||
| 53 | new_name = make_tempname (old_name, &ofd); | ||
| 54 | |||
| 55 | if (new_name == NULL) | ||
| 56 | diff --git a/binutils/arsup.c b/binutils/arsup.c | ||
| 57 | index 0a1f63f6456..f7ce8f0bc82 100644 | ||
| 58 | --- a/binutils/arsup.c | ||
| 59 | +++ b/binutils/arsup.c | ||
| 60 | @@ -42,6 +42,8 @@ extern int deterministic; | ||
| 61 | |||
| 62 | static bfd *obfd; | ||
| 63 | static char *real_name; | ||
| 64 | +static char *temp_name; | ||
| 65 | +static int real_ofd; | ||
| 66 | static FILE *outfile; | ||
| 67 | |||
| 68 | static void | ||
| 69 | @@ -149,27 +151,24 @@ maybequit (void) | ||
| 70 | void | ||
| 71 | ar_open (char *name, int t) | ||
| 72 | { | ||
| 73 | - char *tname; | ||
| 74 | - const char *bname = lbasename (name); | ||
| 75 | - real_name = name; | ||
| 76 | + real_name = xstrdup (name); | ||
| 77 | + temp_name = make_tempname (real_name, &real_ofd); | ||
| 78 | |||
| 79 | - /* Prepend tmp- to the beginning, to avoid file-name clashes after | ||
| 80 | - truncation on filesystems with limited namespaces (DOS). */ | ||
| 81 | - if (asprintf (&tname, "%.*stmp-%s", (int) (bname - name), name, bname) == -1) | ||
| 82 | + if (temp_name == NULL) | ||
| 83 | { | ||
| 84 | - fprintf (stderr, _("%s: Can't allocate memory for temp name (%s)\n"), | ||
| 85 | + fprintf (stderr, _("%s: Can't open temporary file (%s)\n"), | ||
| 86 | program_name, strerror(errno)); | ||
| 87 | maybequit (); | ||
| 88 | return; | ||
| 89 | } | ||
| 90 | |||
| 91 | - obfd = bfd_openw (tname, NULL); | ||
| 92 | + obfd = bfd_fdopenw (temp_name, NULL, real_ofd); | ||
| 93 | |||
| 94 | if (!obfd) | ||
| 95 | { | ||
| 96 | fprintf (stderr, | ||
| 97 | _("%s: Can't open output archive %s\n"), | ||
| 98 | - program_name, tname); | ||
| 99 | + program_name, temp_name); | ||
| 100 | |||
| 101 | maybequit (); | ||
| 102 | } | ||
| 103 | @@ -344,16 +343,30 @@ ar_save (void) | ||
| 104 | } | ||
| 105 | else | ||
| 106 | { | ||
| 107 | - char *ofilename = xstrdup (bfd_get_filename (obfd)); | ||
| 108 | + struct stat target_stat; | ||
| 109 | |||
| 110 | if (deterministic > 0) | ||
| 111 | obfd->flags |= BFD_DETERMINISTIC_OUTPUT; | ||
| 112 | |||
| 113 | bfd_close (obfd); | ||
| 114 | |||
| 115 | - smart_rename (ofilename, real_name, NULL); | ||
| 116 | + if (stat (real_name, &target_stat) != 0) | ||
| 117 | + { | ||
| 118 | + /* The temp file created in ar_open has mode 0600 as per mkstemp. | ||
| 119 | + Create the real empty output file here so smart_rename will | ||
| 120 | + update the mode according to the process umask. */ | ||
| 121 | + obfd = bfd_openw (real_name, NULL); | ||
| 122 | + if (obfd != NULL) | ||
| 123 | + { | ||
| 124 | + bfd_set_format (obfd, bfd_archive); | ||
| 125 | + bfd_close (obfd); | ||
| 126 | + } | ||
| 127 | + } | ||
| 128 | + | ||
| 129 | + smart_rename (temp_name, real_name, NULL); | ||
| 130 | obfd = 0; | ||
| 131 | - free (ofilename); | ||
| 132 | + free (temp_name); | ||
| 133 | + free (real_name); | ||
| 134 | } | ||
| 135 | } | ||
| 136 | |||
| 137 | diff --git a/binutils/objcopy.c b/binutils/objcopy.c | ||
| 138 | index 07a872b5a80..73aa8bc2514 100644 | ||
| 139 | --- a/binutils/objcopy.c | ||
| 140 | +++ b/binutils/objcopy.c | ||
| 141 | @@ -20,7 +20,6 @@ | ||
| 142 | |||
| 143 | #include "sysdep.h" | ||
| 144 | #include "bfd.h" | ||
| 145 | -#include "libbfd.h" | ||
| 146 | #include "progress.h" | ||
| 147 | #include "getopt.h" | ||
| 148 | #include "libiberty.h" | ||
| 149 | diff --git a/binutils/rename.c b/binutils/rename.c | ||
| 150 | index f471b45fd3f..2ff092ee22b 100644 | ||
| 151 | --- a/binutils/rename.c | ||
| 152 | +++ b/binutils/rename.c | ||
| 153 | @@ -130,11 +130,11 @@ int | ||
| 154 | smart_rename (const char *from, const char *to, | ||
| 155 | struct stat *target_stat ATTRIBUTE_UNUSED) | ||
| 156 | { | ||
| 157 | - bfd_boolean exists; | ||
| 158 | - struct stat s; | ||
| 159 | int ret = 0; | ||
| 160 | + struct stat to_stat; | ||
| 161 | + bfd_boolean exists; | ||
| 162 | |||
| 163 | - exists = lstat (to, &s) == 0; | ||
| 164 | + exists = lstat (to, &to_stat) == 0; | ||
| 165 | |||
| 166 | #if defined (_WIN32) && !defined (__CYGWIN32__) | ||
| 167 | /* Win32, unlike unix, will not erase `to' in `rename(from, to)' but | ||
| 168 | -- | ||
| 169 | 2.31.1 | ||
| 170 | |||
diff --git a/meta/recipes-devtools/binutils/binutils/0003-CVE-2021-20197.patch b/meta/recipes-devtools/binutils/binutils/0003-CVE-2021-20197.patch new file mode 100644 index 0000000000..082b28b29c --- /dev/null +++ b/meta/recipes-devtools/binutils/binutils/0003-CVE-2021-20197.patch | |||
| @@ -0,0 +1,171 @@ | |||
| 1 | From 8b69e61d4be276bb862698aaafddc3e779d23c8f Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Alan Modra <amodra@gmail.com> | ||
| 3 | Date: Tue, 23 Feb 2021 09:37:39 +1030 | ||
| 4 | Subject: [PATCH] PR27456, lstat in rename.c on MinGW | ||
| 5 | |||
| 6 | PR 27456 | ||
| 7 | * rename.c: Tidy throughout. | ||
| 8 | (smart_rename): Always copy. Remove windows specific code. | ||
| 9 | |||
| 10 | (cherry picked from commit cca8873dd5a6015d5557ea44bc1ea9c252435a29) | ||
| 11 | |||
| 12 | Upstream-Status: Backport [https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=8b69e61d4be276bb862698aaafddc3e779d23c8f] | ||
| 13 | CVE: CVE-2021-20197 | ||
| 14 | Signed-off-by: Vinay Kumar <vinay.m.engg@gmail.com> | ||
| 15 | --- | ||
| 16 | binutils/rename.c | 111 ++++++++++++++------------------------------- | ||
| 17 | 2 files changed, 40 insertions(+), 76 deletions(-) | ||
| 18 | |||
| 19 | diff --git a/binutils/rename.c b/binutils/rename.c | ||
| 20 | index 2ff092ee22b..72a9323d72c 100644 | ||
| 21 | --- a/binutils/rename.c | ||
| 22 | +++ b/binutils/rename.c | ||
| 23 | @@ -24,14 +24,9 @@ | ||
| 24 | |||
| 25 | #ifdef HAVE_GOOD_UTIME_H | ||
| 26 | #include <utime.h> | ||
| 27 | -#else /* ! HAVE_GOOD_UTIME_H */ | ||
| 28 | -#ifdef HAVE_UTIMES | ||
| 29 | +#elif defined HAVE_UTIMES | ||
| 30 | #include <sys/time.h> | ||
| 31 | -#endif /* HAVE_UTIMES */ | ||
| 32 | -#endif /* ! HAVE_GOOD_UTIME_H */ | ||
| 33 | - | ||
| 34 | -#if ! defined (_WIN32) || defined (__CYGWIN32__) | ||
| 35 | -static int simple_copy (const char *, const char *); | ||
| 36 | +#endif | ||
| 37 | |||
| 38 | /* The number of bytes to copy at once. */ | ||
| 39 | #define COPY_BUF 8192 | ||
| 40 | @@ -82,7 +77,6 @@ simple_copy (const char *from, const char *to) | ||
| 41 | } | ||
| 42 | return 0; | ||
| 43 | } | ||
| 44 | -#endif /* __CYGWIN32__ or not _WIN32 */ | ||
| 45 | |||
| 46 | /* Set the times of the file DESTINATION to be the same as those in | ||
| 47 | STATBUF. */ | ||
| 48 | @@ -91,87 +85,52 @@ void | ||
| 49 | set_times (const char *destination, const struct stat *statbuf) | ||
| 50 | { | ||
| 51 | int result; | ||
| 52 | - | ||
| 53 | - { | ||
| 54 | #ifdef HAVE_GOOD_UTIME_H | ||
| 55 | - struct utimbuf tb; | ||
| 56 | - | ||
| 57 | - tb.actime = statbuf->st_atime; | ||
| 58 | - tb.modtime = statbuf->st_mtime; | ||
| 59 | - result = utime (destination, &tb); | ||
| 60 | -#else /* ! HAVE_GOOD_UTIME_H */ | ||
| 61 | -#ifndef HAVE_UTIMES | ||
| 62 | - long tb[2]; | ||
| 63 | - | ||
| 64 | - tb[0] = statbuf->st_atime; | ||
| 65 | - tb[1] = statbuf->st_mtime; | ||
| 66 | - result = utime (destination, tb); | ||
| 67 | -#else /* HAVE_UTIMES */ | ||
| 68 | - struct timeval tv[2]; | ||
| 69 | - | ||
| 70 | - tv[0].tv_sec = statbuf->st_atime; | ||
| 71 | - tv[0].tv_usec = 0; | ||
| 72 | - tv[1].tv_sec = statbuf->st_mtime; | ||
| 73 | - tv[1].tv_usec = 0; | ||
| 74 | - result = utimes (destination, tv); | ||
| 75 | -#endif /* HAVE_UTIMES */ | ||
| 76 | -#endif /* ! HAVE_GOOD_UTIME_H */ | ||
| 77 | - } | ||
| 78 | + struct utimbuf tb; | ||
| 79 | + | ||
| 80 | + tb.actime = statbuf->st_atime; | ||
| 81 | + tb.modtime = statbuf->st_mtime; | ||
| 82 | + result = utime (destination, &tb); | ||
| 83 | +#elif defined HAVE_UTIMES | ||
| 84 | + struct timeval tv[2]; | ||
| 85 | + | ||
| 86 | + tv[0].tv_sec = statbuf->st_atime; | ||
| 87 | + tv[0].tv_usec = 0; | ||
| 88 | + tv[1].tv_sec = statbuf->st_mtime; | ||
| 89 | + tv[1].tv_usec = 0; | ||
| 90 | + result = utimes (destination, tv); | ||
| 91 | +#else | ||
| 92 | + long tb[2]; | ||
| 93 | + | ||
| 94 | + tb[0] = statbuf->st_atime; | ||
| 95 | + tb[1] = statbuf->st_mtime; | ||
| 96 | + result = utime (destination, tb); | ||
| 97 | +#endif | ||
| 98 | |||
| 99 | if (result != 0) | ||
| 100 | non_fatal (_("%s: cannot set time: %s"), destination, strerror (errno)); | ||
| 101 | } | ||
| 102 | |||
| 103 | -/* Rename FROM to TO, copying if TO exists. TARGET_STAT has the file status | ||
| 104 | - that, if non-NULL, is used to fix up timestamps after rename. Return 0 if | ||
| 105 | - ok, -1 if error. */ | ||
| 106 | +/* Copy FROM to TO. TARGET_STAT has the file status that, if non-NULL, | ||
| 107 | + is used to fix up timestamps. Return 0 if ok, -1 if error. | ||
| 108 | + At one time this function renamed files, but file permissions are | ||
| 109 | + tricky to update given the number of different schemes used by | ||
| 110 | + various systems. So now we just copy. */ | ||
| 111 | |||
| 112 | int | ||
| 113 | smart_rename (const char *from, const char *to, | ||
| 114 | - struct stat *target_stat ATTRIBUTE_UNUSED) | ||
| 115 | + struct stat *target_stat) | ||
| 116 | { | ||
| 117 | - int ret = 0; | ||
| 118 | - struct stat to_stat; | ||
| 119 | - bfd_boolean exists; | ||
| 120 | - | ||
| 121 | - exists = lstat (to, &to_stat) == 0; | ||
| 122 | - | ||
| 123 | -#if defined (_WIN32) && !defined (__CYGWIN32__) | ||
| 124 | - /* Win32, unlike unix, will not erase `to' in `rename(from, to)' but | ||
| 125 | - fail instead. Also, chown is not present. */ | ||
| 126 | - | ||
| 127 | - if (exists) | ||
| 128 | - remove (to); | ||
| 129 | + int ret; | ||
| 130 | |||
| 131 | - ret = rename (from, to); | ||
| 132 | + ret = simple_copy (from, to); | ||
| 133 | if (ret != 0) | ||
| 134 | - { | ||
| 135 | - /* We have to clean up here. */ | ||
| 136 | - non_fatal (_("unable to rename '%s'; reason: %s"), to, strerror (errno)); | ||
| 137 | - unlink (from); | ||
| 138 | - } | ||
| 139 | -#else | ||
| 140 | - /* Avoid a full copy and use rename if TO does not exist. */ | ||
| 141 | - if (!exists) | ||
| 142 | - { | ||
| 143 | - if ((ret = rename (from, to)) != 0) | ||
| 144 | - { | ||
| 145 | - /* We have to clean up here. */ | ||
| 146 | - non_fatal (_("unable to rename '%s'; reason: %s"), to, strerror (errno)); | ||
| 147 | - unlink (from); | ||
| 148 | - } | ||
| 149 | - } | ||
| 150 | - else | ||
| 151 | - { | ||
| 152 | - ret = simple_copy (from, to); | ||
| 153 | - if (ret != 0) | ||
| 154 | - non_fatal (_("unable to copy file '%s'; reason: %s"), to, strerror (errno)); | ||
| 155 | + non_fatal (_("unable to copy file '%s'; reason: %s"), | ||
| 156 | + to, strerror (errno)); | ||
| 157 | |||
| 158 | - if (target_stat != NULL) | ||
| 159 | - set_times (to, target_stat); | ||
| 160 | - unlink (from); | ||
| 161 | - } | ||
| 162 | -#endif /* _WIN32 && !__CYGWIN32__ */ | ||
| 163 | + if (target_stat != NULL) | ||
| 164 | + set_times (to, target_stat); | ||
| 165 | + unlink (from); | ||
| 166 | |||
| 167 | return ret; | ||
| 168 | } | ||
| 169 | -- | ||
| 170 | 2.31.1 | ||
| 171 | |||
