如何解决SELinux问题

作者&投稿:彘丽 (若有异议请与网页底部的电邮联系)
如何在开启selinux前提下解决此问题~

以下介绍一下SELinux相关的工具
/usr/bin/setenforce 修改SELinux的实时运行模式
setenforce 1 设置SELinux 成为enforcing模式
setenforce 0 设置SELinux 成为permissive模式
如果要彻底禁用SELinux 需要在/etc/sysconfig/selinux中设置参数selinux=0
,或者在/etc/grub.conf中添加这个参数
/usr/bin/setstatus -v
察看系统的状态
以下是运行输出,请参考
SELinux status: enabled
SELinuxfs mount: /selinux
Current mode: enforcing
Policy version: 18

不重启关闭selinux的解决办法:
执行命令:setenforce 0
在新版本中的Red Hat 和 Fedora 上,修改档案/etc/sysconfig/selinux:
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - SELinux is fully disabled.
SELINUX=enforcing

# SELINUXTYPE= type of policy in use. Possible values are:
# targeted - Only targeted network daemons are protected.
# strict - Full SELinux protection.
SELINUXTYPE=targeted

把 SELINUX设定为disable, 下次启动系统后将会停止SElinux。
Linux核心参数(Kernel Parameter)

或者可以在核心参数后加上: selinux=0 (停止) 或 selinux=1 (开启)参数

档案/boot/grub/menu.lst

title Fedora Core (2.6.18-1.2798.fc6)
root (hd0,0)
kernel /vmlinuz-2.6.18-1.2798.fc6 ro root=LABEL=/ rhgb quiet selinux=0
initrd /initrd-2.6.18-1.2798.fc6.img

检查SELinux现时况态

要知到你现在是否使用 SELinux:

# getenforce
disabled

android KK 4.4 版本后,如果发现进程无法访问某些文件,无法连接socket 等问题,并且发现errno 是EPERM(Operation not permitted) 或者 EACCES (Permission denied), 如何确认此类问题是因为SELinux 约束引起?

[Keyword]
android, SELinux, Permission denied, 访问限制, 权限问题

[Solution]
在Android KK 4.4 版本后,Google 有正式有限制的启用SELinux, 来增强android 的安全保护。
SELinux 分成enforcing mode 和 permissive mode, enforcing mode 会强制性限制访问; 而permissve mode 只审查权限, 但不限制, 即不会产生实质性影响.

KK 版本, Google 只有限制的启用SELinux, 即只有针对netd, installd, zygote, vold 以及它们直接fork 出的child process 使用enforcing mode, 但不包括zygote fork的普通app.

L 版本, Google 全面开启SELinux, 几乎所有的process 都使enforcing mode, 影响面非常广.

另外为了限制user 版本root 权限,针对su 有做特别的处理,可以参考FAQ android KK 4.4 版本后,user 版本su 权限严重被限制问题说明

目前所有的SELinux check 失败,在kernel log 或者android log(L版本后)中都有对应的"avc: denied" 或者 "avc: denied"的LOG 与之对应。反过来,有此LOG,并非就会直接失败,还需要确认当时SELinux 的模式, 是enforcing mode 还是 permissve mode.

如果问题容易复现,我们可以先将SELinux 模式调整到Permissive mode,然后再测试确认是否与SELinux 约束相关.
在ENG 版本中:
adb shell setenforce 0

  首先需要确认SELinux处于激活状态,可以使用getenforce命令:
  shell> getenforce
Enforcing

  或者使用sestatus命令:
  shell> sestatus
SELinux status: enabled
SELinuxfs mount: /selinux
Current mode: enforcing
Mode from config file: enforcing
Policy version: 24
Policy from config file: targeted

  注:关于SELinux的基础知识介绍请参考鸟哥的Linux私房菜中相关的介绍。
  我们还需要确认系统已经安装并启动了Apache,没有的话就YUM装一个,这很简单,就不多说了,接着在root目录创建一个测试文件test.html,如下:
  shell> cat /root/test.html
hello, world.

  然后把这个测试文件拷贝到Apache的DocumentRoot目录,我的Apache是通过YUM安装的话,缺省是/var/www/html目录,如下:
  shell> cp /root/test.html /var/www/html

  接着浏览一下,如果没出什么幺蛾子,应该一切都在意料之中,如下:
  shell> curl http://localhost/test.html
hello, world.

  看到这,你可能觉得我废话连篇,别着急,下面就是见证奇迹的时候了:
  同样还是那个测试文件test.html,不过这次不再是拷贝,而是移动,如下:
  shell> mv /root/test.html /var/www/html

  接着浏览一下,怎么样,结果很出人意料吧,竟然提示权限错误,如下:
  shell> curl http://localhost/test.html
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>403 Forbidden</title>
</head><body>
<h1>Forbidden</h1>
<p>You don't have permission to access /test.html
on this server.</p>
</body></html>

  当然,我们现在知道这个问题是由于SELinux引起的,但还不知其所以然,实际上问题的原因此时已经被audit进程记录到了相应的日志里,可以这样查看:
  shell> audit2why < /var/log/audit/audit.log

  如果看不懂的话,推荐安装setroubleshoot套件:
  shell> yum install setroubleshoot

  它本身是一个GUI套件,不过其中包含的一个sealert命令对我们命令行用户很有用:
  shell> sealert -a /var/log/audit/audit.log
Summary:

SELinux is preventing /usr/sbin/httpd "getattr" access to
/var/www/html/test.html.

Detailed Description:

SELinux denied access requested by httpd. /var/www/html/test.html may be a
mislabeled. /var/www/html/test.html default SELinux type is httpd_sys_content_t,
but its current type is admin_home_t. Changing this file back to the default
type, may fix your problem.

File contexts can be assigned to a file in the following ways.

* Files created in a directory receive the file context of the parent
directory by default.
* The SELinux policy might override the default label inherited from the
parent directory by specifying a process running in context A which creates
a file in a directory labeled B will instead create the file with label C.
An example of this would be the dhcp client running with the dhclient_t type
and creating a file in the directory /etc. This file would normally receive
the etc_t type due to parental inheritance but instead the file is labeled
with the net_conf_t type because the SELinux policy specifies this.
* Users can change the file context on a file using tools such as chcon, or
restorecon.

This file could have been mislabeled either by user error, or if an normally
confined application was run under the wrong domain.

However, this might also indicate a bug in SELinux because the file should not
have been labeled with this type.

If you believe this is a bug, please file a bug report against this package.

Allowing Access:

You can restore the default system context to this file by executing the
restorecon command. restorecon '/var/www/html/test.html', if this file is a
directory, you can recursively restore using restorecon -R
'/var/www/html/test.html'.

Fix Command:

/sbin/restorecon '/var/www/html/test.html'

  这次应该看懂了吧!原因是说Apache下文件上下文类型应该是httpd_sys_content_t,但是现在是admin_home_t,所以权限错误,并且在结尾处给出了修复命令。
  可httpd_sys_content_t,admin_home_t都怎么看啊?很简单,借助ls命令的-Z参数即可:
  shell> ls -Z /path

  回到问题的开始,拷贝之所以没出现问题,是因为cp自动修改上下文属性,而移动之所以出现问题是因为mv保留原文件的上下文属性。
  注:关于SELinux和Apache的详细介绍,可以参考『man httpd_selinux』。
  知道了如何解决SELinux问题,以后如果遇到类似的情况不要急着武断的关闭SELinux。

上面有个小错,应该是echo "0" > /selinux/enforce (少了>)selinux如果有开很容易造成ifind问题,参看下面系统日志Aug 2 20:52:06 cc-lnx-imglib setroubleshoot: SELinux is preventing /opt/simpana/iDataAgent/ifind "execstack" access to . For complete SELinux messages. run sealert -l 4a0b3993-b18f-4c72-9e1d-4f5d8175ad41Jul 31 00:30:09 cc-lnx-imglib setroubleshoot: SELinux is preventing /bin/hostname access to a leaked /tmp/.gxsetup/cvpkglo g.pipe.26262 file descriptor. For complete SELinux messages. run sealert -l e675a6a6-efc9-461f-b794-784c0fd2d308

有碰到即使是permissive也不行的,最后是改成disabled后重启机器才可以。

别一种查看SElinux方法:# sestatusSELinux status: disabled


我是大地一前苏联的什么电影?
\/ Galina Saburova \/Ruslan Salkovsky \/Sergei Selin \/Anatoli Shvedersky\/ Yelena Smolina\/ Irina Sobanova\/ Vladimir Soshalsky \/Marina Tregubovich\/ Larisa Troyakova\/ Andrei Urgant \/Tamara Urzhinova \/Tatyana Veselova \/Vera Voronkova \/Izil Zabludovsky \/Anatoli Zhuravlyov \/Viktor Zozu...

急找一个以监狱为题材的老电影
Simdi Mahkum)中文名称:监狱进行时 英文名称:O Simdi Mahkum 资源类型:DVDRip 发行时间:2005年 电影导演:Abdullah Oguz 电影演员:Ümit Acar (Baba)Peker Acikalin (Erketeci)Zafer Algoz (Koko Niyazi)Selin Arat (ANS Danisman Kiz)Melih Atalay (Komiser)地区:土耳其 语言:土耳其语 ...

梁其姿的专书
《人观、意义与社会》(论文集)黄应贵编,页129-162(hist)6.Leung AKC 1994 “Elementary Education in the Lower Yangtze Region in the 17th and 18th centuries”,Education in Late Imperial China. Elman & Woodside eds.,U of California Press(论文集)...

云防风化学成份
云防风的化学成分丰富多样,主要包含了北美芹素 (pteryxin) 和丝立尼亭 (selinidin),以及香柑内酯 (bergapten) 这样的香豆精类成分,花椒毒素 (xanthotoxin) 也在其中。此外,云防风还含有一种名为3'-O-当归酰基亥茅酚 (3'-O-angeloylhamaudol) 的化合物,以及十七碳-1,8-二烯-4,6-二...

云防风作用与功效,有什么副作用?
【拼音名】Yun Fanɡ Fēnɡ 【别名】 竹叶防风、鸡脚暗哨、鸡足防风、西防风 【来源】 药材基源: 为伞形科植物竹叶西风芹、松叶西风芹和多毛西风芹的根。 拉丁植物动物矿物名:Sesli mairei Wolff 采收和储藏:春、秋季采挖,除去茎叶及泥土,晒干后,扎成把,再晒干。 【原形态】 ...

关于监狱的电影
以下电影都不同程度反映了监狱黑幕,有一定血腥指数:(不过,电影毕竟是电影,现实中的电影不见得就是电影中描写的那么黑暗)肖申克的救赎 力王 监狱风云 监狱风云之大逃犯 监狱淌血 2029星球女子监狱 海上监狱 破茧急先锋 绿色奇迹 怒虎狂龙 死亡监狱 监狱风暴 监狱风云录 破茧威龙 黑狱断肠歌之生砌...

杨维才的论文文献
Baskar, U. Grossniklaus and W.-C. Yang (2007). The central cell plays a critical role inpollen tube guidance in Arabidopsis. PlantCell 19(11): 3563-3577.Escobar-Restrepo, J.-M., N. Huck, S.Kessler, V. Gagliardini, J. Gheyselinck, W.-C.Yang and U. Grossniklaus (2007). The ...

六合区19422761618: 如何解决Linux开机报错unable to load selinux policy -
段干舒爱邦: selinux的问题 在Grub启动菜单上按e进入编辑模式,在启动项最后面加上 enforcing=0 ,回车,然后按b启动.进系统后可以修改selinux 的配置文件

六合区19422761618: 如何解决SELinux问题 -
段干舒爱邦: http://cache.baiducontent.com/c?m=9d78d513d9d431d94f9a94697d61c0121d4381137d808e4e2393d95f92144c30307192c830536113a4c5682041f14606acb6746536703daac18fd51c86e7c73f2fff76692f01864311d004acc95b27c23d9359e2&...

六合区19422761618: 如何解决SELinux问题 -
段干舒爱邦: 上面有个小错,应该是echo "0" > /selinux/enforce (少了>)selinux如果有开很容易造成ifind问题,参看下面系统日志Aug 2 20:52:06 cc-lnx-imglib setroubleshoot: SELinux is preventing /opt/simpana/iDataAgent/ifind "execstack" access to . ...

六合区19422761618: 如何在开启selinux前提下解决此问题6969 -
段干舒爱邦: 以下介绍一下SELinux相关e69da5e6ba90e799bee5baa631333337613739的工具 /usr/bin/setenforce 修改SELinux的实时运行模式 setenforce 1 设置SELinux 成为enforcing模式 setenforce 0 设置SELinux 成为permissive模式 如果要彻底禁用...

六合区19422761618: 怎么在linux下急救模式下修复Selinux
段干舒爱邦: 错误信息好像是:SELinux运行在enforcing模式下,但是无法加载SELinux策略. 从安装盘启动, 然后输入linux rescue进入救援模式.不要选择只读那个选项.这样原有的系统会被挂载到/mnt/sysimage下.接下来切换到原来的系统,并修改/etc/selinux/config中的SELINUX=disabled为SELINUX=permissive或者SELINUX=enforcing试试: chroot /mnt/sysimage vim /etc/selinux/config

六合区19422761618: 如何在开启selinux前提下解决此问题 -
段干舒爱邦: 以下介绍一下SELinux相关的工具/usr/bin/setenforce 修改SELinux的实时运行模式 setenforce 1 设置SELinux 成为enforcing模式 setenforce 0 设置SELinux 成为permissive模式 如果要彻底禁用SELinux 需要在/etc/sysconfig/selinux中设置参数...

六合区19422761618: 如何关闭Linux里边的selinux -
段干舒爱邦: 首先我们可以用命令来查看selinux的状态 getenforce 这个命令可以查看到selinux的状态,当前可以看到是关闭状态的.还有一个命令也可以查看出selinux的状态. sestatus -v还有一个setenforce 命令可以设置selinux的状态, 具体可以查看 ...

六合区19422761618: 如何关闭linux系统如何关闭selinux -
段干舒爱邦: 一、查看SELinux状态命令:1、/usr/sbin/sestatus -v ##如果SELinux status参数为enabled即为开启状态 SELinux status: enabled2、getenforce ##也可以用这个命令检查 二、关闭SELinux方法:1、临时关闭(不用重启机器):setenforce 0 #设置SELinux 成为permissive模式#setenforce 1 设置SELinux 成为enforcing模式2、修改配置文件需要重启机器:修改/etc/selinux/config 文件 将SELINUX=enforcing改为SELINUX=disabled 重启机器即可.

六合区19422761618: Ubuntu无法开启SELinux -
段干舒爱邦: 1首先应用安装一下 apt-get install selinux2、修改配置文件需要重启机器:修改/etc/selinux/config 文件 有效将SELINUX=enforcing (无效SELINUX=disabled) 重启机器即可

六合区19422761618: android7 怎么关selinux -
段干舒爱邦: 1 命令查看出selinux的状态 sestatus -v2 临时关闭 selinux setenforce 03 永久关闭selinux vi /etc/sysconfig/selinux 把里边的一行改为 selinux=disabled

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 星空见康网