Fix losing locks during fork

Submitted by piastry@etersoft.ru on April 5, 2010, 9:17 p.m.

Details

Message ID 201004060117.39791.piastry@etersoft.ru
State New
Headers show

Commit Message

piastry@etersoft.ru April 5, 2010, 9:17 p.m.
Sorry, for resending - wrong description in the previous email.

From: Pavel Shilovsky <piastryyy@gmail.com>

When process does fork() private_data of files with lock list stays the same
for file descriptors of the parent and of the child. While finishing the child closes
files and deletes locks from the list even if unlocking fails. When the child process
finishes the parent doesn't have lock in lock list and can't unlock previously before
fork() locked region after the child process finished.

This patch provides behaviour to save locks in lock list if unlocking fails.
---
 fs/cifs/file.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)

Comments

Jeff Layton April 6, 2010, 12:14 p.m.
On Tue, 6 Apr 2010 01:17:39 +0400
Pavel Shilovsky <piastry@etersoft.ru> wrote:

> Sorry, for resending - wrong description in the previous email.
> 
> From: Pavel Shilovsky <piastryyy@gmail.com>
> 
> When process does fork() private_data of files with lock list stays the same
> for file descriptors of the parent and of the child. While finishing the child closes
> files and deletes locks from the list even if unlocking fails. When the child process
> finishes the parent doesn't have lock in lock list and can't unlock previously before
> fork() locked region after the child process finished.
> 
> This patch provides behaviour to save locks in lock list if unlocking fails.
> ---
>  fs/cifs/file.c |    7 ++++---
>  1 files changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/cifs/file.c b/fs/cifs/file.c
> index c34b7f8..7185cd3 100644
> --- a/fs/cifs/file.c
> +++ b/fs/cifs/file.c
> @@ -898,9 +898,10 @@ int cifs_lock(struct file *file, int cmd, struct file_lock *pfLock)
>                                                         1, 0, li->type, false);
>                                         if (stored_rc)
>                                                 rc = stored_rc;
> -
> -                                       list_del(&li->llist);
> -                                       kfree(li);
> +                                       else {
> +                                               list_del(&li->llist);
> +                                               kfree(li);
> +                                       }
>                                 }
>                         }
>                         mutex_unlock(&fid->lock_mutex);

Looks correct to me.

Reviewed-by: Jeff Layton <jlayton@samba.org>

Patch hide | download patch | download mbox

diff --git a/fs/cifs/file.c b/fs/cifs/file.c
index c34b7f8..7185cd3 100644
--- a/fs/cifs/file.c
+++ b/fs/cifs/file.c
@@ -898,9 +898,10 @@  int cifs_lock(struct file *file, int cmd, struct file_lock *pfLock)
                                                        1, 0, li->type, false);
                                        if (stored_rc)
                                                rc = stored_rc;
-
-                                       list_del(&li->llist);
-                                       kfree(li);
+                                       else {
+                                               list_del(&li->llist);
+                                               kfree(li);
+                                       }
                                }
                        }
                        mutex_unlock(&fid->lock_mutex);