diff options
author | Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> | 2019-06-22 13:14:26 +0900 |
---|---|---|
committer | Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> | 2019-11-25 19:48:54 +0900 |
commit | df8aec8cd8b26b314d4bf4c6092377b2cf2f24df (patch) | |
tree | 15d514e5e2464dfb8b6a325ccdda06cf1c9033ec /security | |
parent | 219d54332a09e8d8741c1e1982f5eae56099de85 (diff) | |
download | linux-next-df8aec8cd8b26b314d4bf4c6092377b2cf2f24df.tar.gz |
tomoyo: Don't check open/getattr permission on sockets.
syzbot is reporting that use of SOCKET_I()->sk from open() can result in
use after free problem [1], for socket's inode is still reachable via
/proc/pid/fd/n despite destruction of SOCKET_I()->sk already completed.
But there is no point with calling security_file_open() on sockets
because open("/proc/pid/fd/n", !O_PATH) on sockets fails with -ENXIO.
There is some point with calling security_inode_getattr() on sockets
because stat("/proc/pid/fd/n") and fstat(open("/proc/pid/fd/n", O_PATH))
are valid. If we want to access "struct sock"->sk_{family,type,protocol}
fields, we will need to use security_socket_post_create() hook and
security_inode_free() hook in order to remember these fields because
security_sk_free() hook is called before the inode is destructed. But
since information which can be protected by checking
security_inode_getattr() on sockets is trivial, let's not be bothered by
"struct inode"->i_security management.
There is point with calling security_file_ioctl() on sockets. Since
ioctl(open("/proc/pid/fd/n", O_PATH)) is invalid, security_file_ioctl()
on sockets should remain safe.
[1] https://syzkaller.appspot.com/bug?id=73d590010454403d55164cca23bd0565b1eb3b74
Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Reported-by: syzbot <syzbot+0341f6a4d729d4e0acf1@syzkaller.appspotmail.com>
Diffstat (limited to 'security')
-rw-r--r-- | security/tomoyo/tomoyo.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c index 716c92ec941a..8ea3f5d4e551 100644 --- a/security/tomoyo/tomoyo.c +++ b/security/tomoyo/tomoyo.c @@ -126,6 +126,9 @@ static int tomoyo_bprm_check_security(struct linux_binprm *bprm) */ static int tomoyo_inode_getattr(const struct path *path) { + /* It is not safe to call tomoyo_get_socket_name(). */ + if (S_ISSOCK(d_inode(path->dentry)->i_mode)) + return 0; return tomoyo_path_perm(TOMOYO_TYPE_GETATTR, path, NULL); } @@ -316,6 +319,9 @@ static int tomoyo_file_open(struct file *f) /* Don't check read permission here if called from do_execve(). */ if (current->in_execve) return 0; + /* Sockets can't be opened by open(). */ + if (S_ISSOCK(file_inode(f)->i_mode)) + return 0; return tomoyo_check_open_permission(tomoyo_domain(), &f->f_path, f->f_flags); } |