Tetsuo Handa
from-****@I-lov*****
2011年 3月 2日 (水) 16:47:46 JST
カーネル 2.6.36 以降に含まれている TOMOYO 2.3 にメモリリークが見つかりました。 ファイルのオープン時にパーミッションをチェックする tomoyo_check_open_permission() の中で、 allow_rewrite パーミッションの チェック時に既に導出済みのパス名を再度導出してしまっていました。 int tomoyo_check_open_permission(struct tomoyo_domain_info *domain, struct path *path, const int flag) { const u8 acc_mode = ACC_MODE(flag); int error = -ENOMEM; struct tomoyo_path_info buf; struct tomoyo_request_info r; int idx; if (!path->mnt || (path->dentry->d_inode && S_ISDIR(path->dentry->d_inode->i_mode))) return 0; buf.name = NULL; r.mode = TOMOYO_CONFIG_DISABLED; idx = tomoyo_read_lock(); if (!tomoyo_get_realpath(&buf, path)) goto out; error = 0; /* * If the filename is specified by "deny_rewrite" keyword, * we need to check "allow_rewrite" permission when the filename is not * opened for append mode or the filename is truncated at open time. */ if ((acc_mode & MAY_WRITE) && !(flag & O_APPEND) && tomoyo_init_request_info(&r, domain, TOMOYO_MAC_FILE_REWRITE) != TOMOYO_CONFIG_DISABLED) { if (!tomoyo_get_realpath(&buf, path)) { error = -ENOMEM; goto out; } if (tomoyo_no_rewrite_file(&buf)) error = tomoyo_path_permission(&r, TOMOYO_TYPE_REWRITE, &buf); } (...snipped...) } そのため、ファイルが O_APPEND フラグを指定しないで書き込みモードでオープン された場合にメモリリークが発生します。また、プロファイルの設定に関係なく (つまり CONFIG={ mode=disabled } の場合であっても)パス名を導出してしまって いるためパフォーマンス低下が生じています。 このメモリリークおよびパフォーマンス低下を修正するためには以下のパッチを 適用して再コンパイルおよび再起動してください。 --- security/tomoyo/file.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) --- linux-2.6.38-rc7.orig/security/tomoyo/file.c +++ linux-2.6.38-rc7/security/tomoyo/file.c @@ -927,7 +927,7 @@ int tomoyo_check_open_permission(struct struct path *path, const int flag) { const u8 acc_mode = ACC_MODE(flag); - int error = -ENOMEM; + int error = 0; struct tomoyo_path_info buf; struct tomoyo_request_info r; int idx; @@ -938,9 +938,6 @@ int tomoyo_check_open_permission(struct buf.name = NULL; r.mode = TOMOYO_CONFIG_DISABLED; idx = tomoyo_read_lock(); - if (!tomoyo_get_realpath(&buf, path)) - goto out; - error = 0; /* * If the filename is specified by "deny_rewrite" keyword, * we need to check "allow_rewrite" permission when the filename is not すぐに再起動できない場合には、以下の内容を /etc/tomoyo/profile.conf および /sys/kernel/security/tomoyo/profile へと追加する( allow_rewrite パーミッション のチェックを無効化する)ことでメモリリークを回避できます。 0-CONFIG::file::rewrite={ mode=disabled } 1-CONFIG::file::rewrite={ mode=disabled } 2-CONFIG::file::rewrite={ mode=disabled } 3-CONFIG::file::rewrite={ mode=disabled }