• M
    ovl: pass correct flags for opening real directory · 7b6488e9
    Miklos Szeredi 提交于
    mainline inclusion
    from mainline-v5.8-rc1
    commit 130fdbc3
    category: bugfix
    bugzilla: NA
    CVE: CVE-2020-16120
    
    --------------------------------
    
    The three instances of ovl_path_open() in overlayfs/readdir.c do three
    different things:
    
     - pass f_flags from overlay file
     - pass O_RDONLY | O_DIRECTORY
     - pass just O_RDONLY
    
    The value of f_flags can be (other than O_RDONLY):
    
    O_WRONLY	- not possible for a directory
    O_RDWR		- not possible for a directory
    O_CREAT		- masked out by dentry_open()
    O_EXCL		- masked out by dentry_open()
    O_NOCTTY	- masked out by dentry_open()
    O_TRUNC		- masked out by dentry_open()
    O_APPEND	- no effect on directory ops
    O_NDELAY	- no effect on directory ops
    O_NONBLOCK	- no effect on directory ops
    __O_SYNC	- no effect on directory ops
    O_DSYNC		- no effect on directory ops
    FASYNC		- no effect on directory ops
    O_DIRECT	- no effect on directory ops
    O_LARGEFILE	- ?
    O_DIRECTORY	- only affects lookup
    O_NOFOLLOW	- only affects lookup
    O_NOATIME	- overlay sets this unconditionally in ovl_path_open()
    O_CLOEXEC	- only affects fd allocation
    O_PATH		- no effect on directory ops
    __O_TMPFILE	- not possible for a directory
    
    Fon non-merge directories we use the underlying filesystem's iterate; in
    this case honor O_LARGEFILE from the original file to make sure that open
    doesn't get rejected.
    
    For merge directories it's safe to pass O_LARGEFILE unconditionally since
    userspace will only see the artificial offsets created by overlayfs.
    Signed-off-by: NMiklos Szeredi <mszeredi@redhat.com>
    Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
    Reviewed-by: Nzhangyi (F) <yi.zhang@huawei.com>
    Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
    Acked-by: NXie XiuQi <xiexiuqi@huawei.com>
    Signed-off-by: NCheng Jian <cj.chengjian@huawei.com>
    7b6488e9
readdir.c 25.9 KB