Bug 201971 - wrong status_to_posix_error mapping
Summary: wrong status_to_posix_error mapping
Status: RESOLVED CODE_FIX
Alias: None
Product: File System
Classification: Unclassified
Component: CIFS (show other bugs)
Hardware: All Linux
: P1 normal
Assignee: fs_cifs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-12-12 08:58 UTC by omgbebebe
Modified: 2019-02-08 14:34 UTC (History)
3 users (show)

See Also:
Kernel Version: 4.19.7
Subsystem:
Regression: No
Bisected commit-id:


Attachments
example code to test shared locks (791 bytes, text/x-csrc)
2018-12-12 08:58 UTC, omgbebebe
Details

Description omgbebebe 2018-12-12 08:58:46 UTC
Created attachment 279959 [details]
example code to test shared locks

While resolving a bug with locks on samba shares we found a strange behavior. When a file locked by one node and we trying to lock it from another node it fail with errno 5 (EIO) but in that case errno must be set to (EACCES | EAGAIN). This isn't happening when we try to lock file second time on same node. In this case it returns EACCES as expected. Also this issue not reproduces when we use SMB1 protocol (vers=1.0 in mount options).

Further investigation showed that the mapping from status_to_posix_error is different for SMB1 and SMB2+ implementations. For SMB1 mapping is [NT_STATUS_LOCK_NOT_GRANTED to ERRlock](https://github.com/torvalds/linux/blob/master/fs/cifs/netmisc.c#L322) to [-EACCES](https://github.com/torvalds/linux/blob/master/fs/cifs/netmisc.c#L66)
but for SMB2+ mapping is [STATUS_LOCK_NOT_GRANTED to -EIO](https://github.com/torvalds/linux/blob/master/fs/cifs/smb2maperror.c#L383)

Quick changes in SMB2+ mapping from EIO to EACCES has fixed our issue.

Is it bug in mappings in SMB2/3 implementation or it is a new behaviour that we should take in account in future?

PS. I attached example code to test shared locks. To reproduce our case it should be executed on same shared file twice.

Expected behavior:

```
nodeA $ ./share_lock /mnt/server_public/file_samba
File locked successfully.
Press any key to exit...

# in another console
nodeA $ ./share_lock /mnt/server_public/file_samba
fcntl error: 13, Permission denied
```

Wrong behavior:

```
nodeA $ ./share_lock /mnt/server_public/file_samba
File locked successfully.
Press any key to exit...

# on second node
nodeB $ ./share_lock /mnt/server_public/file_samba
fcntl error: 5, Input/output error
```
Comment 1 Ronnie Sahlberg 2019-02-07 22:19:03 UTC
This has been fixed upstream so this bug should be closed.

commit 9a596f5b39593414c0ec80f71b94a226286f084e
Author: Georgy A Bystrenin <gkot@altlinux.org>
Date:   Fri Dec 21 00:11:42 2018 -0600

    CIFS: Fix error mapping for SMB2_LOCK command which caused OFD lock problem
    
    While resolving a bug with locks on samba shares found a strange behavior.
    When a file locked by one node and we trying to lock it from another node
    it fail with errno 5 (EIO) but in that case errno must be set to
    (EACCES | EAGAIN).
    This isn't happening when we try to lock file second time on same node.
    In this case it returns EACCES as expected.
    Also this issue not reproduces when we use SMB1 protocol (vers=1.0 in
    mount options).
    
    Further investigation showed that the mapping from status_to_posix_error
    is different for SMB1 and SMB2+ implementations.
    For SMB1 mapping is [NT_STATUS_LOCK_NOT_GRANTED to ERRlock]
    (See fs/cifs/netmisc.c line 66)
    but for SMB2+ mapping is [STATUS_LOCK_NOT_GRANTED to -EIO]
    (see fs/cifs/smb2maperror.c line 383)
    
    Quick changes in SMB2+ mapping from EIO to EACCES has fixed issue.
    
    BUG: https://bugzilla.kernel.org/show_bug.cgi?id=201971
    
    Signed-off-by: Georgy A Bystrenin <gkot@altlinux.org>
    Reviewed-by: Pavel Shilovsky <pshilov@microsoft.com>
    CC: Stable <stable@vger.kernel.org>
    Signed-off-by: Steve French <stfrench@microsoft.com>

Note You need to log in before you can comment on or make changes to this bug.