Skip to contentSkip to conversation

fanotify: dont destroy mark when ignore mask is cleared

PATCH Lino Sanfilippo 2 participants 2 messages Nov 30, 2010 1 message not in the archive VFS

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw
Quoted 10 lines · Lino Sanfilippo

I guess it is a question of safe vs racy. Yes it is safe, nothing will explode or panic. But we might have a race between one task removing an event type causing the mask to go to 0 and we should destroy the mark and another task adding an event type. If it raced just right we might destroy the mark after the second task added to it. I guess we really need to serialize fsnotify_mark() per group to solve the race...

Do you want to take a stab at fixing these things or should I?

-Eric

IMHO the right thing to serialize this would be to do

LOCK(groups->mark_lock)
- get the inode mark
- set the marks mask
- possibly destroy the mask
UNLOCK(groups->mark_lock)

But we cant do this since setting the marks mask requires the lock of the mark
- which would mean an incorrect lock order according to fsnotify_add_mark():

mark->lock
group->mark_lock
inode->i_lock

What we could do very easily is use another mutex instead (use an existing one like the groups notification_mutex, or a completely new one) which is responsible for synchronising add_mark()/remove_mark().

If that solution is ok I'll prepare the patches for it. Otherwise i am not sure how to solve this...

Lino

#2 lore raw
Quoted 24 lines · Lino Sanfilippo
Quoted 10 lines · Lino Sanfilippo

I guess it is a question of safe vs racy. Yes it is safe, nothing will explode or panic. But we might have a race between one task removing an event type causing the mask to go to 0 and we should destroy the mark and another task adding an event type. If it raced just right we might destroy the mark after the second task added to it. I guess we really need to serialize fsnotify_mark() per group to solve the race...

Do you want to take a stab at fixing these things or should I?

-Eric

IMHO the right thing to serialize this would be to do

LOCK(groups->mark_lock)
- get the inode mark
- set the marks mask
- possibly destroy the mask
UNLOCK(groups->mark_lock)

But we cant do this since setting the marks mask requires the lock of the mark
- which would mean an incorrect lock order according to fsnotify_add_mark():

Quoted 7 lines

mark->lock
group->mark_lock
inode->i_lock

What we could do very easily is use another mutex instead (use an existing one like the groups notification_mutex, or a completely new one) which is responsible for synchronising add_mark()/remove_mark().

I'd think a new per group mutex would be the right way to go. I'm not sure how I feel about notification_mutex. I guess you can go ahead and overload it and we can split it off later if someone finds it to be a performance blocker.

-Eric