Skip to content

Commit 513daa3

Browse files
r4v3n6101apritzel
authored andcommitted
nandpart: fix UAF when freeing mbr
The cleanup loop frees all mbrs entries, including the one referenced by mbr. This leaves mbr pointing to freed memory that is subsequently used to update and write the partition tables. Skip mbr in the initial cleanup and free it after writing or when the user cancels. Signed-off-by: r4v3n6101 <raven6107@gmail.com>
1 parent a08a24a commit 513daa3

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

‎nand-part.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,13 +233,14 @@ static int writembrs(int fd, char names[][MAX_NAME], __u32 start, __u32 *lens, u
233233
printf("\nready to write new partition tables:\n");
234234
printmbr(mbr);
235235
for (i = 0; i < MBR_COPY_NUM; i++) {
236-
if (mbrs[i])
236+
if (mbrs[i] && mbrs[i] != mbr)
237237
_free_mbr(mbrs[i]);
238238
}
239239
printf("\nwrite new partition tables? (Y/N)\n");
240240
read(0, &yn, 1);
241241
if (yn != 'Y' && yn != 'y') {
242242
printf("aborting\n");
243+
_free_mbr(mbr);
243244
return 0;
244245
}
245246

@@ -256,6 +257,7 @@ static int writembrs(int fd, char names[][MAX_NAME], __u32 start, __u32 *lens, u
256257
perror("Failed rereading partition table");
257258
#endif
258259

260+
_free_mbr(mbr);
259261
return 1;
260262
}
261263

0 commit comments

Comments
 (0)