偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

跟著小白一起學鴻蒙— SELinux簡析

系統(tǒng) OpenHarmony
SELinux(Security-Enhanced Linux) 是[美國國家安全局](NSA)對于[強制訪問控制]的實現(xiàn),是 Linux歷史上最杰出的新安全子系統(tǒng)。

??想了解更多關于開源的內容,請訪問:??

??51CTO 開源基礎軟件社區(qū)??

??https://ost.51cto.com??

SELinux

#創(chuàng)作者激勵# #跟著小白一起學鴻蒙# SELinux簡析-開源基礎軟件社區(qū)

SELinux說明

SELinux(Security-Enhanced Linux) 是[美國國家安全局](NSA)對于[強制訪問控制]的實現(xiàn),是 Linux歷史上最杰出的新安全子系統(tǒng)。NSA是在Linux社區(qū)的幫助下開發(fā)了一種訪問控制體系,在這種訪問控制體系的限制下,進程只能訪問那些在他的任務中所需要文件。SELinux 主要作用就是最大限度地減小系統(tǒng)中服務進程可訪問的資源(最小權限原則)。

SELinux基本概念

  • 主體Subjects:可以完全等同于進程。
  • 目標Objects:被主體訪問的資源??梢允俏募⒛夸?、端口、設備等。
  • 策略Policy:哪些進程需要管制、要怎么管制是由政策決定。規(guī)則是模塊化、可擴展的。在安裝新的應用程序時,應用程序可通過添加新的模塊來添加規(guī)則。用戶也可以手動地增減規(guī)則。
  • 模式Mode:默認有三種模式:
  • Enforcing 強制— SELinux 策略強制執(zhí)行,基于 SELinux 策略規(guī)則授予或拒絕主體對目標的訪問。
  • Permissive 寬容— SELinux 策略不強制執(zhí)行,不實際拒絕訪問,但會有拒絕信息寫入日志。
  • Disabled 禁用— 完全禁用SELinux。

OpenHarmony SELinux使用介紹

#創(chuàng)作者激勵# #跟著小白一起學鴻蒙# SELinux簡析-開源基礎軟件社區(qū)

OpenHarmony里的selinux部件負責對文件,屬性,服務等系統(tǒng)資源提供強制訪問控制保護。提供neverallow規(guī)則限制系統(tǒng)中的高危操作,減少系統(tǒng)安全風險。

文件結構(distributedatamgr):

├── BUILD.gn
├── bundle.json
├── config # 板側 三方庫配置文件
├── config.enforce
└── config.permissive
├── docs # 文檔
├── interfaces
├── policycoreutils # 板側 libload_policy.so, librestorecon.so
├── include
└── src
└── tools # 板側 load_policy, restorecon
├── hap_restorecon
├── load_policy
├── param_check
├── restorecon
└── service_check
├── LICENSE
├── OAT.xml
├── README-en.md
├── README.md
├── scripts # 編譯側 策略編譯腳本
├── selinux.gni
├── sepolicy # 編譯側 策略文件
├── base
├── public
├── system
└── te
└── ohos_policy
├── ability
├── ark
├── arkXtest
├── barrierfree
├── bundlemanager
├── cloud
├── communication
├── customization
├── developtools
├── deviceprofile
├── distributeddatamgr
├── distributedhardware
├── distributedschedule
├── drivers
├── dsoftbus
├── filemanagement
├── global
├── graphic
├── hiviewdfx
├── iam
├── kernel
├── location
├── misc
├── miscservices
├── msdp
├── multimedia
├── multimodalinput
├── notification
├── os_account
├── powermgr
├── print
├── resourceschedule
├── security
├── sensors
├── startup
├── telephony
├── test_framework
├── update
├── usb
├── useriam
├── web
├── window
└── xts
└── test

運行驗證:

  • 將鏡像燒錄到開發(fā)板上,開機,hdc_std shell登錄板子 ,在其中執(zhí)行:
ls -lZ /         # 查看文件標簽
ls -lLZ / # 查看link源文件標簽
ps -eZ # 查看進程標簽
setenforce 1 # 使能selinux強制模式
setenforce 0 # 是能selinux寬容模式,當前默認寬容模式
getenforce # 獲取selinux工作模式
  • 策略文件:/etc/selinux/targeted/policy/policy.31
  • 文件標簽規(guī)則 /etc/selinux/targeted/policy/file_contexts
  • selinux模式開關 /etc/selinux/config

日志解讀:

//使用dmsg查看日志
audit: type=1400 audit(1502458430.566:4): avc: denied { open } for pid=1658 comm="setenforce" path="/sys/fs/selinux/enforce" dev="selinuxfs" ino=4 scontext=u:r:hdcd:s0 tcontext=u:object_r:selinuxfs:s0 tclass=file permissive=1

//關鍵字:avc: denied

//日志解讀
open #操作為open
pid=1658 #訪問主體進程號為1658
comm="setenforce" #訪問主體進程名為setenforce
path="/sys/fs/selinux/enforce" #被訪問客體為/sys/fs/selinux/enforce
dev="selinuxfs" #被訪問文件屬于selinuxfs這一文件系統(tǒng)
ino=4 #文件節(jié)點編號為4
scontext=u:r:hdcd:s0 #訪問主體selinux標簽為u:r:hdcd:s0
tcontext=u:object_r:selinuxfs:s0 #被訪問客體selinux標簽為u:object_r:selinuxfs:s0
tclass=file #當前告警屬于file類型的操作
permissive=1 #當前selinux處于寬容模式,只告警不做訪問攔截。強制模式時,做攔截, permissive=0

//分析:
缺少啥權限:denied { open }
誰缺少權限:scontext=u:r:hdcd:s0
對哪個文件缺少:tcontext=u:object_r:selinuxfs:s0
什么類型:tclass=file
通用公式為:all {scontext} {tcontext}:{tclass} {denied權限}

策略編寫:

根據(jù)avc告警,獲取訪問信息
如:
audit: type=1400 audit(1502458430.566:4): avc: denied { open } for pid=1658 comm="setenforce" path="/sys/fs/selinux/enforce" dev="selinuxfs" ino=4 scontext=u:r:hdcd:s0 tcontext=u:object_r:selinuxfs:s0 tclass=file permissive=1
對應規(guī)則為
allow hdcd selinuxfs:file open;

提交倉:

  • 倉名:OpenHarmony? / security_selinux。
  • 位置:按照部件分類,比如wifi為sepolicy/ohos_policy/communication/wifi/system/xxx.te。
  • 加具體規(guī)則進對應te文件。

小結

SELinux是3.2增加的安全保護措施,所以如果我們開發(fā)了新服務,新框架,很有可能會碰到程序不能運行的問題,簡單的判斷方法有三種:

編譯大法:

找到這個文件:vendor/hihope/rk3568/config.json (不同的開發(fā)板文件不同哦)
改build_selinux為false
這樣鏡像就不支持selinux了,然后應該就能運行了,但是不推薦,破壞安全環(huán)境

臨時命令:

setenforce 0
使用此命令后,會關閉selinux判斷,但是下次重啟會恢復,此方法用于臨時驗證問題

增加te規(guī)則(如上解釋)。

??想了解更多關于開源的內容,請訪問:??

??51CTO 開源基礎軟件社區(qū)??

??https://ost.51cto.com??

責任編輯:jianghua 來源: 51CTO 開源基礎軟件社區(qū)
相關推薦

2022-12-05 15:02:14

鴻蒙用戶鑒權

2022-11-28 15:42:39

分布式軟總線鴻蒙

2022-11-22 15:15:46

Wi-Fi鴻蒙

2022-11-08 15:43:45

開源鴻蒙藍牙協(xié)議棧

2022-12-02 14:20:09

Tetris鴻蒙

2022-11-29 16:35:02

Tetris鴻蒙

2023-03-30 09:32:27

2022-11-14 17:01:34

游戲開發(fā)畫布功能

2023-04-04 09:24:11

鴻蒙HiDumper

2022-10-10 14:47:04

藍牙應用鴻蒙

2022-08-19 19:02:20

開源鴻蒙操作系統(tǒng)

2023-02-27 16:30:32

鴻蒙開源協(xié)議分析

2023-01-03 15:09:10

鴻蒙常用工具

2022-11-24 14:34:41

Hap程序鴻蒙

2023-03-15 16:19:03

BinderIPC工具

2022-12-06 15:39:16

鴻蒙主干代碼

2022-10-09 15:05:50

NAPI框架鴻蒙

2022-10-20 16:40:16

JS應用控制LED鴻蒙

2023-02-24 16:02:45

WebSocket網(wǎng)絡通訊協(xié)議

2022-10-17 14:29:24

鴻蒙應用開發(fā)
點贊
收藏

51CTO技術棧公眾號