Bug 4443 - cifs client does not reset permissions when a previously read-only file is no longer read-only
cifs client does not reset permissions when a previously read-only file is no...
Product: CifsVFS
Classification: Unclassified
Component: kernel fs
Other Linux
: P3 normal
: ---
Assigned To: Steve French
Depends on:
  Show dependency treegraph
Reported: 2007-03-09 14:15 UTC by Jeff Layton
Modified: 2007-03-10 02:02 UTC (History)
1 user (show)

See Also:

patch to enable any mode bits allowed by mnt_file_mode if ATTR_READONLY isn't set (1.39 KB, patch)
2007-03-09 14:20 UTC, Jeff Layton
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jeff Layton 2007-03-09 14:15:16 UTC
In both cifs_get_inode_info() and fill_in_inode(), the cifs client checks for the presence of the ATTR_READONLY bit, and turns off the "w" bits in the mode if it's present. Unfortunately, if it does *not* detect this bit then it doesn't reenable any sort of write permissions on the file.

To reproduce this:

1) use CIFS to mount a samba share that does not have unix extensions enabled (making sure that file_mode allows write bits)
2) On the server, create a file in this directory, make sure at least one write bit is set in the mode
3) stat this file on the client
4) on the server remove the write bits from the mode (chmod 0444 testfile)
5) stat the file on the client, write bits should be removed from the mode
6) add the write bits back (chmod 0666 testfile)
7) stat the file again on the client, the write bits are not reenabled

There is virtually no way to get write permissions back on the inode short of renaming the file on the server, stat'ing the original filename on the client (and letting that fail), and then moving the file back.

I'll be posting a patch shortly to address this...
Comment 1 Jeff Layton 2007-03-09 14:20:52 UTC
Created attachment 2322 [details]
patch to enable any mode bits allowed by mnt_file_mode if ATTR_READONLY isn't set

I'm not certain that this is the right logic here, but it seems reasonable:

If unix extensions were not negotiated, ATTR_READONLY is not set on the file, and no write bits are set in the mode, then we assume that the ATTR_READONLY flag was previously on for this file. We then turn on any permission bits allowed by the mnt_file_mode.

If this isn't a safe assumption (I've really not delved too deeply into the CIFS code, so this might not be), then another option might be to track ATTR_READONLY in some cifs-private area of the inode...

This patch was actually done by Alan Tyson at HP, but he asked that I push this upstream for him. I'll also post this to the linux-cifs-client mailing list...
Comment 2 Jeff Layton 2007-03-09 14:29:44 UTC
It's, of course, also possible reproduce this with a windows server, but rather than changing the file mode on the server, you'll right click on the file in the explorer and check and uncheck the 'Read Only' checkbox.
Comment 3 Jeff Layton 2007-03-09 14:50:12 UTC
Patch posted to linux-cifs-client@samba.org and LKML:

Subject: [PATCH] CIFS: reset file mode when CIFS client notices that ATTR_READONLY is no longer set
Comment 4 Steve French 2007-03-10 02:02:35 UTC
Merged into cifs-2.6.git tree (so it should reach mm soon)

Will push to mainline after a bit in -mm tree

If you consider it a serious problem, we can try to merge it to mainline faster