[Devel] [PATCH rh7] ploop: push_backup: fix reentrance in ploop_pb_get_pending()

Dmitry Monakhov dmonakhov at openvz.org
Mon May 9 15:32:19 PDT 2016


The patch implements what Dima Monakhov suggested:

>  AFAIU you have a re-entrance issue if several tasks want performs ioctls
>   task1:ioctl->wait
> 		    task2:ioctl->wait
>
>   Just change wait sequence like this and you are safe:
> 		   /* blocking case */
> 		  if (unlikely(pbd->ppb_waiting))
> 		       /* Other task is already waitng for event */
> 		       err = -EBUSY;
> 		       goto get_pending_unlock;
> 		  }
> 		  pbd->ppb_waiting = true;
> 		  spin_unlock(&pbd->ppb_lock);
> 		  mutex_unlock(&plo->ctl_mutex);

Signed-off-by: Maxim Patlasov <mpatlasov at virtuozzo.com>
---
 drivers/block/ploop/push_backup.c |    5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/block/ploop/push_backup.c b/drivers/block/ploop/push_backup.c
index 4d671a5..10fd55a 100644
--- a/drivers/block/ploop/push_backup.c
+++ b/drivers/block/ploop/push_backup.c
@@ -466,6 +466,11 @@ int ploop_pb_get_pending(struct ploop_pushbackup_desc *pbd,
 		}
 
                 /* blocking case */
+		if (unlikely(pbd->ppb_waiting)) {
+			/* Other task is already waitng for event */
+			err = -EBUSY;
+			goto get_pending_unlock;
+		}
 		pbd->ppb_waiting = true;
 		spin_unlock(&pbd->ppb_lock);
 



More information about the Devel mailing list