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  존재한다. (제조사마다 다르다.)

다음을 추가한다.

(만약 busybox_exec 레이블이 neverallow에 등록되어 있다면 레이블 이름을 바꿔줘야한다.)


/system/vendor/bin/busybox u:object_r:busybox_exec:s0

busybox_exec가 레이블 이름이다.

ex)





busybox.te 파일 만들기


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

- allow 를 이용하여 정책을 등록한다.

<busybox.te>

1
2
3
type busybox_exec, exec_type, file_type;
 
allow netd busybox_exec:file rx_file_perms;
cs


- rx_file_perms 는 매크로이다.

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


- 안드로이드 8 이상부터는

BoardConfig.mk 파일에

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




 



+ Recent posts