The patch titled Subject: proc: revalidate misc dentries has been added to the -mm tree. Its filename is proc-revalidate-misc-dentries.patch This patch should soon appear at http://ozlabs.org/~akpm/mmots/broken-out/proc-revalidate-misc-dentries.patch and later at http://ozlabs.org/~akpm/mmotm/broken-out/proc-revalidate-misc-dentries.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ From: Alexey Dobriyan <adobriyan@xxxxxxxxx> Subject: proc: revalidate misc dentries If module removes proc directory while another process pins it by chdir'ing to it, then subsequent recreation of proc entry and all entries down the tree will not be visible to any process until pinning process unchdir from directory and unpins everything. Steps to reproduce: proc_mkdir("aaa", NULL); proc_create("aaa/bbb", ...); chdir("/proc/aaa"); remove_proc_entry("aaa/bbb", NULL); remove_proc_entry("aaa", NULL); proc_mkdir("aaa", NULL); # inaccessible because "aaa" dentry still points # to the original "aaa". proc_create("aaa/bbb", ...); Fix is to implement ->d_revalidate and ->d_delete. Link: http://lkml.kernel.org/r/20180312201938.GA4871@avx2 Signed-off-by: Alexey Dobriyan <adobriyan@xxxxxxxxx> Cc: Al Viro <viro@xxxxxxxxxxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- fs/proc/generic.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff -puN fs/proc/generic.c~proc-revalidate-misc-dentries fs/proc/generic.c --- a/fs/proc/generic.c~proc-revalidate-misc-dentries +++ a/fs/proc/generic.c @@ -15,6 +15,7 @@ #include <linux/stat.h> #include <linux/mm.h> #include <linux/module.h> +#include <linux/namei.h> #include <linux/slab.h> #include <linux/printk.h> #include <linux/mount.h> @@ -219,6 +220,26 @@ void proc_free_inum(unsigned int inum) ida_simple_remove(&proc_inum_ida, inum - PROC_DYNAMIC_FIRST); } +static int proc_misc_d_revalidate(struct dentry *dentry, unsigned int flags) +{ + if (flags & LOOKUP_RCU) + return -ECHILD; + + if (atomic_read(&PDE(d_inode(dentry))->in_use) < 0) + return 0; /* revalidate */ + return 1; +} + +static int proc_misc_d_delete(const struct dentry *dentry) +{ + return atomic_read(&PDE(d_inode(dentry))->in_use) < 0; +} + +static const struct dentry_operations proc_misc_dentry_ops = { + .d_revalidate = proc_misc_d_revalidate, + .d_delete = proc_misc_d_delete, +}; + /* * Don't create negative dentries here, return -ENOENT by hand * instead. @@ -236,7 +257,7 @@ struct dentry *proc_lookup_de(struct ino inode = proc_get_inode(dir->i_sb, de); if (!inode) return ERR_PTR(-ENOMEM); - d_set_d_op(dentry, &simple_dentry_operations); + d_set_d_op(dentry, &proc_misc_dentry_ops); d_add(dentry, inode); return NULL; } _ Patches currently in -mm which might be from adobriyan@xxxxxxxxx are slab-mark-kmalloc-machinery-as-__ro_after_init.patch slab-fixup-calculate_alignment-argument-type.patch slab-make-kmalloc_index-return-unsigned-int.patch slab-make-kmalloc_size-return-unsigned-int.patch slab-make-create_kmalloc_cache-work-with-32-bit-sizes.patch slab-make-create_boot_cache-work-with-32-bit-sizes.patch slab-make-kmem_cache_create-work-with-32-bit-sizes.patch slab-make-size_index-array-u8.patch slab-make-size_index_elem-unsigned-int.patch slub-make-remote_node_defrag_ratio-unsigned-int.patch slub-make-max_attr_size-unsigned-int.patch slub-make-red_left_pad-unsigned-int.patch slub-make-reserved-unsigned-int.patch slub-make-align-unsigned-int.patch slub-make-inuse-unsigned-int.patch slub-make-cpu_partial-unsigned-int.patch slub-make-offset-unsigned-int.patch slub-make-object_size-unsigned-int.patch slub-make-size-unsigned-int.patch slab-make-kmem_cache_flags-accept-32-bit-object-size.patch kasan-make-kasan_cache_create-work-with-32-bit-slab-cache-sizes.patch slab-make-usercopy-region-32-bit.patch slub-make-slab_index-return-unsigned-int.patch slub-make-struct-kmem_cache_order_objects-x-unsigned-int.patch slub-make-size_from_object-return-unsigned-int.patch slab-use-32-bit-arithmetic-in-freelist_randomize.patch proc-do-less-stuff-under-pde_unload_lock.patch proc-move-proc-sysvipc-creation-to-where-it-belongs.patch proc-faster-open-close-of-files-without-release-hook.patch proc-randomize-struct-pde_opener.patch proc-move-struct-pde_opener-to-kmem-cache.patch proc-account-struct-pde_opener.patch proc-check-permissions-earlier-for-proc-wchan.patch proc-use-set_puts-at-proc-wchan.patch proc-test-proc-self-wchan.patch proc-test-proc-self-syscall.patch proc-move-struct-proc_dir_entry-into-kmem-cache.patch proc-fix-proc-map_files-lookup-some-more.patch proc-register-filesystem-last.patch proc-faster-proc-cmdline.patch proc-do-mmput-asap-for-proc-map_files.patch proc-revalidate-misc-dentries.patch uts-create-struct-uts_namespace-from-kmem_cache.patch seq_file-delete-small-value-optimization.patch -- To unsubscribe from this list: send the line "unsubscribe mm-commits" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html