Skip to content

Commit 7026f19

Browse files
dhowellstorvalds
authored andcommitted
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 occur: -->fscache_alloc_object() -->cachefiles_alloc_object() [via cache->ops->alloc_object] <--[returns new object] -->fscache_attach_object() <--[failed] -->cachefiles_put_object() [via cache->ops->put_object] -->fscache_object_destroy() -->fscache_objlist_remove() -->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 fscache_objlist_add(). 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 <neilb@suse.de> Signed-off-by: David Howells <dhowells@redhat.com> Tested-by: (a customer of) NeilBrown <neilb@suse.de> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 416e2ab commit 7026f19

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

‎fs/fscache/object-list.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ void fscache_objlist_add(struct fscache_object *obj)
5050
struct fscache_object *xobj;
5151
struct rb_node **p = &fscache_object_list.rb_node, *parent = NULL;
5252

53+
ASSERT(RB_EMPTY_NODE(&obj->objlist_link));
54+
5355
write_lock(&fscache_object_list_lock);
5456

5557
while (*p) {
@@ -75,6 +77,9 @@ void fscache_objlist_add(struct fscache_object *obj)
7577
*/
7678
void fscache_objlist_remove(struct fscache_object *obj)
7779
{
80+
if (RB_EMPTY_NODE(&obj->objlist_link))
81+
return;
82+
7883
write_lock(&fscache_object_list_lock);
7984

8085
BUG_ON(RB_EMPTY_ROOT(&fscache_object_list));

‎fs/fscache/object.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,9 @@ void fscache_object_init(struct fscache_object *object,
314314
object->cache = cache;
315315
object->cookie = cookie;
316316
object->parent = NULL;
317+
#ifdef CONFIG_FSCACHE_OBJECT_LIST
318+
RB_CLEAR_NODE(&object->objlist_link);
319+
#endif
317320

318321
object->oob_event_mask = 0;
319322
for (t = object->oob_table; t->events; t++)

0 commit comments

Comments
 (0)