提交 7f827caa 编写于 作者: T Tetsuo Handa 提交者: Xie XiuQi

fs: Allow opening only regular files during execve()

euler inclusion
category: bugfix
bugzilla: 10703
CVE: NA

---------------------------

syzbot is hitting lockdep warning [1] due to trying to open a fifo during
an execve() operation. But we don't need to open non regular files during
an execve() operation, for all files which we will need are the executable
file itself and the interpreter programs like /bin/sh and ld-linux.so.2.

Since the manpage for execve(2) says that execve() returns EACCES when
the file or a script interpreter is not a regular file, and the manpage
for uselib(2) says that uselib() can return EACCES, and we use FMODE_EXEC
when opening for execve()/uselib(), let's bail out if a non regular file
is requested with FMODE_EXEC set.

Link: https://lore.kernel.org/patchwork/patch/1034270/Signed-off-by: NTetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Signed-off-by: Nzhengbin <zhengbin13@huawei.com>
Reviewed-by: NHou Tao <houtao1@huawei.com>
Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
上级 4223d41d
...@@ -733,6 +733,12 @@ static int do_dentry_open(struct file *f, ...@@ -733,6 +733,12 @@ static int do_dentry_open(struct file *f,
return 0; return 0;
} }
/* Any file opened for execve()/uselib() has to be a regular file. */
if (unlikely(f->f_flags & FMODE_EXEC && !S_ISREG(inode->i_mode))) {
error = -EACCES;
goto cleanup_file;
}
if (f->f_mode & FMODE_WRITE && !special_file(inode->i_mode)) { if (f->f_mode & FMODE_WRITE && !special_file(inode->i_mode)) {
error = get_write_access(inode); error = get_write_access(inode);
if (unlikely(error)) if (unlikely(error))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册