selinux編譯
❶ make allnoconfig編譯linux內核出錯,求指點
正確的步驟是;
yum -y install make automake gcc g++ ncurses ncurses-dev ncurses-devel fakeroot wget bzip2 make patch ftp
cp /boot/config-2.6.18-92.el5 .config
關閉Selinux
vi /etc/sysconfig/selinux
SELINUX=disabled
打IMQ補丁:
$patch -p1 < ../linux-2.6.25-imq5.diff
$make menuconfig
驅動模塊
IMQ (intermediate queueing device) support (IMQ)
Location:
-> Device Drivers
-> Networking support
-> Network device support (NETDEVICES)
-> IMQ (intermediate queueing device) support (IMQ)
2.2編譯並安裝新內核
make menuconfig
make
make moles
make moles_install
make install
mkinitrd /boot/initrd_2.6.30.img 2.6.30 根據內核版本和指定參數生成映像文件
cp arch/x86/boot/bzImage /boot/vmlinuz-2.6.30
cp /usr/src/linux-2.6.30/System.map /boot/System.map-2.6.30
❷ 如何設置SELinux 策略規則
[SELinux Policy]如何設置SELinux策略規則?
[Description]
android KK 4.4 版本後,Google 默認啟用了SELinux, 並會把SELinux 審查異常列印在kernel log
或者 android log(L 版本)中,對應的關鍵字是: "avc: denied" 或者"avc: denied"
如一行LOG:
<5>[ 17.285600].(0)[503:idmap]type=1400 audit(1356999072.320:202): avc: denied { create
} for pid=503 comm="idmap" name="overlays.list" scontext=u:r:zygote:s0
tcontext=ubject_r:resource_cache_data_file:s0 tclass=file
即表明idmap 這個process, 使用zygote 的source context, 訪問/data/resource_cache 目錄,並
創建文件時,被SELinux 拒絕訪問。
[Keyword]
android, SELinux, avc: denied, audit
[Solution]
KK 版本, Google 只有限制的啟用SELinux, 即只有針對netd, installd, zygote, vold 以及它們
直接fork 出的child process 使用enforcing mode, 但不包括zygote fork的普通app.
L 版本, Google 全面開啟SELinux, 幾乎所有的process 都使enforcing mode, 影響面非常廣.
目前所有的SELinux check 失敗,在kernel log 或者android log(L版本後)中都有對應的"avc:
denied" 或者 "avc: denied"的LOG 與之對應。反過來,有此LOG,並非就會直接失敗,還需要確認
當時SELinux 的模式, 是enforcing mode 還是 permissve mode.
首先, 務必確認對應進程訪問系統資源是否正常, 是否有必要 看如果本身是異常非法訪問,那麼
就要自行消除訪問。
其次, 如果確認訪問是必要,並且正常的,那麼就要對對應的process/domain 增加新的policy.
1). 簡化方法
1.1 提取所有的avc LOG. 如 adb shell "cat /proc/kmsg | grep avc" > avc_log.txt
1.2 使用 audit2allow tool 直接生成policy. audit2allow -i avc_log.txt 即可自動輸出生成的
policy
1.3 將對應的policy 添加到selinux policy 規則中,對應MTK Solution, 您可以將它們添加在KK:
mediatek/custom/common/sepolicy, L: device/mediatek/common/sepolicy 下面,如
allow zygote resource_cache_data_file:dir rw_dir_perms;
allow zygote resource_cache_data_file:file create_file_perms;
===> mediatek/custom/common/sepolicy/zygote.te (KK)
===> device/mediatek/common/sepolicy/zygote.te (L)
注意audit2allow 它自動機械的幫您將LOG 轉換成policy, 而無法知道你操作的真實意圖,有可能
出現許可權放大問題,經常出現policy 無法編譯通過的情況。
2). 按需確認方法
此方法需要工程人員對SELinux 基本原理,以及SELinux Policy Language 有了解.
2.1 確認是哪個進程訪問哪個資源,具體需要哪些訪問許可權,read ? write ? exec ? create ?
search ?
2.2 當前進程是否已經創建了policy 文件看 通常是process 的執行檔.te,如果沒有,並且它的父
進程即source context 無須訪問對應的資源,則創建新的te 文件.
在L 版本上, Google 要求維護關鍵 security context 的唯一性, 比如嚴禁zygote, netd,
installd, vold, ueventd 等關鍵process 與其它process 共享同一個security context.
2.3 創建文件後,關聯它的執行檔,在file_contexts 中, 關聯相關的執行檔.
比如 /system/bin/idmap 則是 /system/bin/idmap ubject_r:idmap_exec:s0
2.4 填寫policy 到相關的te 文件中
如果沿用原來父進程的te 文件,則直接添加.
如果是新的文件,那麼首先:
#==============================================
# Type Declaration
#==============================================
type idmap, domain;
type idmap_exec, exec_type,file_type;
#==============================================
# Android Policy Rule
#==============================================
#permissive idmap;
domain_auto_trans(zygote, idmap_exec, idmap);
然後添加新的policy
# new policy
allow idmap resource_cache_data_file:dir rw_dir_perms;
allow idmap resource_cache_data_file:file create_file_perms;
3). 許可權放大情況處理
如果直接按照avc: denied 的LOG 轉換出SELinux Policy, 往往會產生許可權放大問題. 比如因為要
訪問某個device, 在這個device 沒有細化SELinux Label 的情況下, 可能出現:
<7>[11281.586780] avc: denied { read write } for pid=1217 comm="mediaserver"
name="tfa9897" dev="tmpfs" ino=4385 scontext=u:r:mediaserver:s0
tcontext=ubject_r:device:s0 tclass=chr_file permissive=0
如果直接按照此LOG 轉換出SELinux Policy: allow mediaserver device:chr_file {read write};
那麼就會放開mediaserver 讀寫所有device 的許可權. 而Google 為了防止這樣的情況, 使用了
neverallow 語句來約束, 這樣你編譯sepolicy 時就無法編譯通過.
為了規避這種許可權放大情況, 我們需要細化訪問目標(Object) 的SELinux Label, 做到按需申請.
通常會由三步構成
3.1 定義相關的SELinux type.
比如上述案例, 在 device/mediatek/common/sepolicy/device.te 添加
type tfa9897_device, dev_type;
3.2 綁定文件與SELinux type.
比如上述案例, 在 device/mediatek/common/sepolicy/file_contexts 添加
/dev/tfa9897(/.*)? ubject_r:tfa9897_device:s0
3.3 添加對應process/domain 的訪問許可權.
比如上述案例, 在 device/mediatek/common/sepolicy/mediaserver.te 添加
allow mediaserver tfa9897_device:chr_file { open read write };
那麼哪些訪問對象通常會遇到此類呢看(以L 版本為例)
* device
-- 類型定義: external/sepolicy/device.te;device/mediatek/common/sepolicy/device.te
-- 類型綁定:
external/sepolicy/file_contexts;device/mediatek/common/sepolicy/file_contexts
* File 類型:
-- 類型定義: external/sepolicy/file.te;device/mediatek/common/sepolicy/file.te
-- 綁定類型:
external/sepolicy/file_contexts;device/mediatek/common/sepolicy/file_contexts
* 虛擬File 類型:
-- 類型定義: external/sepolicy/file.te;device/mediatek/common/sepolicy/file.te
-- 綁定類型:
external/sepolicy/genfs_contexts;device/mediatek/common/sepolicy/genfs_contexts
* Service 類型:
-- 類型定義: external/sepolicy/service.te; device/mediatek/common/sepolicy/service.te
-- 綁定類型
:external/sepolicyservice_contexts;device/mediatek/common/sepolicy/service_contexts
* Property 類型:
-- 類型定義: external/sepolicy/property.te;device/mediatek/common/sepolicy/property.te
-- 綁定類型:
external/sepolicy/property_contexts;device/mediatek/common/sepolicy/property_contexts;
通常我們強烈反對更新google default 的policy, 大家可以更新mediatek 下面的相關的policy.
❸ 安卓關閉selinux好處
你好朋友
1. 禁止selinux
1.1 在內核中關閉selinux編譯選項CONFIG_SECURITY_SELINUX
1.2 還可以在system.prop中定義ro.boot.selinux=disable
這兩種方法都可以禁用selinux,也可以設置成ro.boot.selinux=permissive
寬容模式
1.3 可以通過setenforce1開啟enforce模式,setenforce 0為permissive模式
getenforce獲取當前模式
2. 所有安全策略最終編譯成sepolicy文件放在root目錄下,init進程啟動後會讀取/sepolicy策略文件,並通過/sys/fs/selinux/load節點
把策略文件內容寫入內核
3 安全上下文存放root目錄
/etc/security/mac_permissions.xml
/file_contexts //系統中所有file_contexts安全上下文
/seapp_contexts //app安全上下文
/property_contexts //屬性的安全上下文
/service_contexts //service文件安全上下文
genfs_contexts //虛擬文件系統安全上下文
4. app在/data/data/文件的安全上下文設置過程
1. 根據uid,pkgname,seinfo在seapp_contexts中匹配.
2. 根據匹配到的contexts,重新設置給相對應文件
5. 系統中所有的object class 定義在external/sepolicy/security_classes中.
object class使用在allow語句中,object class所具有的操作定義在external/sepolicy/access_vectors
文件中
6 allow語句
allow語句用來許可權設置
rule_name source_type target_type : class perm_set
rule_name : 有allow,neverallow
source_type : 許可權主體,表示source_type對target_type有perm_set描述的許可權
如:
allow zygote init:process sigchld
允許zygote域裡面的進程可對init域的進程發送sigchld信號
typeattribute表示把屬性和type關聯起來
7 role定義
Android系統中的role定義在external/sepolicy/roles中,
目前只定義了r
8 socket使用
以/data/misc/wifi/sockets/wlan0 socket來說明使用方法
1. 定義socket type
type wpa_socket ,file_type
2. 指定安全上下文
/data/misc/wifi/sockets(/.*)? u:object_r:wpa_socket:s0
給/data/misc/wifi/sockets目錄下所有的文件統一指定安全上下文為wpa_socket
3.聲明socket使用許可權
在進程te中使用unix_socket_send(clientdomain, wpa, serverdomain)即可建立socket連接
9binder使用
在使用binder進程的te中根據情況使用如下宏:
binder_use(domain)//允許domain域中的進程使用binder通信
binder_call(clientdomain, serverdomain)//允許clientdomain和serverdomain域中的進程通信
binder_service(domain)//標志domain為service端
10 文件的使用
以/dev/wmtWifi來說明:
1.定義type
type wmtWifi_device dev_type //dev_type用來標志/dev/下的文件
2.給/dev/wmtWifi指定完全上下文
/dev/wmtWifi(/.*)? u:object_r:wmtWifi_device:s0
3.進程許可權設置
在進程te文件中allow許可權
allow netd wmtWifi_device:chr_file { write open };
11 property 屬性設置
以藍牙的各種屬性來說明
1.定義type
type bluetooth_prop, property_type;
2設置安全上下文
bluetooth. u:object_r:bluetooth_prop:s0
3進程許可權設置
allow bluetooth bluetooth_prop:property_service set;
5 專業詞彙
MLS :Multi-Level Security
RBAC :Role Based Access Control
DAC :Discretionary Access Control
MAC :Mandatory Access Control
TEAC :Type Enforcement Accesc Control
望採納祝你好運
❹ centos7 編譯安裝完openssh 7.5,連接出現異常
selinux 埠允許了嗎?
yum install policycoreutils-python
semanage port -l |grep ssh
semanage port -a -t ssh_port_t -p tcp 埠號
systemctl restart sshd.service
❺ 如何設置SELinux 策略規則
[SELinux Policy]如何設置SELinux策略規則?
[Description]
android KK 4.4 版本後,Google 默認啟用了SELinux, 並會把SELinux 審查異常列印在kernel log
或者 android log(L 版本)中,對應的關鍵字是: "avc: denied" 或者"avc: denied"
如一行LOG:
<5>[ 17.285600].(0)[503:idmap]type=1400 audit(1356999072.320:202): avc: denied { create
} for pid=503 comm="idmap" name="overlays.list" scontext=u:r:zygote:s0
tcontext=ubject_r:resource_cache_data_file:s0 tclass=file
即表明idmap 這個process, 使用zygote 的source context, 訪問/data/resource_cache 目錄,並
創建文件時,被SELinux 拒絕訪問。
[Keyword]
android, SELinux, avc: denied, audit
[Solution]
KK 版本, Google 只有限制的啟用SELinux, 即只有針對netd, installd, zygote, vold 以及它們
直接fork 出的child process 使用enforcing mode, 但不包括zygote fork的普通app.
L 版本, Google 全面開啟SELinux, 幾乎所有的process 都使enforcing mode, 影響面非常廣.
目前所有的SELinux check 失敗,在kernel log 或者android log(L版本後)中都有對應的"avc:
denied" 或者 "avc: denied"的LOG 與之對應。反過來,有此LOG,並非就會直接失敗,還需要確認
當時SELinux 的模式, 是enforcing mode 還是 permissve mode.
首先, 務必確認對應進程訪問系統資源是否正常, 是否有必要 ?如果本身是異常非法訪問,那麼
就要自行消除訪問。
其次, 如果確認訪問是必要,並且正常的,那麼就要對對應的process/domain 增加新的policy.
1). 簡化方法
1.1 提取所有的avc LOG. 如 adb shell "cat /proc/kmsg | grep avc" > avc_log.txt
1.2 使用 audit2allow tool 直接生成policy. audit2allow -i avc_log.txt 即可自動輸出生成的
policy
1.3 將對應的policy 添加到selinux policy 規則中,對應MTK Solution, 您可以將它們添加在KK:
mediatek/custom/common/sepolicy, L: device/mediatek/common/sepolicy 下面,如
allow zygote resource_cache_data_file:dir rw_dir_perms;
allow zygote resource_cache_data_file:file create_file_perms;
===> mediatek/custom/common/sepolicy/zygote.te (KK)
===> device/mediatek/common/sepolicy/zygote.te (L)
注意audit2allow 它自動機械的幫您將LOG 轉換成policy, 而無法知道你操作的真實意圖,有可能
出現許可權放大問題,經常出現policy 無法編譯通過的情況。
2). 按需確認方法
此方法需要工程人員對SELinux 基本原理,以及SELinux Policy Language 有了解.
2.1 確認是哪個進程訪問哪個資源,具體需要哪些訪問許可權,read ? write ? exec ? create ?
search ?
2.2 當前進程是否已經創建了policy 文件? 通常是process 的執行檔.te,如果沒有,並且它的父
進程即source context 無須訪問對應的資源,則創建新的te 文件.
在L 版本上, Google 要求維護關鍵 security context 的唯一性, 比如嚴禁zygote, netd,
installd, vold, ueventd 等關鍵process 與其它process 共享同一個security context.
2.3 創建文件後,關聯它的執行檔,在file_contexts 中, 關聯相關的執行檔.
比如 /system/bin/idmap 則是 /system/bin/idmap ubject_r:idmap_exec:s0
2.4 填寫policy 到相關的te 文件中
如果沿用原來父進程的te 文件,則直接添加.
如果是新的文件,那麼首先:
#==============================================
# Type Declaration
#==============================================
type idmap, domain;
type idmap_exec, exec_type,file_type;
#==============================================
# Android Policy Rule
#==============================================
#permissive idmap;
domain_auto_trans(zygote, idmap_exec, idmap);
然後添加新的policy
# new policy
allow idmap resource_cache_data_file:dir rw_dir_perms;
allow idmap resource_cache_data_file:file create_file_perms;
3). 許可權放大情況處理
如果直接按照avc: denied 的LOG 轉換出SELinux Policy, 往往會產生許可權放大問題. 比如因為要
訪問某個device, 在這個device 沒有細化SELinux Label 的情況下, 可能出現:
<7>[11281.586780] avc: denied { read write } for pid=1217 comm="mediaserver"
name="tfa9897" dev="tmpfs" ino=4385 scontext=u:r:mediaserver:s0
tcontext=ubject_r:device:s0 tclass=chr_file permissive=0
如果直接按照此LOG 轉換出SELinux Policy: allow mediaserver device:chr_file {read write};
那麼就會放開mediaserver 讀寫所有device 的許可權. 而Google 為了防止這樣的情況, 使用了
neverallow 語句來約束, 這樣你編譯sepolicy 時就無法編譯通過.
為了規避這種許可權放大情況, 我們需要細化訪問目標(Object) 的SELinux Label, 做到按需申請.
通常會由三步構成
3.1 定義相關的SELinux type.
比如上述案例, 在 device/mediatek/common/sepolicy/device.te 添加
type tfa9897_device, dev_type;
3.2 綁定文件與SELinux type.
比如上述案例, 在 device/mediatek/common/sepolicy/file_contexts 添加
/dev/tfa9897(/.*)? ubject_r:tfa9897_device:s0
3.3 添加對應process/domain 的訪問許可權.
比如上述案例, 在 device/mediatek/common/sepolicy/mediaserver.te 添加
allow mediaserver tfa9897_device:chr_file { open read write };
那麼哪些訪問對象通常會遇到此類呢?(以L 版本為例)
* device
-- 類型定義: external/sepolicy/device.te;device/mediatek/common/sepolicy/device.te
-- 類型綁定:
external/sepolicy/file_contexts;device/mediatek/common/sepolicy/file_contexts
* File 類型:
-- 類型定義: external/sepolicy/file.te;device/mediatek/common/sepolicy/file.te
-- 綁定類型:
external/sepolicy/file_contexts;device/mediatek/common/sepolicy/file_contexts
* 虛擬File 類型:
-- 類型定義: external/sepolicy/file.te;device/mediatek/common/sepolicy/file.te
-- 綁定類型:
external/sepolicy/genfs_contexts;device/mediatek/common/sepolicy/genfs_contexts
* Service 類型:
-- 類型定義: external/sepolicy/service.te; device/mediatek/common/sepolicy/service.te
-- 綁定類型
:external/sepolicyservice_contexts;device/mediatek/common/sepolicy/service_contexts
* Property 類型:
-- 類型定義: external/sepolicy/property.te;device/mediatek/common/sepolicy/property.te
-- 綁定類型:
external/sepolicy/property_contexts;device/mediatek/common/sepolicy/property_contexts;
通常我們強烈反對更新google default 的policy, 大家可以更新mediatek 下面的相關的policy.
❻ adb環境下的root許可權獲取
1
1.使用非系統進程通過su命令可以將自身提權到root許可權代碼
❼ 我已經完成了ubuntu10.10的內核編譯,現在是2.6.33.20的內核,為什麼還是不能安裝selinux
沒遇到過。可能是軟體包的依賴關系問題,你原來的內核版本比這個高嗎?我不確定內核是否影響軟體包依賴。我只能說,試試更新管理器里,更新軟體包,注意不要選擇內核包。