diff options
Diffstat (limited to 'meta/recipes-devtools/squashfs-tools/files/CVE-2021-41072-requisite-3.patch')
-rw-r--r-- | meta/recipes-devtools/squashfs-tools/files/CVE-2021-41072-requisite-3.patch | 330 |
1 files changed, 330 insertions, 0 deletions
diff --git a/meta/recipes-devtools/squashfs-tools/files/CVE-2021-41072-requisite-3.patch b/meta/recipes-devtools/squashfs-tools/files/CVE-2021-41072-requisite-3.patch new file mode 100644 index 0000000000..fad5898f13 --- /dev/null +++ b/meta/recipes-devtools/squashfs-tools/files/CVE-2021-41072-requisite-3.patch | |||
@@ -0,0 +1,330 @@ | |||
1 | The commit is required by the fix for CVE-2021-41072. Update context for | ||
2 | version 4.4. | ||
3 | |||
4 | Upstream-Status: Backport [https://github.com/plougher/squashfs-tools/commit/9938154] | ||
5 | |||
6 | Signed-off-by: Kai Kang <kai.kang@windriver.com> | ||
7 | |||
8 | From 9938154174756ee48a94ea0b076397a2944b028d Mon Sep 17 00:00:00 2001 | ||
9 | From: Phillip Lougher <phillip@squashfs.org.uk> | ||
10 | Date: Sun, 12 Sep 2021 22:58:11 +0100 | ||
11 | Subject: [PATCH] unsquashfs: use linked list to store directory names | ||
12 | |||
13 | This should bring higher performance, and it allows sorting | ||
14 | if necessary (1.x and 2.0 filesystems). | ||
15 | |||
16 | Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk> | ||
17 | --- | ||
18 | squashfs-tools/unsquash-1.c | 30 +++++++++++++++--------------- | ||
19 | squashfs-tools/unsquash-1234.c | 12 ++++++++---- | ||
20 | squashfs-tools/unsquash-2.c | 29 +++++++++++++++-------------- | ||
21 | squashfs-tools/unsquash-3.c | 29 +++++++++++++++-------------- | ||
22 | squashfs-tools/unsquash-4.c | 29 +++++++++++++++-------------- | ||
23 | squashfs-tools/unsquashfs.c | 16 ++++++++++------ | ||
24 | squashfs-tools/unsquashfs.h | 3 ++- | ||
25 | 7 files changed, 80 insertions(+), 68 deletions(-) | ||
26 | |||
27 | diff --git a/squashfs-tools/unsquash-1.c b/squashfs-tools/unsquash-1.c | ||
28 | index d0121c6..b604434 100644 | ||
29 | --- a/squashfs-tools/unsquash-1.c | ||
30 | +++ b/squashfs-tools/unsquash-1.c | ||
31 | @@ -207,7 +207,7 @@ static struct dir *squashfs_opendir(unsi | ||
32 | long long start; | ||
33 | int bytes; | ||
34 | int dir_count, size; | ||
35 | - struct dir_ent *new_dir; | ||
36 | + struct dir_ent *ent, *cur_ent = NULL; | ||
37 | struct dir *dir; | ||
38 | |||
39 | TRACE("squashfs_opendir: inode start block %d, offset %d\n", | ||
40 | @@ -220,7 +220,7 @@ static struct dir *squashfs_opendir(unsi | ||
41 | EXIT_UNSQUASH("squashfs_opendir: malloc failed!\n"); | ||
42 | |||
43 | dir->dir_count = 0; | ||
44 | - dir->cur_entry = 0; | ||
45 | + dir->cur_entry = NULL; | ||
46 | dir->mode = (*i)->mode; | ||
47 | dir->uid = (*i)->uid; | ||
48 | dir->guid = (*i)->gid; | ||
49 | @@ -295,19 +295,20 @@ static struct dir *squashfs_opendir(unsi | ||
50 | TRACE("squashfs_opendir: directory entry %s, inode " | ||
51 | "%d:%d, type %d\n", dire->name, | ||
52 | dirh.start_block, dire->offset, dire->type); | ||
53 | - if((dir->dir_count % DIR_ENT_SIZE) == 0) { | ||
54 | - new_dir = realloc(dir->dirs, (dir->dir_count + | ||
55 | - DIR_ENT_SIZE) * sizeof(struct dir_ent)); | ||
56 | - if(new_dir == NULL) | ||
57 | - EXIT_UNSQUASH("squashfs_opendir: " | ||
58 | - "realloc failed!\n"); | ||
59 | - dir->dirs = new_dir; | ||
60 | - } | ||
61 | - dir->dirs[dir->dir_count].name = strdup(dire->name); | ||
62 | - dir->dirs[dir->dir_count].start_block = | ||
63 | - dirh.start_block; | ||
64 | - dir->dirs[dir->dir_count].offset = dire->offset; | ||
65 | - dir->dirs[dir->dir_count].type = dire->type; | ||
66 | + ent = malloc(sizeof(struct dir_ent)); | ||
67 | + if(ent == NULL) | ||
68 | + MEM_ERROR(); | ||
69 | + | ||
70 | + ent->name = strdup(dire->name); | ||
71 | + ent->start_block = dirh.start_block; | ||
72 | + ent->offset = dire->offset; | ||
73 | + ent->type = dire->type; | ||
74 | + ent->next = NULL; | ||
75 | + if(cur_ent == NULL) | ||
76 | + dir->dirs = ent; | ||
77 | + else | ||
78 | + cur_ent->next = ent; | ||
79 | + cur_ent = ent; | ||
80 | dir->dir_count ++; | ||
81 | bytes += dire->size + 1; | ||
82 | } | ||
83 | diff --git a/squashfs-tools/unsquash-1234.c b/squashfs-tools/unsquash-1234.c | ||
84 | index ac46d9d..e389f8d 100644 | ||
85 | --- a/squashfs-tools/unsquash-1234.c | ||
86 | +++ b/squashfs-tools/unsquash-1234.c | ||
87 | @@ -60,11 +60,15 @@ int check_name(char *name, int size) | ||
88 | |||
89 | void squashfs_closedir(struct dir *dir) | ||
90 | { | ||
91 | - int i; | ||
92 | + struct dir_ent *ent = dir->dirs; | ||
93 | |||
94 | - for(i = 0; i < dir->dir_count; i++) | ||
95 | - free(dir->dirs[i].name); | ||
96 | + while(ent) { | ||
97 | + struct dir_ent *tmp = ent; | ||
98 | + | ||
99 | + ent = ent->next; | ||
100 | + free(tmp->name); | ||
101 | + free(tmp); | ||
102 | + } | ||
103 | |||
104 | - free(dir->dirs); | ||
105 | free(dir); | ||
106 | } | ||
107 | diff --git a/squashfs-tools/unsquash-2.c b/squashfs-tools/unsquash-2.c | ||
108 | index e847980..956f96f 100644 | ||
109 | --- a/squashfs-tools/unsquash-2.c | ||
110 | +++ b/squashfs-tools/unsquash-2.c | ||
111 | @@ -308,7 +308,7 @@ static struct dir *squashfs_opendir(unsi | ||
112 | long long start; | ||
113 | int bytes; | ||
114 | int dir_count, size; | ||
115 | - struct dir_ent *new_dir; | ||
116 | + struct dir_ent *ent, *cur_ent = NULL; | ||
117 | struct dir *dir; | ||
118 | |||
119 | TRACE("squashfs_opendir: inode start block %d, offset %d\n", | ||
120 | @@ -321,7 +321,7 @@ static struct dir *squashfs_opendir(unsi | ||
121 | EXIT_UNSQUASH("squashfs_opendir: malloc failed!\n"); | ||
122 | |||
123 | dir->dir_count = 0; | ||
124 | - dir->cur_entry = 0; | ||
125 | + dir->cur_entry = NULL; | ||
126 | dir->mode = (*i)->mode; | ||
127 | dir->uid = (*i)->uid; | ||
128 | dir->guid = (*i)->gid; | ||
129 | @@ -396,19 +396,20 @@ static struct dir *squashfs_opendir(unsi | ||
130 | TRACE("squashfs_opendir: directory entry %s, inode " | ||
131 | "%d:%d, type %d\n", dire->name, | ||
132 | dirh.start_block, dire->offset, dire->type); | ||
133 | - if((dir->dir_count % DIR_ENT_SIZE) == 0) { | ||
134 | - new_dir = realloc(dir->dirs, (dir->dir_count + | ||
135 | - DIR_ENT_SIZE) * sizeof(struct dir_ent)); | ||
136 | - if(new_dir == NULL) | ||
137 | - EXIT_UNSQUASH("squashfs_opendir: " | ||
138 | - "realloc failed!\n"); | ||
139 | - dir->dirs = new_dir; | ||
140 | - } | ||
141 | - dir->dirs[dir->dir_count].name = strdup(dire->name); | ||
142 | - dir->dirs[dir->dir_count].start_block = | ||
143 | - dirh.start_block; | ||
144 | - dir->dirs[dir->dir_count].offset = dire->offset; | ||
145 | - dir->dirs[dir->dir_count].type = dire->type; | ||
146 | + ent = malloc(sizeof(struct dir_ent)); | ||
147 | + if(ent == NULL) | ||
148 | + MEM_ERROR(); | ||
149 | + | ||
150 | + ent->name = strdup(dire->name); | ||
151 | + ent->start_block = dirh.start_block; | ||
152 | + ent->offset = dire->offset; | ||
153 | + ent->type = dire->type; | ||
154 | + ent->next = NULL; | ||
155 | + if(cur_ent == NULL) | ||
156 | + dir->dirs = ent; | ||
157 | + else | ||
158 | + cur_ent->next = ent; | ||
159 | + cur_ent = ent; | ||
160 | dir->dir_count ++; | ||
161 | bytes += dire->size + 1; | ||
162 | } | ||
163 | diff --git a/squashfs-tools/unsquash-3.c b/squashfs-tools/unsquash-3.c | ||
164 | index 8223f27..835a574 100644 | ||
165 | --- a/squashfs-tools/unsquash-3.c | ||
166 | +++ b/squashfs-tools/unsquash-3.c | ||
167 | @@ -334,7 +334,7 @@ static struct dir *squashfs_opendir(unsi | ||
168 | long long start; | ||
169 | int bytes; | ||
170 | int dir_count, size; | ||
171 | - struct dir_ent *new_dir; | ||
172 | + struct dir_ent *ent, *cur_ent = NULL; | ||
173 | struct dir *dir; | ||
174 | |||
175 | TRACE("squashfs_opendir: inode start block %d, offset %d\n", | ||
176 | @@ -347,7 +347,7 @@ static struct dir *squashfs_opendir(unsi | ||
177 | EXIT_UNSQUASH("squashfs_opendir: malloc failed!\n"); | ||
178 | |||
179 | dir->dir_count = 0; | ||
180 | - dir->cur_entry = 0; | ||
181 | + dir->cur_entry = NULL; | ||
182 | dir->mode = (*i)->mode; | ||
183 | dir->uid = (*i)->uid; | ||
184 | dir->guid = (*i)->gid; | ||
185 | @@ -423,19 +423,20 @@ static struct dir *squashfs_opendir(unsi | ||
186 | TRACE("squashfs_opendir: directory entry %s, inode " | ||
187 | "%d:%d, type %d\n", dire->name, | ||
188 | dirh.start_block, dire->offset, dire->type); | ||
189 | - if((dir->dir_count % DIR_ENT_SIZE) == 0) { | ||
190 | - new_dir = realloc(dir->dirs, (dir->dir_count + | ||
191 | - DIR_ENT_SIZE) * sizeof(struct dir_ent)); | ||
192 | - if(new_dir == NULL) | ||
193 | - EXIT_UNSQUASH("squashfs_opendir: " | ||
194 | - "realloc failed!\n"); | ||
195 | - dir->dirs = new_dir; | ||
196 | - } | ||
197 | - dir->dirs[dir->dir_count].name = strdup(dire->name); | ||
198 | - dir->dirs[dir->dir_count].start_block = | ||
199 | - dirh.start_block; | ||
200 | - dir->dirs[dir->dir_count].offset = dire->offset; | ||
201 | - dir->dirs[dir->dir_count].type = dire->type; | ||
202 | + ent = malloc(sizeof(struct dir_ent)); | ||
203 | + if(ent == NULL) | ||
204 | + MEM_ERROR(); | ||
205 | + | ||
206 | + ent->name = strdup(dire->name); | ||
207 | + ent->start_block = dirh.start_block; | ||
208 | + ent->offset = dire->offset; | ||
209 | + ent->type = dire->type; | ||
210 | + ent->next = NULL; | ||
211 | + if(cur_ent == NULL) | ||
212 | + dir->dirs = ent; | ||
213 | + else | ||
214 | + cur_ent->next = ent; | ||
215 | + cur_ent = ent; | ||
216 | dir->dir_count ++; | ||
217 | bytes += dire->size + 1; | ||
218 | } | ||
219 | diff --git a/squashfs-tools/unsquash-4.c b/squashfs-tools/unsquash-4.c | ||
220 | index 1e199a7..694783d 100644 | ||
221 | --- a/squashfs-tools/unsquash-4.c | ||
222 | +++ b/squashfs-tools/unsquash-4.c | ||
223 | @@ -281,7 +281,7 @@ static struct dir *squashfs_opendir(unsi | ||
224 | long long start; | ||
225 | long long bytes; | ||
226 | int dir_count, size; | ||
227 | - struct dir_ent *new_dir; | ||
228 | + struct dir_ent *ent, *cur_ent = NULL; | ||
229 | struct dir *dir; | ||
230 | |||
231 | TRACE("squashfs_opendir: inode start block %d, offset %d\n", | ||
232 | @@ -294,7 +294,7 @@ static struct dir *squashfs_opendir(unsi | ||
233 | EXIT_UNSQUASH("squashfs_opendir: malloc failed!\n"); | ||
234 | |||
235 | dir->dir_count = 0; | ||
236 | - dir->cur_entry = 0; | ||
237 | + dir->cur_entry = NULL; | ||
238 | dir->mode = (*i)->mode; | ||
239 | dir->uid = (*i)->uid; | ||
240 | dir->guid = (*i)->gid; | ||
241 | @@ -359,19 +359,20 @@ static struct dir *squashfs_opendir(unsi | ||
242 | TRACE("squashfs_opendir: directory entry %s, inode " | ||
243 | "%d:%d, type %d\n", dire->name, | ||
244 | dirh.start_block, dire->offset, dire->type); | ||
245 | - if((dir->dir_count % DIR_ENT_SIZE) == 0) { | ||
246 | - new_dir = realloc(dir->dirs, (dir->dir_count + | ||
247 | - DIR_ENT_SIZE) * sizeof(struct dir_ent)); | ||
248 | - if(new_dir == NULL) | ||
249 | - EXIT_UNSQUASH("squashfs_opendir: " | ||
250 | - "realloc failed!\n"); | ||
251 | - dir->dirs = new_dir; | ||
252 | - } | ||
253 | - dir->dirs[dir->dir_count].name = strdup(dire->name); | ||
254 | - dir->dirs[dir->dir_count].start_block = | ||
255 | - dirh.start_block; | ||
256 | - dir->dirs[dir->dir_count].offset = dire->offset; | ||
257 | - dir->dirs[dir->dir_count].type = dire->type; | ||
258 | + ent = malloc(sizeof(struct dir_ent)); | ||
259 | + if(ent == NULL) | ||
260 | + MEM_ERROR(); | ||
261 | + | ||
262 | + ent->name = strdup(dire->name); | ||
263 | + ent->start_block = dirh.start_block; | ||
264 | + ent->offset = dire->offset; | ||
265 | + ent->type = dire->type; | ||
266 | + ent->next = NULL; | ||
267 | + if(cur_ent == NULL) | ||
268 | + dir->dirs = ent; | ||
269 | + else | ||
270 | + cur_ent->next = ent; | ||
271 | + cur_ent = ent; | ||
272 | dir->dir_count ++; | ||
273 | bytes += dire->size + 1; | ||
274 | } | ||
275 | diff --git a/squashfs-tools/unsquashfs.c b/squashfs-tools/unsquashfs.c | ||
276 | index 04be53c..fee28ec 100644 | ||
277 | --- a/squashfs-tools/unsquashfs.c | ||
278 | +++ b/squashfs-tools/unsquashfs.c | ||
279 | @@ -1277,14 +1277,18 @@ failed: | ||
280 | int squashfs_readdir(struct dir *dir, char **name, unsigned int *start_block, | ||
281 | unsigned int *offset, unsigned int *type) | ||
282 | { | ||
283 | - if(dir->cur_entry == dir->dir_count) | ||
284 | + if(dir->cur_entry == NULL) | ||
285 | + dir->cur_entry = dir->dirs; | ||
286 | + else | ||
287 | + dir->cur_entry = dir->cur_entry->next; | ||
288 | + | ||
289 | + if(dir->cur_entry == NULL) | ||
290 | return FALSE; | ||
291 | |||
292 | - *name = dir->dirs[dir->cur_entry].name; | ||
293 | - *start_block = dir->dirs[dir->cur_entry].start_block; | ||
294 | - *offset = dir->dirs[dir->cur_entry].offset; | ||
295 | - *type = dir->dirs[dir->cur_entry].type; | ||
296 | - dir->cur_entry ++; | ||
297 | + *name = dir->cur_entry->name; | ||
298 | + *start_block = dir->cur_entry->start_block; | ||
299 | + *offset = dir->cur_entry->offset; | ||
300 | + *type = dir->cur_entry->type; | ||
301 | |||
302 | return TRUE; | ||
303 | } | ||
304 | diff --git a/squashfs-tools/unsquashfs.h b/squashfs-tools/unsquashfs.h | ||
305 | index 583fbe4..f8cf78c 100644 | ||
306 | --- a/squashfs-tools/unsquashfs.h | ||
307 | +++ b/squashfs-tools/unsquashfs.h | ||
308 | @@ -169,17 +169,18 @@ struct dir_ent { | ||
309 | unsigned int start_block; | ||
310 | unsigned int offset; | ||
311 | unsigned int type; | ||
312 | + struct dir_ent *next; | ||
313 | }; | ||
314 | |||
315 | struct dir { | ||
316 | int dir_count; | ||
317 | - int cur_entry; | ||
318 | unsigned int mode; | ||
319 | uid_t uid; | ||
320 | gid_t guid; | ||
321 | unsigned int mtime; | ||
322 | unsigned int xattr; | ||
323 | struct dir_ent *dirs; | ||
324 | + struct dir_ent *cur_entry; | ||
325 | }; | ||
326 | |||
327 | struct file_entry { | ||
328 | -- | ||
329 | 2.17.1 | ||
330 | |||