Commit 7312ee64 authored by Sachin Prabhu's avatar Sachin Prabhu Committed by Greg Kroah-Hartman

cifs: Check for existing directory when opening file with O_CREAT

commit 8d9535b6 upstream.

When opening a file with O_CREAT flag, check to see if the file opened
is an existing directory.

This prevents the directory from being opened which subsequently causes
a crash when the close function for directories cifs_closedir() is called
which frees up the file->private_data memory while the file is still
listed on the open file list for the tcon.
Signed-off-by: default avatarSachin Prabhu <sprabhu@redhat.com>
Signed-off-by: default avatarSteve French <smfrench@gmail.com>
Reported-by: default avatarXiaoli Feng <xifeng@redhat.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 7c02304b
...@@ -245,6 +245,13 @@ cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned int xid, ...@@ -245,6 +245,13 @@ cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned int xid,
goto cifs_create_get_file_info; goto cifs_create_get_file_info;
} }
if (S_ISDIR(newinode->i_mode)) {
CIFSSMBClose(xid, tcon, fid->netfid);
iput(newinode);
rc = -EISDIR;
goto out;
}
if (!S_ISREG(newinode->i_mode)) { if (!S_ISREG(newinode->i_mode)) {
/* /*
* The server may allow us to open things like * The server may allow us to open things like
...@@ -415,10 +422,14 @@ cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned int xid, ...@@ -415,10 +422,14 @@ cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned int xid,
if (rc != 0) { if (rc != 0) {
cifs_dbg(FYI, "Create worked, get_inode_info failed rc = %d\n", cifs_dbg(FYI, "Create worked, get_inode_info failed rc = %d\n",
rc); rc);
if (server->ops->close) goto out_err;
server->ops->close(xid, tcon, fid);
goto out;
} }
if (S_ISDIR(newinode->i_mode)) {
rc = -EISDIR;
goto out_err;
}
d_drop(direntry); d_drop(direntry);
d_add(direntry, newinode); d_add(direntry, newinode);
...@@ -426,6 +437,13 @@ cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned int xid, ...@@ -426,6 +437,13 @@ cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned int xid,
kfree(buf); kfree(buf);
kfree(full_path); kfree(full_path);
return rc; return rc;
out_err:
if (server->ops->close)
server->ops->close(xid, tcon, fid);
if (newinode)
iput(newinode);
goto out;
} }
int int
......
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