SELinux 權(quán)限

如何根據(jù)log 信息修改SELinux 權(quán)限

當(dāng)出現(xiàn) SELinux 權(quán)限不足時,可根據(jù)LOG 信息提示進(jìn)行相應(yīng)的修改。下面介紹如何根據(jù) kernel log 來查看信息

1. disable selinux

在終端下

su
setenforce 0

該操作主要是為了禁用系統(tǒng)SELinux序无,讓權(quán)限暫時通過试幽。但是依然是會輸出 SELinux 校驗時的LOG。后面根據(jù)輸出的LOG 進(jìn)行相應(yīng)的處理。

2. 查看kernel log

復(fù)現(xiàn)問題垢粮,導(dǎo)出 kernel log.

或者 adb shell su 之后輸入 cat /dev/kmsg | grep avc 在控制臺輸出關(guān)鍵信息

kernel 日志的輸出在 /dev/kmsg 節(jié)點下,avcSELinux 打印的信息

如:

5,4978,791423968,-;audit: type=1400 audit(1556096333.959:26): avc:  denied  { write } for  pid=5106 comm="Log_LogStrategy" name="Logs_Collector" dev="mmcblk0p40" ino=16321 scontext=u:r:system_app:s0 tcontext=u:object_r:system_data_file:s0 tclass=dir permissive=1
5,4979,791424019,-;audit: type=1400 audit(1556096333.959:27): avc:  denied  { add_name } for  pid=5106 comm="Log_LogStrategy" name="amefrktoukgokiph_20190424165853.zip" scontext=u:r:system_app:s0 tcontext=u:object_r:system_data_file:s0 tclass=dir permissive=1
5,4980,791424176,-;audit: type=1400 audit(1556096333.959:28): avc:  denied  { create } for  pid=5106 comm="Log_LogStrategy" name="amefrktoukgokiph_20190424165853.zip" scontext=u:r:system_app:s0 tcontext=u:object_r:system_data_file:s0 tclass=file permissive=1
5,4981,791425437,-;audit: type=1400 audit(1556096333.959:29): avc:  denied  { write } for  pid=5106 comm="Log_LogStrategy" path="/data/Logs_Collector/amefrktoukgokiph_20190424165853.zip" dev="mmcblk0p40" ino=16331 scontext=u:r:system_app:s0 tcontext=u:object_r:system_data_file:s0 tclass=file permissive=1
5,4982,797691545,-;audit: type=1400 audit(1556096340.229:30): avc:  denied  { remove_name } for  pid=5086 comm="xtc.systemagent" name="amefrktoukgokiph_20190424165853.zip" dev="mmcblk0p40" ino=16331 scontext=u:r:system_app:s0 tcontext=u:object_r:system_data_file:s0 tclass=dir permissive=1
5,4983,797691614,-;audit: type=1400 audit(1556096340.229:31): avc:  denied  { rename } for  pid=5086 comm="xtc.systemagent" name="amefrktoukgokiph_20190424165853.zip" dev="mmcblk0p40" ino=16331 scontext=u:r:system_app:s0 tcontext=u:object_r:system_data_file:s0 tclass=file permissive=1
5,4984,797693717,-;audit: type=1400 audit(1556096340.229:32): avc:  denied  { unlink } for  pid=5086 comm="xtc.systemagent" name="1556096340234" dev="mmcblk0p40" ino=16331 scontext=u:r:system_app:s0 tcontext=u:object_r:system_data_file:s0 tclass=file permissive=1

3. 修改te 文件

  • 3.1 找到對應(yīng)的domain

如:

scontext=u:r:system_app:s0

domainsystem_app靠粪, 所以需要修改 system/sepolicy/system_app.te 文件

  • 3.2 找到 target 和 Object Class

如:

tcontext=u:object_r:system_data_file:s0 tclass=dir

targetsystem_data_file, object classdir

  • 3.3 找到缺失的權(quán)限

如:

denied  { add_name }

缺失的權(quán)限為: add_name

  • 3.4 最后整合整個缺失的權(quán)限蜡吧,統(tǒng)一處理

最后針對上面的權(quán)限提示修改的 system/sepolicy/system_app.te 為,增加如下內(nèi)容:

allow system_app system_data_file:dir { add_name remove_name rw_dir_perms };
allow system_app system_data_file:file { create rename unlink rw_file_perms };

格式(分號結(jié)尾)

allow scontext tcontext:tclass { perm };

4. 檢查是否違反了 neverallow

可以先進(jìn)行嘗試編譯占键,若有違反 neverallowSELinux 定義昔善,會編譯不通過,同時會提示哪個 te 文件中定義的 neverallow 沖突了畔乙。

如上面的修改會導(dǎo)致 system/sepolicy/app.te 文件中的 neverallow 規(guī)則有沖突君仆。

原先沖突的 nerverallow 定義為:

# Write to system-owned parts of /data.
# This is the default type for anything under /data not otherwise
# specified in file_contexts.  Define a different type for portions
# that should be writable by apps.
neverallow { appdomain} system_data_file:dir_file_class_set
    { create write setattr relabelfrom relabelto append unlink link rename };

這里定義了不允許 system_data_filetarget 進(jìn)行 create write unlink 等操作

此時解決方法是,需要過濾去除掉我們需要的 domain

進(jìn)行修改如下:

neverallow { appdomain -system_app }
    system_data_file:dir_file_class_set
    { create write setattr relabelfrom relabelto append unlink link rename };

加上 -system_app 的排除語法牲距。

5. 重編系統(tǒng)

至此根據(jù) kernel log 信息提取權(quán)限完成返咱,重新編譯系統(tǒng)。

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末牍鞠,一起剝皮案震驚了整個濱河市咖摹,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌难述,老刑警劉巖萤晴,帶你破解...
    沈念sama閱讀 216,402評論 6 499
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異胁后,居然都是意外死亡店读,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,377評論 3 392
  • 文/潘曉璐 我一進(jìn)店門攀芯,熙熙樓的掌柜王于貴愁眉苦臉地迎上來屯断,“玉大人,你說我怎么就攤上這事敲才」桑” “怎么了?”我有些...
    開封第一講書人閱讀 162,483評論 0 353
  • 文/不壞的土叔 我叫張陵紧武,是天一觀的道長剃氧。 經(jīng)常有香客問我,道長阻星,這世上最難降的妖魔是什么朋鞍? 我笑而不...
    開封第一講書人閱讀 58,165評論 1 292
  • 正文 為了忘掉前任已添,我火速辦了婚禮,結(jié)果婚禮上滥酥,老公的妹妹穿的比我還像新娘更舞。我一直安慰自己,他們只是感情好坎吻,可當(dāng)我...
    茶點故事閱讀 67,176評論 6 388
  • 文/花漫 我一把揭開白布缆蝉。 她就那樣靜靜地躺著,像睡著了一般瘦真。 火紅的嫁衣襯著肌膚如雪刊头。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,146評論 1 297
  • 那天诸尽,我揣著相機(jī)與錄音原杂,去河邊找鬼。 笑死您机,一個胖子當(dāng)著我的面吹牛穿肄,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播际看,決...
    沈念sama閱讀 40,032評論 3 417
  • 文/蒼蘭香墨 我猛地睜開眼咸产,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了仿村?” 一聲冷哼從身側(cè)響起锐朴,我...
    開封第一講書人閱讀 38,896評論 0 274
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎蔼囊,沒想到半個月后焚志,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,311評論 1 310
  • 正文 獨居荒郊野嶺守林人離奇死亡畏鼓,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,536評論 2 332
  • 正文 我和宋清朗相戀三年酱酬,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片云矫。...
    茶點故事閱讀 39,696評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡膳沽,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出让禀,到底是詐尸還是另有隱情挑社,我是刑警寧澤,帶...
    沈念sama閱讀 35,413評論 5 343
  • 正文 年R本政府宣布巡揍,位于F島的核電站痛阻,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏腮敌。R本人自食惡果不足惜阱当,卻給世界環(huán)境...
    茶點故事閱讀 41,008評論 3 325
  • 文/蒙蒙 一俏扩、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧弊添,春花似錦录淡、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,659評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至免钻,卻和暖如春彼水,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背极舔。 一陣腳步聲響...
    開封第一講書人閱讀 32,815評論 1 269
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點兒被人妖公主榨干…… 1. 我叫王不留链瓦,地道東北人拆魏。 一個月前我還...
    沈念sama閱讀 47,698評論 2 368
  • 正文 我出身青樓,卻偏偏與公主長得像慈俯,于是被迫代替她去往敵國和親渤刃。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 44,592評論 2 353

推薦閱讀更多精彩內(nèi)容