Browse files

FS-Cache: Handle removal of unadded object to the fscache_object_list…

… rb tree

When FS-Cache allocates an object, the following sequence of events can

    -->cachefiles_alloc_object() [via cache->ops->alloc_object]
    <--[returns new object]
    -->cachefiles_put_object() [via cache->ops->put_object]
             -->rb_erase() to remove the object from fscache_object_list.

resulting in a crash in the rbtree code.

The problem is that the object is only added to fscache_object_list on
the success path of fscache_attach_object() where it calls

So if fscache_attach_object() fails, the object won't have been added to
the objlist rbtree.  We do, however, unconditionally try to remove the
object from the tree.

Thanks to NeilBrown for finding this and suggesting this solution.

Reported-by: NeilBrown <>
Signed-off-by: David Howells <>
Tested-by: (a customer of) NeilBrown <>
Signed-off-by: Linus Torvalds <>
  • Loading branch information...
1 parent 416e2ab commit 7026f1929e18921fd67bf478f475a8fdfdff16ae @dhowells dhowells committed with Feb 17, 2014
Showing with 8 additions and 0 deletions.
  1. +5 −0 fs/fscache/object-list.c
  2. +3 −0 fs/fscache/object.c
@@ -50,6 +50,8 @@ void fscache_objlist_add(struct fscache_object *obj)
struct fscache_object *xobj;
struct rb_node **p = &fscache_object_list.rb_node, *parent = NULL;
+ ASSERT(RB_EMPTY_NODE(&obj->objlist_link));
while (*p) {
@@ -75,6 +77,9 @@ void fscache_objlist_add(struct fscache_object *obj)
void fscache_objlist_remove(struct fscache_object *obj)
+ if (RB_EMPTY_NODE(&obj->objlist_link))
+ return;
@@ -314,6 +314,9 @@ void fscache_object_init(struct fscache_object *object,
object->cache = cache;
object->cookie = cookie;
object->parent = NULL;
+ RB_CLEAR_NODE(&object->objlist_link);
object->oob_event_mask = 0;
for (t = object->oob_table; t->events; t++)

0 comments on commit 7026f19

Please sign in to comment.