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
b56a757f
Commit
b56a757f
authored
Aug 17, 2016
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add live patch
parent
f7c04991
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
14 deletions
+53
-14
sepolicy-inject.c
sepolicy-inject.c
+53
-14
No files found.
sepolicy-inject.c
View file @
b56a757f
...
@@ -499,11 +499,36 @@ int auto_allow(type_datum_t *src, type_datum_t *tgt, class_datum_t *cls, policyd
...
@@ -499,11 +499,36 @@ int auto_allow(type_datum_t *src, type_datum_t *tgt, class_datum_t *cls, policyd
return
0
;
return
0
;
}
}
int
live_patch
(
policydb_t
*
policydb
)
{
char
*
filename
=
"/sys/fs/selinux/load"
;
int
fd
,
ret
;
void
*
data
=
NULL
;
size_t
len
;
policydb_to_image
(
NULL
,
policydb
,
&
data
,
&
len
);
// based on libselinux security_load_policy()
fd
=
open
(
filename
,
O_RDWR
);
if
(
fd
<
0
)
{
fprintf
(
stderr
,
"Can't open '%s': %s
\n
"
,
filename
,
strerror
(
errno
));
return
1
;
}
ret
=
write
(
fd
,
data
,
len
);
close
(
fd
);
if
(
ret
<
0
)
{
fprintf
(
stderr
,
"Could not write policy to %s
\n
"
,
filename
);
return
1
;
}
return
0
;
}
int
main
(
int
argc
,
char
**
argv
)
int
main
(
int
argc
,
char
**
argv
)
{
{
char
*
policy
=
NULL
,
*
source
=
NULL
,
*
target
=
NULL
,
*
class
=
NULL
,
*
perm
=
NULL
;
char
*
policy
=
NULL
,
*
source
=
NULL
,
*
target
=
NULL
,
*
class
=
NULL
,
*
perm
=
NULL
;
char
*
fcon
=
NULL
,
*
outfile
=
NULL
,
*
permissive
=
NULL
,
*
attr
=
NULL
,
*
filetrans
=
NULL
;
char
*
fcon
=
NULL
,
*
outfile
=
NULL
,
*
permissive
=
NULL
,
*
attr
=
NULL
,
*
filetrans
=
NULL
;
int
exists
=
0
,
not
=
0
,
autoAllow
=
0
;
int
exists
=
0
,
not
=
0
,
autoAllow
=
0
,
live
=
0
;
policydb_t
policydb
;
policydb_t
policydb
;
struct
policy_file
pf
,
outpf
;
struct
policy_file
pf
,
outpf
;
sidtab_t
sidtab
;
sidtab_t
sidtab
;
...
@@ -527,6 +552,7 @@ int main(int argc, char **argv)
...
@@ -527,6 +552,7 @@ int main(int argc, char **argv)
{
"not-permissive"
,
required_argument
,
NULL
,
'z'
},
{
"not-permissive"
,
required_argument
,
NULL
,
'z'
},
{
"not"
,
no_argument
,
NULL
,
0
},
{
"not"
,
no_argument
,
NULL
,
0
},
{
"auto"
,
no_argument
,
NULL
,
0
},
{
"auto"
,
no_argument
,
NULL
,
0
},
{
"live"
,
no_argument
,
NULL
,
0
},
{
NULL
,
0
,
NULL
,
0
}
{
NULL
,
0
,
NULL
,
0
}
};
};
...
@@ -538,6 +564,8 @@ int main(int argc, char **argv)
...
@@ -538,6 +564,8 @@ int main(int argc, char **argv)
not
=
1
;
not
=
1
;
else
if
(
strcmp
(
long_options
[
option_index
].
name
,
"auto"
)
==
0
)
else
if
(
strcmp
(
long_options
[
option_index
].
name
,
"auto"
)
==
0
)
autoAllow
=
1
;
autoAllow
=
1
;
else
if
(
strcmp
(
long_options
[
option_index
].
name
,
"live"
)
==
0
)
live
=
1
;
else
else
usage
(
argv
[
0
]);
usage
(
argv
[
0
]);
break
;
break
;
...
@@ -587,12 +615,15 @@ int main(int argc, char **argv)
...
@@ -587,12 +615,15 @@ int main(int argc, char **argv)
}
}
}
}
if
((
(
!
source
||
!
target
||
!
class
||
!
perm
)
&&
!
permissive
&&
!
fcon
&&
!
attr
&&!
filetrans
&&
!
exists
&&
!
auto_allow
)
||
!
policy
)
if
((
!
source
||
!
target
||
!
class
||
!
perm
)
&&
!
permissive
&&
!
fcon
&&
!
attr
&&!
filetrans
&&
!
exists
&&
!
auto_allow
)
usage
(
argv
[
0
]);
usage
(
argv
[
0
]);
if
(
!
outfile
)
if
(
!
outfile
)
outfile
=
policy
;
outfile
=
policy
;
if
(
!
policy
)
policy
=
"/sys/fs/selinux/policy"
;
sepol_set_policydb
(
&
policydb
);
sepol_set_policydb
(
&
policydb
);
sepol_set_sidtab
(
&
sidtab
);
sepol_set_sidtab
(
&
sidtab
);
...
@@ -686,23 +717,31 @@ int main(int argc, char **argv)
...
@@ -686,23 +717,31 @@ int main(int argc, char **argv)
}
}
}
}
fp
=
fopen
(
outfile
,
"w"
);
if
(
live
)
{
if
(
!
fp
)
{
if
(
live_patch
(
&
policydb
))
{
fprintf
(
stderr
,
"Could not open outfile
\n
"
);
fprintf
(
stderr
,
"Could not load new policy into kernel
\n
"
);
return
1
;
return
1
;
}
}
}
if
(
outfile
)
{
fp
=
fopen
(
outfile
,
"w"
);
if
(
!
fp
)
{
fprintf
(
stderr
,
"Could not open outfile
\n
"
);
return
1
;
}
policy_file_init
(
&
outpf
);
policy_file_init
(
&
outpf
);
outpf
.
type
=
PF_USE_STDIO
;
outpf
.
type
=
PF_USE_STDIO
;
outpf
.
fp
=
fp
;
outpf
.
fp
=
fp
;
if
(
policydb_write
(
&
policydb
,
&
outpf
))
{
if
(
policydb_write
(
&
policydb
,
&
outpf
))
{
fprintf
(
stderr
,
"Could not write policy
\n
"
);
fprintf
(
stderr
,
"Could not write policy
\n
"
);
return
1
;
return
1
;
}
fclose
(
fp
);
}
}
policydb_destroy
(
&
policydb
);
policydb_destroy
(
&
policydb
);
fclose
(
fp
);
return
0
;
return
0
;
}
}
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