at_yasu's blog

ロード的なことを

他人には見せない。

FreeBSD 6.0以降(かな?)の機能に、他人に自分のプロセス情報を見せない機能があります。

どういう事かというと、たいていのBSD,Linuxでは ps コマンドを打つと、全てのプロセスが表示されます。
こんな感じに

[negro: ~][21:37] $ ps aux | tail -10
yasui     2184   0.0  0.4    39616   4288  ??  Ss    9:32PM   0:00.28 /System/Library/Frameworks/SyncServices.framework/R
root      2188   0.0  0.1    27528    576  p2  Ss    9:37PM   0:00.02 login -pf yasui
yasui     2189   0.0  0.1    31836    948  p2  U     9:37PM   0:00.08 -tcsh
root      2195   0.0  0.0    27312    428  p2  R+    9:38PM   0:00.00 ps aux
yasui     2196   0.0  0.1    31836    948  p2  UV+   9:38PM   0:00.08 tail -10
root         1   0.0  0.0    28344    380  ??  S<s  Fri06PM   0:01.38 /sbin/launchd
root        23   0.0  0.0    27260    148  ??  Ss   Fri06PM   0:00.00 /sbin/dynamic_pager -F /private/var/vm/swapfile
root        27   0.0  0.1    28212    900  ??  Ss   Fri06PM   0:01.32 kextd
root        32   0.0  0.1    28240    676  ??  Ss   Fri06PM   0:00.02 /usr/sbin/KernelEventAgent
[negro: ~][21:38] $ 

それで、FreeBSD6.0以降ではsysctlのsecurity.bsd.see_other_uidsを0にする事で、見せない様にすることができる。
以下、実例。

[top: ~][21:40] $ sysctl security.bsd.see_other_uids
security.bsd.see_other_uids: 1
[top: ~][21:40] $ id
uid=1001(yasui) gid=1001(yasui) groups=1001(yasui), 0(wheel), 1009(karekinada), 1010(cvs)
[top: ~][21:40] $ ps aux | tail -10
root      739  0.0  0.3  1344   800  v0  Is+  Mon01PM   0:00.01 /usr/libexec/getty Pc ttyv0
root      740  0.0  0.3  1344   800  v1  Is+  Mon01PM   0:00.01 /usr/libexec/getty Pc ttyv1
root      584  0.0  0.4  1724   964 con- I    Mon01PM   0:00.03 /bin/sh /usr/local/mysql/mysql/bin/mysqld_safe --basedir
mysql     622  0.0  9.5 51332 24120 con- S    Mon01PM  11:50.70 /mysql/libexec/mysqld --basedir=/mysql --datadir=/var --
root     5945  0.0  0.8  3480  2052  p0- S    Tue02AM   0:03.80 /usr/local/libexec/kdc
root     5946  0.0  0.8  3460  1916  p0- I    Tue02AM   0:00.04 /usr/local/libexec/kpasswdd
root     5947  0.0  0.8  3460  1984  p0- I    Tue02AM   0:07.48 /usr/local/libexec/ipropd-master
yasui   68867  0.0  1.0  4720  2496  p0  Ss    9:28PM   0:00.13 -tcsh (tcsh)
yasui   68974  0.0  0.3  1492   884  p0  R+    9:40PM   0:00.01 ps aux
yasui   68975  0.0  0.1   312   164  p0  R+    9:40PM   0:00.00 tail -10
[top: ~][21:40] $ sudo sysctl security.bsd.see_other_uids=0
Password:
security.bsd.see_other_uids: 1 -> 0
[top: ~][21:40] $ ps aux | tail -10
USER    PID %CPU %MEM   VSZ   RSS  TT  STAT STARTED      TIME COMMAND
yasui 68866  0.0  1.1  6272  2844  ??  S     9:28PM   0:00.17 sshd: yasui@ttyp0 (sshd)
yasui 68867  0.0  1.0  4800  2600  p0  Ds    9:28PM   0:00.18 -tcsh (tcsh)
yasui 68989  0.0  0.3  1420   812  p0  R+    9:40PM   0:00.00 ps aux
yasui 68990  0.0  1.0  4800  2600  p0  RV    9:40PM   0:00.00 -tcsh (tcsh)
[top: ~][21:40] $ 

一方で、bsd.see_other_uids=0の時、netstatもListenしている他人のプロセスは表示されません。

[top: ~][21:45] $ id
uid=1001(yasui) gid=1001(yasui) groups=1001(yasui), 0(wheel), 1009(karekinada), 1010(cvs)
[top: ~][21:45] $ netstat -ant
[top: ~][21:45] $ sudo -u mysql netstat -ant
Active Internet connections (including servers)
Proto Recv-Q Send-Q  Local Address          Foreign Address        (state)
tcp4       0      0  *.3306                 *.*                    LISTEN
Active UNIX domain sockets
Address  Type   Recv-Q Send-Q    Inode     Conn     Refs  Nextref Addr
c2453834 stream      0      0        0 c25549d8        0        0 /mysql/tmp/mysql.sock
c2554e38 stream      0      0 c2597bb0        0        0        0 /mysql/tmp/mysql.sock
[top: ~][21:45] $ 

一方で、rootだと何でも表示してくれます。

[top: ~][21:47] $ id
uid=0(root) gid=0(wheel) groups=0(wheel), 5(operator), 1010(cvs)
[top: ~][21:47] $ netstat -ant | head -10
Active Internet connections (including servers)
Proto Recv-Q Send-Q  Local Address          Foreign Address        (state)
tcp4       0      0  192.168.24.254.22      192.168.24.51.63280    ESTABLISHED
tcp4       0      0  127.0.0.1.953          *.*                    LISTEN
tcp4       0      0  127.0.0.1.53           *.*                    LISTEN
tcp4       0      0  192.168.24.254.53      *.*                    LISTEN
tcp4       0      0  *.199                  *.*                    LISTEN
tcp4       0      0  *.2121                 *.*                    LISTEN
tcp4       0      0  127.0.0.1.88           *.*                    LISTEN
tcp4       0      0  192.168.24.254.88      *.*                    LISTEN
[top: ~][21:47] $ ps aux | head -10
USER      PID %CPU %MEM   VSZ   RSS  TT  STAT STARTED      TIME COMMAND
root       10 98.3  0.0     0     8  ??  RL   Mon01PM 7548:57.90 [idle]
root        0  0.0  0.0     0     0  ??  WLs  Mon01PM   0:00.00 [swapper]
root        1  0.0  0.1   772   260  ??  ILs  Mon01PM   0:00.73 /sbin/init --
root        2  0.0  0.0     0     8  ??  DL   Mon01PM   0:33.82 [g_event]
root        3  0.0  0.0     0     8  ??  DL   Mon01PM   1:25.90 [g_up]
root        4  0.0  0.0     0     8  ??  DL   Mon01PM   1:31.08 [g_down]
root        5  0.0  0.0     0     8  ??  DL   Mon01PM   0:00.00 [kqueue taskq]
root        6  0.0  0.0     0     8  ??  DL   Mon01PM   0:00.00 [acpi_task_0]
root        7  0.0  0.0     0     8  ??  DL   Mon01PM   0:00.00 [acpi_task_1]
[top: ~][21:48] $ 

FreeBSDすげー

ただ、selinuxとかseDarwinだとどうなるかは知らないけど。