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
没遇到过。可能是软件包的依赖关系问题,你原来的内核版本比这个高吗?我不确定内核是否影响软件包依赖。我只能说,试试更新管理器里,更新软件包,注意不要选择内核包。