diff options
Diffstat (limited to 'meta/recipes-devtools/binutils/binutils/0001-CVE-2021-20197.patch')
-rw-r--r-- | meta/recipes-devtools/binutils/binutils/0001-CVE-2021-20197.patch | 201 |
1 files changed, 0 insertions, 201 deletions
diff --git a/meta/recipes-devtools/binutils/binutils/0001-CVE-2021-20197.patch b/meta/recipes-devtools/binutils/binutils/0001-CVE-2021-20197.patch deleted file mode 100644 index 2b4eaba26d..0000000000 --- a/meta/recipes-devtools/binutils/binutils/0001-CVE-2021-20197.patch +++ /dev/null | |||
@@ -1,201 +0,0 @@ | |||
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 | |||