RHEL/CentOS 7でphp 7.xを使う方法(2023/10/30更新)

RHEL7 / CentOS7のphpは5.4.16である。

新しいバージョンのphpを使う場合はソースからコンパイルして導入するか、3rdレポジトリを利用する必要がある。

有名なのはremiだが、Oracle Linuxにもあった。

うちはCentOS7だけど、 Oracle Linuxのol7_developer_php72 ol7_developer_php74レポジトリを追加する形で使っている。

1. remi-php?? レポジトリ

標準のphpを新しいバージョンで置き換える「remi-php??」レポジトリ(こちらはphpコマンドが置き換わる)と、標準のPHPはそのままに、そして後述のSCLとも共存できる「remi-safe」レポジトリ(こちらはphp73コマンドなどになる)というものもある。

意外なことに2022年秋リリース予定のphp 8.2についてもRC版で php 8.3も提供され始めた

Web: https://rpms.remirepo.net/enterprise/7/
提供中PHPバージョン: 8.3, 8.2, 8.1, 8.0, 7.4, 7.3, 7.2, 7.1, 7.0, 5.6
EOLしたもの: 5.5, 5.4

2. PHP for Oracle Linux

Web: http://yum.oracle.com/oracle-linux-php.html
PHPバージョン: 7.4, 7.2, 7.1, 7.0
EOLしたもの: 7.2, 7.1, 7.0

php v7.2に置き換える場合の手順

# yum install yum-utils
# curl -o /etc/pki/rpm-gpg/RPM-GPG-KEY-oracle https://yum.oracle.com/RPM-GPG-KEY-oracle-ol7
# curl -o /etc/yum.repos.d/public-yum-ol7.repo https://yum.oracle.com/public-yum-ol7.repo
# yum-config-manager --disable ol7_\*
# yum-config-manager --enable ol7_developer_php72
# 「yum install php」もしくは「yum update」で既存phpパッケージをphp72にアップデート
# systemctl restart httpd

上記でdisableを忘れるとOracle Linuxにアップデートしてしまうかもしれないので注意すること。また、先にyum-utilsをインストールしておくこと

2019/09/30 追記

Oracle Linux(Oracle Cloud Always Freeインスタンスなど)を使っている場合は「yum install oracle-php-release-el7」を実行することで、PHP拡張レポジトリが導入されます。導入直後は「ol7_developer_php72」が有効化されているので、上記と同じ「yum-config-manager –disable ol7_*」とか「yum-config-manager –enable ol7_developer_php72」で有効/無効を切り替えてください。

2020/07/20 追記 、2020/09/07修正

ol7_developer_php74は上記の http://yum.oracle.com/public-yum-ol7.repo には含まれてないようです。(Oracle Linuxで提供されるoracle-php-releaseパッケージに分離している)

また、Oralcleのphp 7.4はol7_addons収録のoniguruma-5.9.5が要求されます。 epel収録のoniguruma-6.8.2 がインストールされていると「Requires: libonig.so.2()(64bit)」というエラーになりますので、注意が必要です。

これを考慮して /etc/yum.repos.d/ol7_developer_php74.repo を書くと以下の様になる。

[ol7_developer_php74]
name=Oracle Linux $releasever PHP 7.4 Packages for Development and test ($basearch)
baseurl=https://yum.oracle.com/repo/OracleLinux/OL7/developer/php74/$basearch/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-oracle
gpgcheck=1
enabled=1

[ol7_addons]
name=Oracle Linux $releasever Add ons ($basearch)
baseurl=https://yum.oracle.com/repo/OracleLinux/OL7/addons/$basearch/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-oracle
gpgcheck=1
enabled=1

そしてepelのonigurumaを使用しないよう、 epelに関する設定の中に「exclude=oniguruma jq」を追加しておく必要がある。(epelのjqパッケージはepelのonigurumaを要求しているので一緒に除外する必要がある)

/etc/yum.repos.d/epel.repo の該当部分だけ抜き出したもの

[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
#baseurl=http://download.fedoraproject.org/pub/epel/7/$basearch
metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=$basearch&infra=$infra&content=$contentdir
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
exclude=oniguruma jq

3. webtatic

2019/10/26の更新が最後になっており、現状使うべきでは無い。

Web: https://webtatic.com/
提供中PHPバージョン: 7.2, 7.1
EOLしたもの:7.0, 5.6

4. Software Collection (SCL)

CentOSのwikiに「Using PHP 7.x on CentOS 7.4」という記載があった。
CentOS Software Collectionレポジトリにあるという。

確認してみると、「rh-php70~」「rh-php71~」「rh-php72~」と標準のパッケージ名とは別に設定されているものがあった。また、rh-phpにないものを補完するための「sclo-php~」というのもあった。

PHP 7.2 by Software Collections」とRedHat DEVELOPER BLOGの「PHP Configuration Tips」に参考になる記述があるが、FastCGIを使うための装備はあるが、mod_phpを使うための装備はない。

Remiさんとこのblog「PHP 7.2 as Software Collection」にSCLとRemiレポジトリの違いが書かれている。また、複数バージョンのPHPを1サーバで共存させる場合の手法「My PHP Workstation」も公開されている。

# yum -y install centos-release-scl.noarch
<略>
================================================================================
 Package                    アーキテクチャー
                                        バージョン            リポジトリー
                                                                           容量
================================================================================
インストール中:
 centos-release-scl         noarch      2-2.el7.centos        extras       12 k
依存性関連でのインストールをします:
 centos-release-scl-rh      noarch      2-2.el7.centos        extras       12 k

トランザクションの要約
================================================================================
インストール  1 パッケージ (+1 個の依存関係のパッケージ)

総ダウンロード容量: 24 k
インストール容量: 39 k
<略>
# yum search rh-php
<略>
============================= N/S matched: rh-php ==============================
rh-php70-runtime.x86_64 : Package that handles rh-php70 Software Collection.
rh-php70-scldevel.x86_64 : Package shipping development files for rh-php70
rh-php71-runtime.x86_64 : Package that handles rh-php71 Software Collection.
rh-php71-scldevel.x86_64 : Package shipping development files for rh-php71
rh-php72-runtime.x86_64 : Package that handles rh-php72 Software Collection.
rh-php72-scldevel.x86_64 : Package shipping development files for rh-php72
rh-php70.x86_64 : Package that installs PHP 7.0
rh-php70-build.x86_64 : Package shipping basic build configuration
rh-php70-php.x86_64 : PHP scripting language for creating dynamic web sites
rh-php70-php-bcmath.x86_64 : A module for PHP applications for using the bcmath
                           : library
rh-php70-php-cli.x86_64 : Command-line interface for PHP
rh-php70-php-common.x86_64 : Common files for PHP
rh-php70-php-dba.x86_64 : A database abstraction layer module for PHP
                        : applications
rh-php70-php-dbg.x86_64 : The interactive PHP debugger
rh-php70-php-devel.x86_64 : Files needed for building PHP extensions
rh-php70-php-embedded.x86_64 : PHP library for embedding in applications
rh-php70-php-enchant.x86_64 : Enchant spelling extension for PHP applications
rh-php70-php-fpm.x86_64 : PHP FastCGI Process Manager
rh-php70-php-gd.x86_64 : A module for PHP applications for using the gd graphics
                       : library
rh-php70-php-gmp.x86_64 : A module for PHP applications for using the GNU MP
                        : library
rh-php70-php-intl.x86_64 : Internationalization extension for PHP applications
rh-php70-php-json.x86_64 : JavaScript Object Notation extension for PHP
rh-php70-php-ldap.x86_64 : A module for PHP applications that use LDAP
rh-php70-php-mbstring.x86_64 : A module for PHP applications which need
                             : multi-byte string handling
rh-php70-php-mysqlnd.x86_64 : A module for PHP applications that use MySQL
                            : databases
rh-php70-php-odbc.x86_64 : A module for PHP applications that use ODBC databases
rh-php70-php-opcache.x86_64 : The Zend OPcache
rh-php70-php-pdo.x86_64 : A database access abstraction module for PHP
                        : applications
rh-php70-php-pear.noarch : PHP Extension and Application Repository framework
rh-php70-php-pgsql.x86_64 : A PostgreSQL database module for PHP
rh-php70-php-process.x86_64 : Modules for PHP script using system process
                            : interfaces
rh-php70-php-pspell.x86_64 : A module for PHP applications for using pspell
                           : interfaces
rh-php70-php-recode.x86_64 : A module for PHP applications for using the recode
                           : library
rh-php70-php-snmp.x86_64 : A module for PHP applications that query SNMP-managed
                         : devices
rh-php70-php-soap.x86_64 : A module for PHP applications that use the SOAP
                         : protocol
rh-php70-php-xml.x86_64 : A module for PHP applications which use XML
rh-php70-php-xmlrpc.x86_64 : A module for PHP applications which use the XML-RPC
                           : protocol
rh-php70-php-zip.x86_64 : ZIP archive management extension for PHP
rh-php71.x86_64 : Package that installs PHP 7.1
rh-php71-build.x86_64 : Package shipping basic build configuration
rh-php71-php.x86_64 : PHP scripting language for creating dynamic web sites
rh-php71-php-bcmath.x86_64 : A module for PHP applications for using the bcmath
                           : library
rh-php71-php-cli.x86_64 : Command-line interface for PHP
rh-php71-php-common.x86_64 : Common files for PHP
rh-php71-php-dba.x86_64 : A database abstraction layer module for PHP
                        : applications
rh-php71-php-dbg.x86_64 : The interactive PHP debugger
rh-php71-php-devel.x86_64 : Files needed for building PHP extensions
rh-php71-php-embedded.x86_64 : PHP library for embedding in applications
rh-php71-php-enchant.x86_64 : Enchant spelling extension for PHP applications
rh-php71-php-fpm.x86_64 : PHP FastCGI Process Manager
rh-php71-php-gd.x86_64 : A module for PHP applications for using the gd graphics
                       : library
rh-php71-php-gmp.x86_64 : A module for PHP applications for using the GNU MP
                        : library
rh-php71-php-intl.x86_64 : Internationalization extension for PHP applications
rh-php71-php-json.x86_64 : JavaScript Object Notation extension for PHP
rh-php71-php-ldap.x86_64 : A module for PHP applications that use LDAP
rh-php71-php-mbstring.x86_64 : A module for PHP applications which need
                             : multi-byte string handling
rh-php71-php-mysqlnd.x86_64 : A module for PHP applications that use MySQL
                            : databases
rh-php71-php-odbc.x86_64 : A module for PHP applications that use ODBC databases
rh-php71-php-opcache.x86_64 : The Zend OPcache
rh-php71-php-pdo.x86_64 : A database access abstraction module for PHP
                        : applications
rh-php71-php-pear.noarch : PHP Extension and Application Repository framework
rh-php71-php-pecl-apcu.x86_64 : APC User Cache
rh-php71-php-pecl-apcu-devel.x86_64 : APCu developer files (header)
rh-php71-php-pgsql.x86_64 : A PostgreSQL database module for PHP
rh-php71-php-process.x86_64 : Modules for PHP script using system process
                            : interfaces
rh-php71-php-pspell.x86_64 : A module for PHP applications for using pspell
                           : interfaces
rh-php71-php-recode.x86_64 : A module for PHP applications for using the recode
                           : library
rh-php71-php-snmp.x86_64 : A module for PHP applications that query SNMP-managed
                         : devices
rh-php71-php-soap.x86_64 : A module for PHP applications that use the SOAP
                         : protocol
rh-php71-php-xml.x86_64 : A module for PHP applications which use XML
rh-php71-php-xmlrpc.x86_64 : A module for PHP applications which use the XML-RPC
                           : protocol
rh-php71-php-zip.x86_64 : ZIP archive management extension for PHP
rh-php72.x86_64 : Package that installs PHP 7.2
rh-php72-build.x86_64 : Package shipping basic build configuration
rh-php72-php.x86_64 : PHP scripting language for creating dynamic web sites
rh-php72-php-bcmath.x86_64 : A module for PHP applications for using the bcmath
                           : library
rh-php72-php-cli.x86_64 : Command-line interface for PHP
rh-php72-php-common.x86_64 : Common files for PHP
rh-php72-php-dba.x86_64 : A database abstraction layer module for PHP
                        : applications
rh-php72-php-dbg.x86_64 : The interactive PHP debugger
rh-php72-php-devel.x86_64 : Files needed for building PHP extensions
rh-php72-php-embedded.x86_64 : PHP library for embedding in applications
rh-php72-php-enchant.x86_64 : Enchant spelling extension for PHP applications
rh-php72-php-fpm.x86_64 : PHP FastCGI Process Manager
rh-php72-php-gd.x86_64 : A module for PHP applications for using the gd graphics
                       : library
rh-php72-php-gmp.x86_64 : A module for PHP applications for using the GNU MP
                        : library
rh-php72-php-intl.x86_64 : Internationalization extension for PHP applications
rh-php72-php-json.x86_64 : JavaScript Object Notation extension for PHP
rh-php72-php-ldap.x86_64 : A module for PHP applications that use LDAP
rh-php72-php-mbstring.x86_64 : A module for PHP applications which need
                             : multi-byte string handling
rh-php72-php-mysqlnd.x86_64 : A module for PHP applications that use MySQL
                            : databases
rh-php72-php-odbc.x86_64 : A module for PHP applications that use ODBC databases
rh-php72-php-opcache.x86_64 : The Zend OPcache
rh-php72-php-pdo.x86_64 : A database access abstraction module for PHP
                        : applications
rh-php72-php-pear.noarch : PHP Extension and Application Repository framework
rh-php72-php-pecl-apcu.x86_64 : APC User Cache
rh-php72-php-pecl-apcu-devel.x86_64 : APCu developer files (header)
rh-php72-php-pgsql.x86_64 : A PostgreSQL database module for PHP
rh-php72-php-process.x86_64 : Modules for PHP script using system process
                            : interfaces
rh-php72-php-pspell.x86_64 : A module for PHP applications for using pspell
                           : interfaces
rh-php72-php-recode.x86_64 : A module for PHP applications for using the recode
                           : library
rh-php72-php-snmp.x86_64 : A module for PHP applications that query SNMP-managed
                         : devices
rh-php72-php-soap.x86_64 : A module for PHP applications that use the SOAP
                         : protocol
rh-php72-php-xml.x86_64 : A module for PHP applications which use XML
rh-php72-php-xmlrpc.x86_64 : A module for PHP applications which use the XML-RPC
                           : protocol
rh-php72-php-zip.x86_64 : ZIP archive management extension for PHP

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

RHEL6/CentOS6向けの3rdパーティーrepo

RHEL6/CentO6で使われているphpがver5.3.3と古い。
より新しいバージョンのphpを要求されている。

そんな時に、頼る先は、公式以外からリリースされているRPM群

yumでとってこれる先として代表的なもの

EPEL
Fedoraプロジェクトから出ているレポジトリ。
標準にないものを追加する方が主体で、オリジナルより新しいバージョンの提供はあまりやらない。
Cent OS6の場合「yum install epel-release」で追加できる。

RepoForge
旧名:RPMforge
標準に対するアップデートも行うし、オリジナルにないのの追加も行うし、で手広いもの。
ただ、範囲が広いので、問題が発生しやすいところがある。

IUS Community Project
mysql,php,pythonのバージョンアップを目的としたレポジトリ。
それ以外のソフトウェアについては基本的に提供されていない。
また、phpの細かいソフトウェアパッケージ群についても提供せず、基本部分のみとなっている。

Les RPM de Remi – Repository
phpのバージョンアップと、phpの細かいソフトウェアパッケージ群の提供を目的としている。
php関連をがっつり入れたい場合はコレになるかな?

・Oracle Linux
番外的なところがあるが、Oracle Linuxだと、追加のレポジトリで、MySQL 5.5/5.6対応のレポジトリが存在している。
状況によってはそちらを選択してもよいかもしれない。
参考:「Oracle Linux用の公開レポジトリについて」と「RHEL6/CentOS6をOracle Linuxにしてみる

CVE-2015-0235はRHEL4/CentOS4に影響する&修正版提供開始(2015/01/30 20:40版)

CVE-2015-0235 というglibcに大きめのバグが見つかった模様。

RedHat Enterprise Linux 4 / CentOS 4に対して影響があるのかどうかを調べてみた。

まずは、RedHat公式情報系

・RedHat Bugzilla:Bug 1183461 – (CVE-2015-0235) CVE-2015-0235 glibc: __nss_hostname_digits_dots() heap-based buffer overflow
 ・RHEL Knowledgebase Articles:GHOST: glibc vulnerability (CVE-2015-0235) / GHOST: glibc 脆弱性 (CVE-2015-0235)
 ・RHEL CVEデータベース:CVE-2015-0235
 ・RHEL4向け:RHSA-2015:0101:Critical: glibc security update
 ・RHEL5向け:RHSA-2015:0090:Critical: glibc security update
 ・RHEL6,RHEL7向け:RHSA-2015:0092:Critical: glibc security update

はい、RHEL4も対象になっています。

実際に確認してみるため、openwallにあるCVE-2015-0235についての詳細報告書「Qualys Security Advisory CVE-2015-0235 – GHOST: glibc gethostbyname buffer overflow」の「4 – Case studies」の記述を試してみる。

実行した際に「vulnerable」と出たら、問題あり。
「not vulnerable」だったら問題なし、というもの。

[root@cent4 201501]# mkdir security
[root@cent4 201501]# cd security/
[root@cent4 security]# rpm -qa|grep glibc|sort
警告: only V3 signatures can be verified, skipping V4 signature
glibc-2.3.4-2.57
glibc-2.3.4-2.57
glibc-common-2.3.4-2.57
glibc-devel-2.3.4-2.57
glibc-devel-2.3.4-2.57
glibc-headers-2.3.4-2.57
glibc-kernheaders-2.4-9.1.103.EL
[root@cent4 security]# cat > GHOST.c << EOF
> #include <netdb.h>
> #include <stdio.h>
> #include <stdlib.h>
> #include <string.h>
> #include <errno.h>
>
> #define CANARY "in_the_coal_mine"
>
> struct {
>   char buffer[1024];
>   char canary[sizeof(CANARY)];
> } temp = { "buffer", CANARY };
>
> int main(void) {
>   struct hostent resbuf;
>   struct hostent *result;
>   int herrno;
>   int retval;
>
>   /*** strlen (name) = size_needed - sizeof (*host_addr) - sizeof (*h_addr_ptrs) - 1; ***/
>   size_t len = sizeof(temp.buffer) - 16*sizeof(unsigned char) - 2*sizeof(char *) - 1;
>   char name[sizeof(temp.buffer)];
>   memset(name, '0', len);
>   name[len] = '\0';
>
>   retval = gethostbyname_r(name, &resbuf, temp.buffer, sizeof(temp.buffer), &result, &herrno);
>
>   if (strcmp(temp.canary, CANARY) != 0) {
>     puts("vulnerable");
>     exit(EXIT_SUCCESS);
>   }
>   if (retval == ERANGE) {
>     puts("not vulnerable");
>     exit(EXIT_SUCCESS);
>   }
>   puts("should not happen");
>   exit(EXIT_FAILURE);
> }
> EOF
[root@cent4 security]# ls
GHOST.c
[root@cent4 security]# gcc GHOST.c -o GHOST
[root@cent4 security]# ls
GHOST  GHOST.c
[root@cent4 security]# ./GHOST
vulnerable
[root@cent4 security]#

「vulnerable」なので、「問題あり」確定です。

修正版については、RHEL4の通常サポートは終了。現在はELSと呼ばれる特別な契約者向けに提供されているものだけが更新されています。

前述の「RHSA-2015:0101 Critical: glibc security update」にあるとおり、修正されたglibcのバージョンは「glibc-2.3.4-2.57.el4.2」となります。

ただ、このバージョンは通常の方法ではRHEL4およびCentOS4には提供されません。

しかし、RHEL4のソースを元にOracleで再構成した、Oracle Linux 4は、まだサポートを行っています。
こちらから、ファイルを持ってくることで対応が可能となっています。

Oracle Linux 4向けのSource RPMは、「https://oss.oracle.com/el4/SRPMS-updates/」にて提供されています。
Oracle LinuxではRHEL4とパッケージバージョンが若干異なり「glibc-2.3.4-2.57.0.1.el4.1」となります。
https://oss.oracle.com/el4/SRPMS-updates/glibc-2.3.4-2.57.0.1.el4.1.src.rpm

ただ、今回のことを受けて更新されたコンパイル済みのRPMは、glibc関連だけではなかったりします。
nptl-devel, nscdも更新されています。
このため、今回については、glibcのSource RPMだけを持ってきてコンパイルして適用、というのは、あまりお薦めできないような感じです。

コンパイル済みのRPMファイルについて、Oracle Linuxでは「Oracle Public Yum Server」としてレポジトリを公開しており、適切な設定を行うことで、RHEL4/CentOS4からOracle Linux 4に乗り換え、yumコマンドによるアップデートが行えるようになります。

コンパイル済みRPMファイル自体は「http://public-yum.oracle.com/repo/EnterpriseLinux/EL4/latest/」以下を探せば出てきますので、ページを「2015」で検索し出てくるパッケージが自分のサーバにインストールされているかを確認し、ダウンロードして適用する、ということが可能です。

しかし、依存関係解決とか面倒なので、これを機会にOracle Linux 4に乗り換えてしまう、というのも手かもしれません。

切り替え方法については、「RHEL4/CentOS4をOracle Linux4に!」にて紹介していますので、興味がある方は参照してみてください。
設定は非常に簡単です。

こちらの環境ではOralce Linux 4になっているため「yum update -y」で更新が完了しました。

更新後、再度テストプログラムを実行してみます。

[root@cent4 security]# ./GHOST
not vulnerable
[root@cent4 security]#

「not vulnerable」と出力されるので、脆弱性は修正されている、ということになります。

これで、一安心、といったところです。


<以下は修正版のglibcが出る前に書いたものです。資料として残しておきます>

glibcに大きめのバグが見つかった模様。
CVE-2015-0235

・RedHat Bugzilla:Bug 1183461 – (CVE-2015-0235) CVE-2015-0235 glibc: __nss_hostname_digits_dots() heap-based buffer overflow
 ・RHEL CVEデータベース:CVE-2015-0235
 ・RHEL5向け:RHSA-2015:0090-1:Critical: glibc security update
 ・RHEL6,RHEL7向け:RHSA-2015:0092-1:Critical: glibc security update

RHEL4/CentOS4についての記載が見付からない。

Oracle LinuxのSource RPM置き場 https://oss.oracle.com/el4/SRPMS-updates/ を見ても、2015/01/28 10:35時点では何も無し。

(2015/01/28 23:00 追加)
1時間ぐらい前に「GHOST: glibc vulnerability (CVE-2015-0235)」にRed Hat Enterprise Linux 4 Extended Life Cycle Supportに関する記述が追加された。
いまのところ修正版に関する記述はないが、RHEL4に脆弱性がある、という公式告知になっている。

(2015/01/29 19:30追加)
Red Hat Enterprise Linux ELS (v. 4)に対するSecurity Advisoryが公開された。
RHSA-2015:0101 Critical: glibc security update

ELS契約者向けに glibc-2.3.4-2.57.el4.2 としてリリースされたので、そのうちOracle Linuxにも波及してくるものと想定されるが、現状はまだ公開されていない。

(2015/01/30 14:20追加)
https://oss.oracle.com/el4/SRPMS-updates/ に、glibc-2.3.4-2.57.0.1.el4.1.src.rpmが置かれました。
Oralce Linux 4のpublic yumレポジトリのほう(repo url)にはまだ登録されていないようです。

(2015/01/30 16:30追加)
Oracle Linux 4のpublic yumレポジトリでの配布が始まりました。

以下の16:20ぐらいの段階ではi386(32bit)版のみだったのですが、16:37にはx86_64(64bit)版のディレクトリにもファイルが置かれ始めました。

i386(32bit)版
 http://public-yum.oracle.com/repo/EnterpriseLinux/EL4/latest/i386/getPackage/glibc-common-2.3.4-2.57.0.1.el4.1.i386.rpm
 http://public-yum.oracle.com/repo/EnterpriseLinux/EL4/latest/i386/getPackage/glibc-devel-2.3.4-2.57.0.1.el4.1.i386.rpm
 http://public-yum.oracle.com/repo/EnterpriseLinux/EL4/latest/i386/getPackage/glibc-headers-2.3.4-2.57.0.1.el4.1.i386.rpm
 http://public-yum.oracle.com/repo/EnterpriseLinux/EL4/latest/i386/getPackage/glibc-profile-2.3.4-2.57.0.1.el4.1.i386.rpm
 http://public-yum.oracle.com/repo/EnterpriseLinux/EL4/latest/i386/getPackage/glibc-utils-2.3.4-2.57.0.1.el4.1.i386.rpm
 http://public-yum.oracle.com/repo/EnterpriseLinux/EL4/latest/i386/getPackage/nptl-devel-2.3.4-2.57.0.1.el4.1.i386.rpm
 http://public-yum.oracle.com/repo/EnterpriseLinux/EL4/latest/i386/getPackage/nptl-devel-2.3.4-2.57.0.1.el4.1.i686.rpm
 http://public-yum.oracle.com/repo/EnterpriseLinux/EL4/latest/i386/getPackage/nscd-2.3.4-2.57.0.1.el4.1.i386.rpm

64bit(x86_64)版
 

(追加部分おわり)

openwallにあるCVE-2015-0235についての詳細報告書「Qualys Security Advisory CVE-2015-0235 – GHOST: glibc gethostbyname buffer overflow」の「4 – Case studies」には事象確認方法が記載されている。

下記をコンパイルして、実行した際に「vulnerable」と出たら、問題あり。
「not vulnerable」だったら問題なし、というもの。

#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>

#define CANARY "in_the_coal_mine"

struct {
  char buffer[1024];
  char canary[sizeof(CANARY)];
} temp = { "buffer", CANARY };

int main(void) {
  struct hostent resbuf;
  struct hostent *result;
  int herrno;
  int retval;

  /*** strlen (name) = size_needed - sizeof (*host_addr) - sizeof (*h_addr_ptrs) - 1; ***/
  size_t len = sizeof(temp.buffer) - 16*sizeof(unsigned char) - 2*sizeof(char *) - 1;
  char name[sizeof(temp.buffer)];
  memset(name, '0', len);
  name[len] = '\0';

  retval = gethostbyname_r(name, &resbuf, temp.buffer, sizeof(temp.buffer), &result, &herrno);

  if (strcmp(temp.canary, CANARY) != 0) {
    puts("vulnerable");
    exit(EXIT_SUCCESS);
  }
  if (retval == ERANGE) {
    puts("not vulnerable");
    exit(EXIT_SUCCESS);
  }
  puts("should not happen");
  exit(EXIT_FAILURE);
}

さて・・・CentOS4ではどうなっているのか?

[root@cent4 201501]# mkdir security
[root@cent4 201501]# cd security/
[root@cent4 security]# rpm -qa|grep glibc|sort
警告: only V3 signatures can be verified, skipping V4 signature
glibc-2.3.4-2.57
glibc-2.3.4-2.57
glibc-common-2.3.4-2.57
glibc-devel-2.3.4-2.57
glibc-devel-2.3.4-2.57
glibc-headers-2.3.4-2.57
glibc-kernheaders-2.4-9.1.103.EL
[root@cent4 security]# cat > GHOST.c << EOF
> #include <netdb.h>
> #include <stdio.h>
> #include <stdlib.h>
> #include <string.h>
> #include <errno.h>
>
> #define CANARY "in_the_coal_mine"
>
> struct {
>   char buffer[1024];
>   char canary[sizeof(CANARY)];
> } temp = { "buffer", CANARY };
>
> int main(void) {
>   struct hostent resbuf;
>   struct hostent *result;
>   int herrno;
>   int retval;
>
>   /*** strlen (name) = size_needed - sizeof (*host_addr) - sizeof (*h_addr_ptrs) - 1; ***/
>   size_t len = sizeof(temp.buffer) - 16*sizeof(unsigned char) - 2*sizeof(char *) - 1;
>   char name[sizeof(temp.buffer)];
>   memset(name, '0', len);
>   name[len] = '\0';
>
>   retval = gethostbyname_r(name, &resbuf, temp.buffer, sizeof(temp.buffer), &result, &herrno);
>
>   if (strcmp(temp.canary, CANARY) != 0) {
>     puts("vulnerable");
>     exit(EXIT_SUCCESS);
>   }
>   if (retval == ERANGE) {
>     puts("not vulnerable");
>     exit(EXIT_SUCCESS);
>   }
>   puts("should not happen");
>   exit(EXIT_FAILURE);
> }
> EOF
[root@cent4 security]# ls
GHOST.c
[root@cent4 security]# gcc GHOST.c -o GHOST
[root@cent4 security]# ls
GHOST  GHOST.c
[root@cent4 security]# ./GHOST
vulnerable
[root@cent4 security]#

駄目でした。

とりあえず、続報待ちということで・・・

(2015/01/30 16:50追記)
Oralce public yum repoで提供されたのでアップデートを行い、試験実施。

[root@cent4 security]# ./ghost
not vulnerable
[root@cent4 security]#

問題がなくなったことを確認できました。

なお、Oracle Linux public レポジトリからyumコマンドを使ってファイルを持ってこれるようにするには「RHEL4/CentOS4をOracle Linux4に!」で紹介しているようにOracle Linuxに切り替えてしまう、というのが簡単でいいと思います。

RHEL6/CentOS6をOracle Linuxにしてみる

2020/09/28追記

Oracle公式のCentOSからの移行手順「Switch your CentOS systems to Oracle Linux」とRHELからサポートありのOracleLinuxへの移行手順「Switching from Red Hat Network (RHN) to Oracle Unbreakable Linux Network (ULN)

また、逆にRedHat公式によるCentOS/Oracle LinuxからRHELへの移行手順「How to convert from CentOS or Oracle Linux to RHEL

また、レポジトリによっては下記の様なメッセージが出るようになったようです。

IMPORTANT: A legacy Oracle Linux yum server repo file was found. Oracle Linux yum server repository configurations have changed which means public-yum-ol7.repo will no longer be updated. New repository configuration files have been installed but are disabled. To complete the transition, run this script as the root user:

/usr/bin/ol_yum_configure.sh

See https://yum.oracle.com/faq.html for more information.


Oracle Linux用にOpenStackがリリースされた、ということなので、Oracle Linuxの環境を用意してみようと思った。
つい先ほど、RHEL4/CentOS4でOralce Linuxにしてみたので、同じようにできるかな、と思ったらちょっと工夫が必要でした。
(注:手法としては、既知のディストリビューション乗り換え手法なんですけどね)

1. GPG Keyの入手

[root@centos6 ~]# wget http://public-yum.oracle.com/RPM-GPG-KEY-oracle-ol6 -O /etc/pki/rpm-gpg/RPM-GPG-KEY-oracle
--2014-09-26 16:40:22--  http://public-yum.oracle.com/RPM-GPG-KEY-oracle-ol6
public-yum.oracle.com をDNSに問いあわせています... 203.179.83.11, 203.179.83.19
public-yum.oracle.com|203.179.83.11|:80 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 200 OK
長さ: 1011 [text/plain]
`/etc/pki/rpm-gpg/RPM-GPG-KEY-oracle' に保存中

100%[===================================================&amp;gt;] 1,011       --.-K/s 時間 0s

2014-09-26 16:40:22 (4.83 MB/s) - `/etc/pki/rpm-gpg/RPM-GPG-KEY-oracle' へ保存完了 [1011/1011]

[root@centos6 ~]# 

2. yumレポジトリの編集
Oracle Linux用レポジトリの追加と、CentOS用レポジトリの削除

[root@centos6 ~]# cd /etc/yum.repos.d
[root@centos6 yum.repos.d]# wget http://public-yum.oracle.com/public-yum-ol6.repo
--2014-09-26 16:40:45--  http://public-yum.oracle.com/public-yum-ol6.repo
public-yum.oracle.com をDNSに問いあわせています... 203.179.83.11, 203.179.83.19
public-yum.oracle.com|203.179.83.11|:80 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 200 OK
長さ: 4233 (4.1K) [text/plain]
`public-yum-ol6.repo' に保存中

100%[===================================================&amp;gt;] 4,233       --.-K/s 時間 0s

2014-09-26 16:40:46 (323 MB/s) - `public-yum-ol6.repo' へ保存完了 [4233/4233]

[root@centos6 yum.repos.d]# ls
CentOS-Base.repo       CentOS-Media.repo  public-yum-ol6.repo
CentOS-Debuginfo.repo  CentOS-Vault.repo
[root@centos6 yum.repos.d]# mv CentOS-Base.repo CentOS-Base.repo.disable
[root@centos6 yum.repos.d]# mv CentOS-Debuginfo.repo CentOS-Debuginfo.repo.disable
[root@centos6 yum.repos.d]# mv CentOS-Media.repo CentOS-Media.repo.disable
[root@centos6 yum.repos.d]# mv CentOS-Vault.repo CentOS-Vault.repo.disable
[root@centos6 yum.repos.d]#

で、アップデート実施

[root@centos6 yum.repos.d]# yum update -y
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Setting up Update Process
Resolving Dependencies
--&amp;gt; Running transaction check
---&amp;gt; Package audit.x86_64 0:2.2-2.el6 will be updated
<略>
Transaction Check Error:
  file /etc/issue from install of oraclelinux-release-6:6Server-5.0.2.x86_64 conflicts with file from package centos-release-6-4.el6.centos.10.x86_64
  file /etc/issue.net from install of oraclelinux-release-6:6Server-5.0.2.x86_64 conflicts with file from package centos-release-6-4.el6.centos.10.x86_64
  file /etc/redhat-release from install of oraclelinux-release-6:6Server-5.0.2.x86_64 conflicts with file from package centos-release-6-4.el6.centos.10.x86_64
  file /etc/rpm/macros.dist from install of oraclelinux-release-6:6Server-5.0.2.x86_64 conflicts with file from package centos-release-6-4.el6.centos.10.x86_64
  file /etc/system-release from install of oraclelinux-release-6:6Server-5.0.2.x86_64 conflicts with file from package centos-release-6-4.el6.centos.10.x86_64
  file /etc/system-release-cpe from install of oraclelinux-release-6:6Server-5.0.2.x86_64 conflicts with file from package centos-release-6-4.el6.centos.10.x86_64

Error Summary
-------------

[root@centos6 yum.repos.d]#

oraclelinux-releaseパッケージと、centos-releaseパッケージが競合するというもの。

/var/cache/yum/x86_64/6/ol6_latest/packages/に、oraclelinux-releaseパッケージがダウンロードされているので、rpmコマンドを使って強制的にインストールする。

[root@centos6 yum.repos.d]# rpm -Uvh --force /var/cache/yum/x86_64/6/ol6_latest/packages/oraclelinux-release-6Server-5.0.2.x86_64.rpm /var/cache/yum/x86_64/6/ol6_latest/packages/redhat-release-server-6Server-6.5.0.1.0.1.el6.x86_64.rpm
準備中...                ########################################### [100%]
   1:redhat-release-server  ########################################### [ 50%]
   2:oraclelinux-release    ########################################### [100%]
[root@centos6 yum.repos.d]#

これで「yum update」が可能になりました。

再起動後は以下の様な状態となりました。

[root@centos6 ~]# uname -a
Linux centos6.adosakana.net 2.6.32-431.29.2.el6.x86_64 #1 SMP Tue Sep 9 11:28:47 PDT 2014 x86_64 x86_64 x86_64 GNU/Linux
[root@centos6 ~]# rpm -qa|grep release
redhat-release-server-6Server-6.5.0.1.0.1.el6.x86_64
centos-release-6-4.el6.centos.10.x86_64
oraclelinux-release-6Server-5.0.2.x86_64
[root@centos6 ~]# cat /etc/motd
[root@centos6 ~]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 6.5 (Santiago)
[root@centos6 ~]#

ちなみに、Oracle Linux 6では、以下の追加レポジトリがある。
・MySQL 5.5 (ol6_MySQL)
・MySQL 5.6 (ol6_MySQL56)
・Unbrakable Enterprise kernel 2.6.39 (ol6_UEK_latest)
・Unbrakable Enterprise kernel 3.8.13 (ol6_UEKR3_latest)
・常に最新kernel。 (ol6_playground_latest)

詳細については、以前書いた「Oracle Linux用の公開レポジトリについて」を参照のこと。

RHEL4/CentOS4をOracle Linux4に!

今回の件を検証するため、CentOS4をセットアップした。

が・・・yum updateとかすると、エラー。
原因はCentOS4のレポジトリがアーカイブ化されてしまい、ミラーされなくなったため。

[root@centos4 ~]# yum update
Setting up Update Process
Setting up repositories
not using ftp, http[s], or file for repos, skipping - 4 is not a valid release or hasnt been released yet
Cannot find a valid baseurl for repo: update
Error: Cannot find a valid baseurl for repo: update
[root@centos4 ~]#

/etc/yum.repos.d/CentOS-Base.repo内にある「http://mirror.centos.org/centos/$releasever/」を「http://vault.centos.org/4.9/」、「http://mirror.centos.org/centos/RPM-GPG-KEY-centos4」を「http://vault.centos.org/RPM-GPG-KEY-centos4」に書き換え、また、「mirrorlist=~」をコメントにし、逆に「#baseurl=~」のコメントを外すことでアップデートはできるようになる。

が・・・、面倒なので、Oracle LinuxのPublic Yum Serverを使用するように切り替えてみる。
つまりは、Oracle Linuxへの乗り換え、ということになる。

切り替え手順は簡単。
How can I convert an RHEL or RHEL-compatible system to Oracle Linux using public-yum?」と「Getting Started」を行う。

具体的には、「OracleのGPGキーを登録」してから、「Yumレポジトリを追加」、ということになる。

[root@centos4 ~]# wget http://public-yum.oracle.com/RPM-GPG-KEY-oracle-el4 -O /usr/share/rhn/RPM-GPG-KEY-oracle
--01:57:00--  http://public-yum.oracle.com/RPM-GPG-KEY-oracle-el4
           => `/usr/share/rhn/RPM-GPG-KEY-oracle'
public-yum.oracle.com をDNSに問いあわせています... 203.179.83.11, 203.179.83.19
public-yum.oracle.com|203.179.83.11|:80 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 200 OK
長さ: 1,744 (1.7K) 

100%[====================================>] 1,744         --.--K/s

01:57:01 (87.54 MB/s) - `/usr/share/rhn/RPM-GPG-KEY-oracle' を保存しました [1744/1744]

[root@centos4 ~]# gpg --quiet --with-fingerprint /usr/share/rhn/RPM-GPG-KEY-oracle
gpg: failed to create temporary file `/root/.gnupg/.#lk0x552ac57280.centos4.adosakana.net.4053': そのようなファイルやディレクトリはありません
gpg: 新しい構成ファイル`/root/.gnupg/gpg.conf'ができました
gpg: 警告: 「/root/.gnupg/gpg.conf」のオプションは起動している間、有効になりません
pub  1024D/B38A8516 2006-09-05 Oracle OSS group (Open Source Software group) <build@oss.oracle.com>
                指紋 = 1122 A29A B257 825F 322C  234E 2E2B CDBC B38A 8516
sub  2048g/0042D4F4 2006-09-05 [有効期限: 2011-09-04]
[root@centos4 ~]# cd /etc/yum.repos.d
[root@centos4 yum.repos.d]# mv CentOS-Base.repo CentOS-Base.repo.disabled
[root@centos4 yum.repos.d]# wget http://public-yum.oracle.com/public-yum-el4.repo
--01:58:33--  http://public-yum.oracle.com/public-yum-el4.repo
           => `public-yum-el4.repo'
public-yum.oracle.com をDNSに問いあわせています... 203.179.83.19, 203.179.83.11
public-yum.oracle.com|203.179.83.19|:80 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 200 OK
長さ: 1,191 (1.2K) 

100%[====================================>] 1,191         --.--K/s

01:58:33 (70.99 MB/s) - `public-yum-el4.repo' を保存しました [1191/1191]

[root@centos4 yum.repos.d]#

この後、「yum update」を実行すれば完了です。

ちなみに、この手法でアップデートした場合、release関連情報は以下のようになります。

[root@centos4 ~]# rpm -qa|grep release
enterprise-release-4-3.7.18
[root@centos4 ~]# cat /etc/redhat-release
Red Hat Enterprise Linux AS release 4 (Nahant Update 9)
[root@centos4 ~]#  rpm -qa|grep logo
oracle-logos-1.1.1-3
[root@centos4 ~]#

また、/etc/yum.repos.d/ULN-Base.repo が追加されますが、こいつが問題児で、2014年9月現在、これは使用できません。
無効にしてしまいましょう。

[root@centos4 ~]# mv /etc/yum.repos.d/ULN-Base.repo /etc/yum.repos.d/ULN-Base.repo.disabled
[root@centos4 ~]#

ついでに、vmware-toolsをyumレポジトリとして追加するには、/etc/yum.repos.d/vmwaretools.repoとして、以下の内容を記載しましょう。

[root@centos4 ~]# cat /etc/yum.repos.d/vmwaretools.repo
[vmwaretools]
name=vmwaretools
baseurl=http://packages.vmware.com/tools/esx/latest/rhel4/x86_64/
gpgcheck=0
[root@centos4 ~]#

X-Windowsがあるシステムの場合「yum install vmware-tools-esx」、X-Windowsがないシステムなら「yum install vmware-tools-esx-nox」でvmware-toolsをインストールできます。

モバイルバージョンを終了