]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
kernfs: fix ino wrap-around detection
authorTejun Heo <tj@kernel.org>
Mon, 4 Nov 2019 23:54:29 +0000 (15:54 -0800)
committerMarcelo Henrique Cerri <marcelo.cerri@canonical.com>
Fri, 17 Jan 2020 17:22:27 +0000 (14:22 -0300)
BugLink: https://bugs.launchpad.net/bugs/1857158
commit e23f568aa63f64cd6b355094224cc9356c0f696b upstream.

When the 32bit ino wraps around, kernfs increments the generation
number to distinguish reused ino instances.  The wrap-around detection
tests whether the allocated ino is lower than what the cursor but the
cursor is pointing to the next ino to allocate so the condition never
triggers.

Fix it by remembering the last ino and comparing against that.

Signed-off-by: Tejun Heo <tj@kernel.org>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Fixes: 4a3ef68acacf ("kernfs: implement i_generation")
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: stable@vger.kernel.org # v4.14+
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
fs/kernfs/dir.c
include/linux/kernfs.h

index c95490e9b2258e0ef63b3052fdce5fc32af877f9..5d7f34e7547d372461a7d77ccca937532ad19569 100644 (file)
@@ -624,7 +624,6 @@ static struct kernfs_node *__kernfs_new_node(struct kernfs_root *root,
 {
        struct kernfs_node *kn;
        u32 gen;
-       int cursor;
        int ret;
 
        name = kstrdup_const(name, GFP_KERNEL);
@@ -637,11 +636,11 @@ static struct kernfs_node *__kernfs_new_node(struct kernfs_root *root,
 
        idr_preload(GFP_KERNEL);
        spin_lock(&kernfs_idr_lock);
-       cursor = idr_get_cursor(&root->ino_idr);
        ret = idr_alloc_cyclic(&root->ino_idr, kn, 1, 0, GFP_ATOMIC);
-       if (ret >= 0 && ret < cursor)
+       if (ret >= 0 && ret < root->last_ino)
                root->next_generation++;
        gen = root->next_generation;
+       root->last_ino = ret;
        spin_unlock(&kernfs_idr_lock);
        idr_preload_end();
        if (ret < 0)
index 814643f7ee529eb6c9e27ec3e1653487d818595e..84e9358d605f8778d484678d08ede89e4e0f1178 100644 (file)
@@ -186,6 +186,7 @@ struct kernfs_root {
 
        /* private fields, do not use outside kernfs proper */
        struct idr              ino_idr;
+       u32                     last_ino;
        u32                     next_generation;
        struct kernfs_syscall_ops *syscall_ops;