Clearing FMODE_LSEEK flag should not rely on whether proc_open ops exists, fix it. Fixed: ad7f4ea6e36e ("proc: avoid use-after-free in proc_reg_open()") Signed-off-by: wangzijie <wangzijie1@xxxxxxxxx> --- Based on mm-nonmm-unstable --- fs/proc/inode.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/fs/proc/inode.c b/fs/proc/inode.c index 8de0af8c3..10a8481cc 100644 --- a/fs/proc/inode.c +++ b/fs/proc/inode.c @@ -474,12 +474,11 @@ static int proc_reg_open(struct inode *inode, struct file *file) struct pde_opener *pdeo; if (pde_is_permanent(pde)) { + if (!pde->proc_ops->proc_lseek) + file->f_mode &= ~FMODE_LSEEK; open = pde->proc_ops->proc_open; - if (open) { - if (!pde->proc_ops->proc_lseek) - file->f_mode &= ~FMODE_LSEEK; + if (open) rv = open(inode, file); - } return rv; } -- 2.25.1