HYLOGICS

今後は各分室にコンテンツを移して、ここは雑記や暮らしを中心としたライフログ的な何かにしていく予定です。

【作業メモ】Linuxカーネルの脆弱性 CVE-2016-0728の対応

概要

Linuxカーネル3.8以降のシステムにおいてローカルユーザがroot権限を取得可能となる脆弱性

詳細

Analysis and Exploitation of a Linux Kernel Vulnerability (CVE-2016-0728) | Perception Point

検証

[kirine@office ~]$ cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)

[kirine@office ~]$ uname -r
3.18.25

[kirine@office ~]$ git clone https://gist.github.com/3864cf0c2a77f7ebd1dd.git
Cloning into '3864cf0c2a77f7ebd1dd'...
remote: Counting objects: 6, done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 6 (delta 2), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (6/6), done.

[kirine@office ~]$ cd 3864cf0c2a77f7ebd1dd/

[kirine@office 3864cf0c2a77f7ebd1dd]$ ls
leak.c

[kirine@office ~]$ gcc leak.c -o leak -lkeyutils -Wall
leak.c:7:22: 致命的エラー: keyutils.h: そのようなファイルやディレクトリはありません
 #include <keyutils.h>
                      ^
コンパイルを停止しました。

[kirine@office ~]$ yum search keyutils
読み込んだプラグイン:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: ftp.tsukuba.wide.ad.jp
 * epel: ftp.tsukuba.wide.ad.jp
 * extras: ftp.tsukuba.wide.ad.jp
 * updates: ftp.tsukuba.wide.ad.jp
============================ N/S matched: keyutils =============================
keyutils.x86_64 : Linux Key Management Utilities
keyutils-libs.i686 : Key utilities library
keyutils-libs.x86_64 : Key utilities library
keyutils-libs-devel.i686 : Development package for building Linux key management
                         : utilities
keyutils-libs-devel.x86_64 : Development package for building Linux key
                           : management utilities

  Name and summary matches only, use "search all" for everything.

[kirine@office ~]$ sudo yum install keyutils-libs-devel
[sudo] password for kirine:
読み込んだプラグイン:fastestmirror, langpacks
base                                                     | 3.6 kB     00:00
epel/x86_64/metalink                                     | 4.4 kB     00:00
epel                                                     | 4.3 kB     00:00
extras                                                   | 3.4 kB     00:00
google-chrome                                            |  951 B     00:00
updates                                                  | 3.4 kB     00:00
google-chrome/primary                                      | 1.9 kB   00:00
Determining fastest mirrors
 * base: ftp.riken.jp
 * epel: ftp.riken.jp
 * extras: ftp.riken.jp
 * updates: ftp.riken.jp
google-chrome                                                               3/3
依存性の解決をしています
--> トランザクションの確認を実行しています。
---> パッケージ keyutils-libs-devel.x86_64 0:1.5.8-3.el7 を インストール
--> 依存性解決を終了しました。

依存性を解決しました

================================================================================
 Package                    アーキテクチャー
                                          バージョン          リポジトリー
                                                                           容量
================================================================================
インストール中:
 keyutils-libs-devel        x86_64        1.5.8-3.el7         base         37 k

トランザクションの要約
================================================================================
インストール  1 パッケージ

総ダウンロード容量: 37 k
インストール容量: 29 k
Is this ok [y/d/N]: y
Downloading packages:
keyutils-libs-devel-1.5.8-3.el7.x86_64.rpm                 |  37 kB   00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  インストール中          : keyutils-libs-devel-1.5.8-3.el7.x86_64          1/1
  検証中                  : keyutils-libs-devel-1.5.8-3.el7.x86_64          1/1

インストール:
  keyutils-libs-devel.x86_64 0:1.5.8-3.el7

完了しました!

[kirine@office ~]$ gcc leak.c -o leak -lkeyutils -Wall

[kirine@office ~]$ cat /proc/keys
0055870c IR-Q---    12 expd 3f030000   500   500 keyring   _ses: empty
0f7f9dae I--Q---     1 perm 1f3f0000   500 65534 keyring   _uid_ses.500: 1
13bd3d72 I--Q---     4 perm 1f3f0000   500 65534 keyring   _uid.500: empty
19eee0e3 I--Q---     7 perm 3f030000   500   500 keyring   _ses: 1
30db1c2e I--Q---     4 perm 3f030000   500   500 keyring   _ses: 1

[kirine@office ~]$ ./leak

[kirine@office ~]$ cat /proc/keys
0055870c IR-Q---    12 expd 3f030000   500   500 keyring   _ses: empty
0e630588 I--Q---   100 perm 3f3f0000   500   500 keyring   leaked-keyring: empty
0f7f9dae I--Q---     1 perm 1f3f0000   500 65534 keyring   _uid_ses.500: 1
13bd3d72 I--Q---     4 perm 1f3f0000   500 65534 keyring   _uid.500: empty
19eee0e3 I--Q---     7 perm 3f030000   500   500 keyring   _ses: 1
30db1c2e I--Q---     4 perm 3f030000   500   500 keyring   _ses: 1

検証結果 NG

対応

01/20 16:30(JST) 公式にはパッチ提供待ち。

LKMLではパッチが提供されていたので適用してみる。

LKML: James Morris: [GIT PULL] Security subsystem update

[kirine@office ~]$ cd rpmbuild/SOURCES/

[kirine@office ~]$ cp -iRp linux-3.18.25 linux-3.18.25.1

[kirine@office ~]$ cd linux-3.18.25.1

[kirine@office linux-3.18.25.1]$ wget -O patch https://lkml.org/lkml/diff/2016/1/19/627/1
--2016-01-20 17:16:30--  https://lkml.org/lkml/diff/2016/1/19/627/1
lkml.org (lkml.org) をDNSに問いあわせています... 146.185.183.13, 2a03:b0c0:0:1010::77:8001
lkml.org (lkml.org)|146.185.183.13|:443 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 200 OK
長さ: 394 [text/plain]
`patch' に保存中

100%[==================================================================>] 394         --.-K/s 時間 0s

2016-01-20 17:16:32 (142 MB/s) - `patch' へ保存完了 [394/394]

[kirine@office linux-3.18.25.1]# patch -p1 < patch
patching file security/keys/process_keys.c

[kirine@office ~]$ vi Makefile

[kirine@office linux-3.18.25.1]# diff ./Makefile ../linux-3.18.25/Makefile
4c4
< EXTRAVERSION = -1
---
> EXTRAVERSION =

[kirine@office linux-3.18.25.1]# make rpm
  HOSTCC  scripts/basic/fixdep
  HOSTCC  scripts/basic/bin2c
  HOSTCC  scripts/kconfig/conf.o
  HOSTCC  scripts/kconfig/zconf.tab.o
  HOSTLD  scripts/kconfig/conf
scripts/kconfig/conf --silentoldconfig Kconfig
  CHK     include/config/kernel.release
  UPD     include/config/kernel.release
make clean

<省略>

[kirine@office RPMS]# cd ~/rpmbuild/RPMS/x86_64/

[root@office x86_64]# ls
kernel-3.18.25_1-3.x86_64.rpm
kernel-headers-3.18.25_1-3.x86_64.rpm
kernel-devel-3.18.25_1-3.x86_64.rpm

[root@office x86_64]# yum localinstall ./kernel*rpm

<中略>

================================================================================
 Package        アーキテクチャー
                         バージョン    リポジトリー                        容量
================================================================================
インストール中:
 kernel         x86_64   3.18.25_1-3   /kernel-3.18.25_1-3.x86_64         1.6 G
 kernel-devel   x86_64   3.18.25_1-3   /kernel-devel-3.18.25_1-3.x86_64   525 M

トランザクションの要約
================================================================================
インストール  2 パッケージ

合計容量: 2.1 G
インストール容量: 2.1 G
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  インストール中          : kernel-3.18.25_1-3.x86_64                       1/2
  インストール中          : kernel-devel-3.18.25_1-3.x86_64                 2/2
  検証中                  : kernel-devel-3.18.25_1-3.x86_64                 1/2
  検証中                  : kernel-3.18.25_1-3.x86_64                       2/2

インストール:
  kernel.x86_64 0:3.18.25_1-3         kernel-devel.x86_64 0:3.18.25_1-3

完了しました!

[root@office linux-3.18.25.1]# shutdown -r now

再検証

[kirine@office ~]$ uname -r
3.18.25-1

[kirine@office ~]$ sudo cat /var/log/messages| egrep -iv 'overr|interr' | egrep -i 'err|warn|crit|fail|fatal|bad|emerg' | less
省略

[kirine@office 3864cf0c2a77f7ebd1dd]$ ./leak

[kirine@office 3864cf0c2a77f7ebd1dd]$ cat /proc/keys
003fc463 I--Q---     4 perm 1f3f0000   500 65534 keyring   _uid.500: empty
24e23ab6 I--Q---     1 perm 1f3f0000   500 65534 keyring   _uid_ses.500: 1
2d7551b0 I--Q---    12 perm 3f030000   500   500 keyring   _ses: 1
3e640d46 I--Q---    11 perm 3f030000   500   500 keyring   _ses: 1

再検証結果 OK

余談