Commit f42ec909 authored by Steve French's avatar Steve French Committed by Steve French

fix problem with inode revalidation and cache page invalidation

parent d7203748
......@@ -26,5 +26,6 @@ Test case and Bug Report contributors
-------------------------------------
Thanks to those in the community who have submitted detailed bug reports
and debug of problems they have found: Jochen Dolze, David Blaine,
Rene Scharfe, Martin Josefsson, Alexander Wild and others.
Rene Scharfe, Martin Josefsson, Alexander Wild, Anthony Liguori,
Urban Widmark, Massimiliano Ferrero, Howard Owen and others.
......@@ -63,7 +63,19 @@ domain to the proper network user. The mount.cifs mount helper can be
trivially built from Samba 3.0 or later source e.g. by executing:
gcc samba/source/client/mount.cifs.c -o mount.cifs
Note that when the mount.cifs utility is run suid (allowing user mounts),
in order to reduce risks, the "nosuid" mount flag is passed in on mount to
disallow execution of an suid program mounted on the remote target.
When mount is executed as root, nosuid is not passed in by default,
and execution of suid programs on the remote target would be enabled
by default. This can be changed, as with nfs and other filesystems,
by simply specifying "nosuid" among the mount options. For user mounts
though to be able to pass the suid flag to mount requires rebuilding
mount.cifs with the following flag:
gcc samba/source/client/mount.cifs.c -DCIFS_ALLOW_USR_SUID -o mount.cifs
There is a corresponding manual page for cifs mounting in the Samba 3.0 and
later source tree in docs/manpages/mount.cifs.8
......@@ -173,6 +185,15 @@ A partial list of the supported mount options follows:
or password or domain. This option is less important
when the cifs mount helper cifs.mount (version 1.1 or later)
is used.
nosuid Do not allow remote executables with the suid bit
program to be executed. This is only meaningful for mounts
to servers such as Samba which support the CIFS Unix Extensions.
If you do not trust the servers in your network (your mount
targets) it is recommended that you specify this option for
greater security.
suid Allow remote files on this mountpoint with suid enabled to
be executed (default for mounts when executed as root,
nosuid is default for user mounts).
Misc /proc/fs/cifs Flags and Debug Info
=======================================
......
......@@ -244,6 +244,8 @@ cifs_demultiplex_thread(struct TCP_Server_Info *server)
}
pdu_length = 4 + ntohl(smb_buffer->smb_buf_length);
/* Ony read pdu_length after below checks for too short (due
to e.g. int overflow) and too long ie beyond end of buf */
cFYI(1, ("Peek length rcvd: %d with smb length: %d", length, pdu_length));
temp = (char *) smb_buffer;
......@@ -264,8 +266,8 @@ cifs_demultiplex_thread(struct TCP_Server_Info *server)
} else if (temp[0] != (char) 0) {
cERROR(1,
("Unknown RFC 1001 frame received not 0x00 nor 0x85"));
cifs_dump_mem(" Received Data is: ", temp, length);
("Unknown RFC 1001 frame not 0x00 nor 0x85"));
cifs_dump_mem(" Received Data: ", temp, length);
cifs_reconnect(server);
csocket = server->ssocket;
continue;
......@@ -293,8 +295,9 @@ cifs_demultiplex_thread(struct TCP_Server_Info *server)
length = 0;
iov.iov_base = smb_buffer;
iov.iov_len = pdu_length;
for (total_read = 0; total_read < pdu_length; total_read += length) {
/* Should improve check for buffer overflow with bad pdu_length */
for (total_read = 0;
total_read < pdu_length;
total_read += length) {
length = sock_recvmsg(csocket, &smb_msg,
pdu_length - total_read, 0);
if (length == 0) {
......
......@@ -375,7 +375,6 @@ cifs_close(struct inode *inode, struct file *file)
info on this inode, much less write behind and read ahead */
CIFS_I(inode)->clientCanCacheRead = FALSE;
CIFS_I(inode)->clientCanCacheAll = FALSE;
invalidate_remote_inode(inode);
}
if((rc ==0) && CIFS_I(inode)->write_behind_rc)
rc = CIFS_I(inode)->write_behind_rc;
......
......@@ -560,6 +560,20 @@ cifs_revalidate(struct dentry *direntry)
char *full_path;
struct cifs_sb_info *cifs_sb;
struct cifsInodeInfo *cifsInode;
loff_t local_size;
struct timespec local_mtime;
if(direntry->d_inode == NULL)
return -ENOENT;
cifsInode = CIFS_I(direntry->d_inode);
if(cifsInode == NULL)
return -ENOENT;
/* no sense revalidating inode info on file that only we can write */
if(CIFS_I(direntry->d_inode)->clientCanCacheRead)
return rc;
xid = GetXid();
......@@ -572,10 +586,6 @@ cifs_revalidate(struct dentry *direntry)
direntry->d_inode->i_count.counter, direntry,
direntry->d_time, jiffies));
cifsInode = CIFS_I(direntry->d_inode);
/* BB add check - do not need to revalidate oplocked files */
if (time_before(jiffies, cifsInode->time + HZ) && lookupCacheEnabled) {
if((S_ISREG(direntry->d_inode->i_mode) == 0) ||
(direntry->d_inode->i_nlink == 1)) {
......@@ -587,7 +597,13 @@ cifs_revalidate(struct dentry *direntry)
cFYI(1,("Have to revalidate file due to hardlinks"));
}
}
/* save mtime and size */
local_mtime = direntry->d_inode->i_mtime;
local_size = direntry->d_inode->i_size;
/* BB we need to write out dirty pages here if any before getting possibly
stale time from server */
if (cifs_sb->tcon->ses->capabilities & CAP_UNIX) {
rc = cifs_get_inode_info_unix(&direntry->d_inode, full_path,
direntry->d_sb);
......@@ -607,8 +623,18 @@ cifs_revalidate(struct dentry *direntry)
}
/* should we remap certain errors, access denied?, to zero */
/* BB if not oplocked, invalidate inode pages if mtime has changed */
/* if not oplocked, we invalidate inode pages if mtime
or file size has changed on server */
if(timespec_equal(&local_mtime,&direntry->d_inode->i_mtime) &&
(local_size == direntry->d_inode->i_size)) {
cFYI(1,("inode unchanged on server"));
} else {
/* file has changed on server */
cFYI(1,("Server copy changed, invalidating remote inode "));
invalidate_remote_inode(direntry->d_inode);
}
if (full_path)
kfree(full_path);
FreeXid(xid);
......
......@@ -318,8 +318,8 @@ checkSMB(struct smb_hdr *smb, __u16 mid, int length)
("Entering checkSMB with Length: %x, smb_buf_length: %x ",
length, ntohl(smb->smb_buf_length)));
if (((unsigned int)length < 2 + sizeof (struct smb_hdr))
|| (4 + ntohl(smb->smb_buf_length) >
CIFS_MAX_MSGSIZE + MAX_CIFS_HDR_SIZE)) {
|| (ntohl(smb->smb_buf_length) >
CIFS_MAX_MSGSIZE + MAX_CIFS_HDR_SIZE - 4)) {
if ((unsigned int)length < 2 + sizeof (struct smb_hdr)) {
cERROR(1, ("Length less than 2 + sizeof smb_hdr "));
if (((unsigned int)length >= sizeof (struct smb_hdr) - 1)
......@@ -327,8 +327,8 @@ checkSMB(struct smb_hdr *smb, __u16 mid, int length)
return 0; /* some error cases do not return wct and bcc */
}
if (4 + ntohl(smb->smb_buf_length) >
CIFS_MAX_MSGSIZE + MAX_CIFS_HDR_SIZE)
if (ntohl(smb->smb_buf_length) >
CIFS_MAX_MSGSIZE + MAX_CIFS_HDR_SIZE - 4)
cERROR(1,
("smb_buf_length greater than CIFS_MAX_MSGSIZE ... "));
cERROR(1,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment