반응형

 

 

 

neverallow 관련 처리

 기본적으로 neverallow 되어있는 곳은 system/sepolicy/public/domain.te 파일에 작성되어 있습니다. neverallow로 등록된 정책들은 단순히 allow만 해서 사용할 수 없습니다. allow로 처리를 해놔도 neverallow에서 걸러지기 때문입니다. 그래서 type을 따로 설정해서 사용해야 합니다.

 

busybox로 정책 처리 예


< 정책 위반으로 denied가 뜨는 로그 >

 type=1400 audit(0.0:34avc: denied { getattr } for path="/system/vendor/bin/busybox" dev="mmcblk0p7" ino=1713 scontext=u:r:netd:s0 tcontext=u:object_r:busybox_exec:s0 tclass=file permissive=1
 type=1400 audit(0.0:33avc: denied { getattr } for path="/system/vendor/bin/busybox" dev="mmcblk0p7" ino=1713 scontext=u:r:netd:s0 tcontext=u:object_r:busybox_exec:s0 tclass=file permissive=1
 type=1400 audit(0.0:35avc: denied { execute } for name="busybox" dev="mmcblk0p7" ino=1713 scontext=u:r:netd:s0 tcontext=u:object_r:busybox_exec:s0 tclass=file permissive=1

 type=1400 audit(0.0:36avc: denied { execute } for name="busybox" dev="mmcblk0p7" ino=1713 scontext=u:r:netd:s0 tcontext=u:object_r:busybox_exec:s0 tclass=file permissive=1
 type=1400 audit(0.0:38avc: denied { read open } for path="/system/vendor/bin/busybox" dev="mmcblk0p7" ino=1713 scontext=u:r:netd:s0 tcontext=u:object_r:busybox_exec:s0 tclass=file permissive=1
 type=1400 audit(0.0:37avc: denied { read open } for path="/system/vendor/bin/busybox" dev="mmcblk0p7" ino=1713 scontext=u:r:netd:s0 tcontext=u:object_r:busybox_exec:s0 tclass=file permissive=1
 type=1400 audit(0.0:39avc: denied { execute_no_trans } for path="/system/vendor/bin/busybox" dev="mmcblk0p7" ino=1713 scontext=u:r:netd:s0 tcontext=u:object_r:busybox_exec:s0 tclass=file permissive=1

- 위와 같이 로그가 뜨면 로그를 보고 파악 할 수 있다.

denied : 어떤이유로 거부되었는지 알 수 있다.

scontext : 사용하는 소스 프로세스 레이블  - 여기서는 netd

tcontext : 사용되는 타겟 오브젝트 레이블 - 여기서는 busybox_exec 

tclass : 사용되는 타겟 오브젝트 클래스 - 여기서는 file



 

file_contexts 파일 수정

파일위치는 보통 /device/[manufacturer]/[device-name]/sepolicy 존재합니다. 제조사마다 다릅니다.

 

allow 정책 등록

1. busybox.te 파일 만들기

2. sepolicy 디렉토리에 busybox.te 파일을 만들고 다음과 같이 작성

<busybox.te>

type busybox_exec, exec_type, file_type;
allow netd busybox_exec:file rx_file_perms;

- rx_file_perms 는 매크로이다.

/system/sepolicy/public/global_macros 에 가면 매크로를 볼 수 있다.

 

안드로이드 8 이상부터는

BoardConfig.mk 파일에

BOARD_SEPOLICY_DIR 변수에 sepolicy 폴더위치를 넣어줘야 한다



출처: https://gamdekong.tistory.com/154 [Be adventurous.]

 

 

출처/참고자료

 

https://gamdekong.tistory.com/154 

https://kldp.org/files/selinux_140.pdf   

반응형