All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/1] cifs: potential missing check for posix_lock_file_wait
@ 2015-03-25  0:18 Chengyu Song
       [not found] ` <1427242729-11515-1-git-send-email-csong84-/4noJB3qBVQ3uPMLIKxrzw@public.gmane.org>
  2015-04-03 12:11 ` Jeff Layton
  0 siblings, 2 replies; 6+ messages in thread
From: Chengyu Song @ 2015-03-25  0:18 UTC (permalink / raw)
  To: sfrench, linux-cifs, samba-technical, linux-kernel
  Cc: taesoo, changwoo, sanidhya, blee, csong84

posix_lock_file_wait may fail under certain circumstances, and its result is
usually checked/returned. But given the complexity of cifs, I'm not sure if
the result is intentially left unchecked and always expected to succeed.

Signed-off-by: Chengyu Song <csong84@gatech.edu>
---
 fs/cifs/file.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/cifs/file.c b/fs/cifs/file.c
index a94b3e6..beef67b 100644
--- a/fs/cifs/file.c
+++ b/fs/cifs/file.c
@@ -1553,8 +1553,8 @@ cifs_setlk(struct file *file, struct file_lock *flock, __u32 type,
 		rc = server->ops->mand_unlock_range(cfile, flock, xid);
 
 out:
-	if (flock->fl_flags & FL_POSIX)
-		posix_lock_file_wait(file, flock);
+	if (flock->fl_flags & FL_POSIX && !rc)
+		rc = posix_lock_file_wait(file, flock);
 	return rc;
 }
 
-- 
2.1.0

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/1] cifs: potential missing check for posix_lock_file_wait
  2015-03-25  0:18 [PATCH 1/1] cifs: potential missing check for posix_lock_file_wait Chengyu Song
@ 2015-03-25  2:29     ` Steve French
  2015-04-03 12:11 ` Jeff Layton
  1 sibling, 0 replies; 6+ messages in thread
From: Steve French @ 2015-03-25  2:29 UTC (permalink / raw)
  To: Chengyu Song
  Cc: Steve French, linux-cifs-u79uwXL29TY76Z2rM5mHXA, samba-technical,
	LKML, taesoo-/4noJB3qBVQ3uPMLIKxrzw,
	changwoo-/4noJB3qBVQ3uPMLIKxrzw, sanidhya-/4noJB3qBVQ3uPMLIKxrzw,
	Byoungyoung Lee

On Tue, Mar 24, 2015 at 7:18 PM, Chengyu Song <csong84-/4noJB3qBVQ3uPMLIKxrzw@public.gmane.org> wrote:
> posix_lock_file_wait may fail under certain circumstances, and its result is
> usually checked/returned. But given the complexity of cifs, I'm not sure if
> the result is intentially left unchecked and always expected to succeed.
>
> Signed-off-by: Chengyu Song <csong84-/4noJB3qBVQ3uPMLIKxrzw@public.gmane.org>
> ---
>  fs/cifs/file.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/fs/cifs/file.c b/fs/cifs/file.c
> index a94b3e6..beef67b 100644
> --- a/fs/cifs/file.c
> +++ b/fs/cifs/file.c
> @@ -1553,8 +1553,8 @@ cifs_setlk(struct file *file, struct file_lock *flock, __u32 type,
>                 rc = server->ops->mand_unlock_range(cfile, flock, xid);
>
>  out:
> -       if (flock->fl_flags & FL_POSIX)
> -               posix_lock_file_wait(file, flock);
> +       if (flock->fl_flags & FL_POSIX && !rc)
> +               rc = posix_lock_file_wait(file, flock);
>         return rc;
>  }
>

This is interesting.   Useful comparisons include

For network file systems you could
- enforce byte range locks only at the server
- enforce locks only on the client, and don't send to the server
- do both

Since cifs byte range locks are often emulated (except when Unix
Extensions are enabled, e.g. on mounts to Samba), we do the latter by
default, as does fs/9p (although they do it in a different order,
trying to grab the local byte range lock first).

But another interesting comparison point is nfs, where the code for v3
vs. v4 looks different. Take a look at nfsv3 (see fs/nfs/file.c) where
the choice is made to either do the posix_lock_file_wait (if 'local'
locking only) or if sending locks to the server then don't call to set
the local lock. Alternatively nfs4proc.c handles it differently.

There may not be a perfect answer on this one but was wondering if you
have experimented with what happens when you mount with "nobrl" (which
is the cifs mount option which causes locks not to be sent to the
server, and thus only evaulted locally).  My suspicion is that you can
demonstrate a failure if you mount with nobrl (without your patch).



-- 
Thanks,

Steve

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/1] cifs: potential missing check for posix_lock_file_wait
@ 2015-03-25  2:29     ` Steve French
  0 siblings, 0 replies; 6+ messages in thread
From: Steve French @ 2015-03-25  2:29 UTC (permalink / raw)
  To: Chengyu Song
  Cc: Steve French, linux-cifs, samba-technical, LKML, taesoo,
	changwoo, sanidhya, Byoungyoung Lee

On Tue, Mar 24, 2015 at 7:18 PM, Chengyu Song <csong84@gatech.edu> wrote:
> posix_lock_file_wait may fail under certain circumstances, and its result is
> usually checked/returned. But given the complexity of cifs, I'm not sure if
> the result is intentially left unchecked and always expected to succeed.
>
> Signed-off-by: Chengyu Song <csong84@gatech.edu>
> ---
>  fs/cifs/file.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/fs/cifs/file.c b/fs/cifs/file.c
> index a94b3e6..beef67b 100644
> --- a/fs/cifs/file.c
> +++ b/fs/cifs/file.c
> @@ -1553,8 +1553,8 @@ cifs_setlk(struct file *file, struct file_lock *flock, __u32 type,
>                 rc = server->ops->mand_unlock_range(cfile, flock, xid);
>
>  out:
> -       if (flock->fl_flags & FL_POSIX)
> -               posix_lock_file_wait(file, flock);
> +       if (flock->fl_flags & FL_POSIX && !rc)
> +               rc = posix_lock_file_wait(file, flock);
>         return rc;
>  }
>

This is interesting.   Useful comparisons include

For network file systems you could
- enforce byte range locks only at the server
- enforce locks only on the client, and don't send to the server
- do both

Since cifs byte range locks are often emulated (except when Unix
Extensions are enabled, e.g. on mounts to Samba), we do the latter by
default, as does fs/9p (although they do it in a different order,
trying to grab the local byte range lock first).

But another interesting comparison point is nfs, where the code for v3
vs. v4 looks different. Take a look at nfsv3 (see fs/nfs/file.c) where
the choice is made to either do the posix_lock_file_wait (if 'local'
locking only) or if sending locks to the server then don't call to set
the local lock. Alternatively nfs4proc.c handles it differently.

There may not be a perfect answer on this one but was wondering if you
have experimented with what happens when you mount with "nobrl" (which
is the cifs mount option which causes locks not to be sent to the
server, and thus only evaulted locally).  My suspicion is that you can
demonstrate a failure if you mount with nobrl (without your patch).



-- 
Thanks,

Steve

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/1] cifs: potential missing check for posix_lock_file_wait
  2015-03-25  2:29     ` Steve French
  (?)
@ 2015-03-25 17:26     ` Chengyu Song
  -1 siblings, 0 replies; 6+ messages in thread
From: Chengyu Song @ 2015-03-25 17:26 UTC (permalink / raw)
  To: Steve French
  Cc: Steve French, linux-cifs, samba-technical, LKML, taesoo,
	changwoo, sanidhya, Byoungyoung Lee


> On Mar 24, 2015, at 10:29 PM, Steve French <smfrench@gmail.com> wrote:
> 
> On Tue, Mar 24, 2015 at 7:18 PM, Chengyu Song <csong84@gatech.edu> wrote:
>> posix_lock_file_wait may fail under certain circumstances, and its result is
>> usually checked/returned. But given the complexity of cifs, I'm not sure if
>> the result is intentially left unchecked and always expected to succeed.
>> 
>> Signed-off-by: Chengyu Song <csong84@gatech.edu>
>> ---
>> fs/cifs/file.c | 4 ++--
>> 1 file changed, 2 insertions(+), 2 deletions(-)
>> 
>> diff --git a/fs/cifs/file.c b/fs/cifs/file.c
>> index a94b3e6..beef67b 100644
>> --- a/fs/cifs/file.c
>> +++ b/fs/cifs/file.c
>> @@ -1553,8 +1553,8 @@ cifs_setlk(struct file *file, struct file_lock *flock, __u32 type,
>>                rc = server->ops->mand_unlock_range(cfile, flock, xid);
>> 
>> out:
>> -       if (flock->fl_flags & FL_POSIX)
>> -               posix_lock_file_wait(file, flock);
>> +       if (flock->fl_flags & FL_POSIX && !rc)
>> +               rc = posix_lock_file_wait(file, flock);
>>        return rc;
>> }
>> 
> 
> This is interesting.   Useful comparisons include
> 
> For network file systems you could
> - enforce byte range locks only at the server
> - enforce locks only on the client, and don't send to the server
> - do both
> 
> Since cifs byte range locks are often emulated (except when Unix
> Extensions are enabled, e.g. on mounts to Samba), we do the latter by
> default, as does fs/9p (although they do it in a different order,
> trying to grab the local byte range lock first).
> 
> But another interesting comparison point is nfs, where the code for v3
> vs. v4 looks different. Take a look at nfsv3 (see fs/nfs/file.c) where
> the choice is made to either do the posix_lock_file_wait (if 'local'
> locking only) or if sending locks to the server then don't call to set
> the local lock. Alternatively nfs4proc.c handles it differently.
> 
> There may not be a perfect answer on this one but was wondering if you
> have experimented with what happens when you mount with "nobrl" (which
> is the cifs mount option which causes locks not to be sent to the
> server, and thus only evaulted locally).  My suspicion is that you can
> demonstrate a failure if you mount with nobrl (without your patch).
> 

Maybe it's better to provide more context. We're developing a static checker that
cross check different implementations of filesystems, and this is a warning we get
from that tool as it is the only place where the return value of posix_lock_file_wait
is not checked/forwarded. So I have not experimented with mounting options.

And I guess another thing is, for the path of posix_lock == false, posix_lock_file_wait
is never invoked if any error happens. But for CIFSSMBPosixLock, its return value
is never checked and posix_lock_file_wait is always invoked.

Thanks,
Chengyu

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/1] cifs: potential missing check for posix_lock_file_wait
  2015-03-25  0:18 [PATCH 1/1] cifs: potential missing check for posix_lock_file_wait Chengyu Song
       [not found] ` <1427242729-11515-1-git-send-email-csong84-/4noJB3qBVQ3uPMLIKxrzw@public.gmane.org>
@ 2015-04-03 12:11 ` Jeff Layton
  2015-05-20 18:16   ` Steve French
  1 sibling, 1 reply; 6+ messages in thread
From: Jeff Layton @ 2015-04-03 12:11 UTC (permalink / raw)
  To: Chengyu Song
  Cc: sfrench, linux-cifs, samba-technical, linux-kernel, taesoo,
	changwoo, sanidhya, blee, Pavel Shilovsky

On Tue, 24 Mar 2015 20:18:49 -0400
Chengyu Song <csong84@gatech.edu> wrote:

> posix_lock_file_wait may fail under certain circumstances, and its result is
> usually checked/returned. But given the complexity of cifs, I'm not sure if
> the result is intentially left unchecked and always expected to succeed.
> 
> Signed-off-by: Chengyu Song <csong84@gatech.edu>
> ---
>  fs/cifs/file.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/cifs/file.c b/fs/cifs/file.c
> index a94b3e6..beef67b 100644
> --- a/fs/cifs/file.c
> +++ b/fs/cifs/file.c
> @@ -1553,8 +1553,8 @@ cifs_setlk(struct file *file, struct file_lock *flock, __u32 type,
>  		rc = server->ops->mand_unlock_range(cfile, flock, xid);
>  
>  out:
> -	if (flock->fl_flags & FL_POSIX)
> -		posix_lock_file_wait(file, flock);
> +	if (flock->fl_flags & FL_POSIX && !rc)
> +		rc = posix_lock_file_wait(file, flock);
>  	return rc;
>  }
>  

(cc'ing Pavel since he wrote a lot of this code)

I think your patch looks correct -- if we (for instance) get a memory
allocation failure while trying to set the local lock then I think we
probably don't want to return success. So...

    Acked-by: Jeff Layton <jeff.layton@primarydata.com>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/1] cifs: potential missing check for posix_lock_file_wait
  2015-04-03 12:11 ` Jeff Layton
@ 2015-05-20 18:16   ` Steve French
  0 siblings, 0 replies; 6+ messages in thread
From: Steve French @ 2015-05-20 18:16 UTC (permalink / raw)
  To: Jeff Layton
  Cc: Chengyu Song, Steve French, linux-cifs, samba-technical, LKML,
	taesoo, changwoo, sanidhya, Byoungyoung Lee, Pavel Shilovsky

merged into cifs-2.6.git for-next

On Fri, Apr 3, 2015 at 7:11 AM, Jeff Layton <jeff.layton@primarydata.com> wrote:
> On Tue, 24 Mar 2015 20:18:49 -0400
> Chengyu Song <csong84@gatech.edu> wrote:
>
>> posix_lock_file_wait may fail under certain circumstances, and its result is
>> usually checked/returned. But given the complexity of cifs, I'm not sure if
>> the result is intentially left unchecked and always expected to succeed.
>>
>> Signed-off-by: Chengyu Song <csong84@gatech.edu>
>> ---
>>  fs/cifs/file.c | 4 ++--
>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/fs/cifs/file.c b/fs/cifs/file.c
>> index a94b3e6..beef67b 100644
>> --- a/fs/cifs/file.c
>> +++ b/fs/cifs/file.c
>> @@ -1553,8 +1553,8 @@ cifs_setlk(struct file *file, struct file_lock *flock, __u32 type,
>>               rc = server->ops->mand_unlock_range(cfile, flock, xid);
>>
>>  out:
>> -     if (flock->fl_flags & FL_POSIX)
>> -             posix_lock_file_wait(file, flock);
>> +     if (flock->fl_flags & FL_POSIX && !rc)
>> +             rc = posix_lock_file_wait(file, flock);
>>       return rc;
>>  }
>>
>
> (cc'ing Pavel since he wrote a lot of this code)
>
> I think your patch looks correct -- if we (for instance) get a memory
> allocation failure while trying to set the local lock then I think we
> probably don't want to return success. So...
>
>     Acked-by: Jeff Layton <jeff.layton@primarydata.com>



-- 
Thanks,

Steve

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-05-20 18:16 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-25  0:18 [PATCH 1/1] cifs: potential missing check for posix_lock_file_wait Chengyu Song
     [not found] ` <1427242729-11515-1-git-send-email-csong84-/4noJB3qBVQ3uPMLIKxrzw@public.gmane.org>
2015-03-25  2:29   ` Steve French
2015-03-25  2:29     ` Steve French
2015-03-25 17:26     ` Chengyu Song
2015-04-03 12:11 ` Jeff Layton
2015-05-20 18:16   ` Steve French

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.