Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
M
Magisk
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Magisk
Commits
f6ee2525
Commit
f6ee2525
authored
Jun 09, 2018
by
Alexandre Boeglin
Committed by
John Wu
Jun 09, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
magiskboot: Check dtb header content to avoid false positives
parent
90d218eb
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
0 deletions
+24
-0
bootimg.c
native/jni/magiskboot/bootimg.c
+24
-0
No files found.
native/jni/magiskboot/bootimg.c
View file @
f6ee2525
#include <stdlib.h>
#include <stdlib.h>
#include <unistd.h>
#include <unistd.h>
#include <fcntl.h>
#include <fcntl.h>
#include <libfdt.h>
#include <sys/mman.h>
#include <sys/mman.h>
#include "bootimg.h"
#include "bootimg.h"
...
@@ -181,6 +182,29 @@ int parse_img(const char *image, boot_img *boot) {
...
@@ -181,6 +182,29 @@ int parse_img(const char *image, boot_img *boot) {
// Search for dtb in kernel
// Search for dtb in kernel
for
(
uint32_t
i
=
0
;
i
<
header
(
boot
,
kernel_size
);
++
i
)
{
for
(
uint32_t
i
=
0
;
i
<
header
(
boot
,
kernel_size
);
++
i
)
{
if
(
memcmp
(
boot
->
kernel
+
i
,
DTB_MAGIC
,
4
)
==
0
)
{
if
(
memcmp
(
boot
->
kernel
+
i
,
DTB_MAGIC
,
4
)
==
0
)
{
// Check that fdt_header.totalsize does not overflow kernel image size
uint32_t
dt_size
=
fdt32_to_cpu
(
*
(
uint32_t
*
)(
boot
->
kernel
+
i
+
4
));
if
(
dt_size
>
header
(
boot
,
kernel_size
)
-
i
)
{
fprintf
(
stderr
,
"Invalid DTB detection at 0x%x: size (%u) > remaining (%u)
\n
"
,
i
,
dt_size
,
header
(
boot
,
kernel_size
)
-
i
);
continue
;
}
// Check that fdt_header.off_dt_struct does not overflow kernel image size
uint32_t
dt_struct_offset
=
fdt32_to_cpu
(
*
(
uint32_t
*
)(
boot
->
kernel
+
i
+
8
));
if
(
dt_struct_offset
>
header
(
boot
,
kernel_size
)
-
i
)
{
fprintf
(
stderr
,
"Invalid DTB detection at 0x%x: struct offset (%u) > remaining (%u)
\n
"
,
i
,
dt_struct_offset
,
header
(
boot
,
kernel_size
)
-
i
);
continue
;
}
// Check that fdt_node_header.tag of first node is FDT_BEGIN_NODE
uint32_t
dt_begin_node
=
fdt32_to_cpu
(
*
(
uint32_t
*
)(
boot
->
kernel
+
i
+
dt_struct_offset
));
if
(
dt_begin_node
!=
FDT_BEGIN_NODE
)
{
fprintf
(
stderr
,
"Invalid DTB detection at 0x%x: header tag of first node != FDT_BEGIN_NODE
\n
"
,
i
);
continue
;
}
boot
->
dtb
=
boot
->
kernel
+
i
;
boot
->
dtb
=
boot
->
kernel
+
i
;
boot
->
dt_size
=
header
(
boot
,
kernel_size
)
-
i
;
boot
->
dt_size
=
header
(
boot
,
kernel_size
)
-
i
;
lheader
(
boot
,
kernel_size
,
=
i
);
lheader
(
boot
,
kernel_size
,
=
i
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment