Skip to content

Commit 1598a01

Browse files
meetakshi253gregkh
authored andcommitted
cifs: fixes for get_inode_info
[ Upstream commit fc20c52 ] Fix potential memory leaks, add error checking, remove unnecessary initialisation of status_file_deleted and do not use cifs_iget() to get inode in reparse_info_to_fattr since fattrs may not be fully set. Fixes: ffceb76 ("smb: client: do not defer close open handles to deleted files") Reported-by: Paulo Alcantara <[email protected]> Signed-off-by: Meetakshi Setiya <[email protected]> Signed-off-by: Steve French <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 91cdeb0 commit 1598a01

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

fs/smb/client/file.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,6 @@ struct cifsFileInfo *cifs_new_fileinfo(struct cifs_fid *fid, struct file *file,
501501
cfile->uid = current_fsuid();
502502
cfile->dentry = dget(dentry);
503503
cfile->f_flags = file->f_flags;
504-
cfile->status_file_deleted = false;
505504
cfile->invalidHandle = false;
506505
cfile->deferred_close_scheduled = false;
507506
cfile->tlink = cifs_get_tlink(tlink);

fs/smb/client/inode.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -820,8 +820,10 @@ cifs_get_file_info(struct file *filp)
820820
void *page = alloc_dentry_path();
821821
const unsigned char *path;
822822

823-
if (!server->ops->query_file_info)
823+
if (!server->ops->query_file_info) {
824+
free_dentry_path(page);
824825
return -ENOSYS;
826+
}
825827

826828
xid = get_xid();
827829
rc = server->ops->query_file_info(xid, tcon, cfile, &data);
@@ -835,8 +837,8 @@ cifs_get_file_info(struct file *filp)
835837
}
836838
path = build_path_from_dentry(dentry, page);
837839
if (IS_ERR(path)) {
838-
free_dentry_path(page);
839-
return PTR_ERR(path);
840+
rc = PTR_ERR(path);
841+
goto cgfi_exit;
840842
}
841843
cifs_open_info_to_fattr(&fattr, &data, inode->i_sb);
842844
if (fattr.cf_flags & CIFS_FATTR_DELETE_PENDING)
@@ -1009,7 +1011,6 @@ static int reparse_info_to_fattr(struct cifs_open_info_data *data,
10091011
struct kvec rsp_iov, *iov = NULL;
10101012
int rsp_buftype = CIFS_NO_BUFFER;
10111013
u32 tag = data->reparse.tag;
1012-
struct inode *inode = NULL;
10131014
int rc = 0;
10141015

10151016
if (!tag && server->ops->query_reparse_point) {
@@ -1049,12 +1050,8 @@ static int reparse_info_to_fattr(struct cifs_open_info_data *data,
10491050

10501051
if (tcon->posix_extensions)
10511052
smb311_posix_info_to_fattr(fattr, data, sb);
1052-
else {
1053+
else
10531054
cifs_open_info_to_fattr(fattr, data, sb);
1054-
inode = cifs_iget(sb, fattr);
1055-
if (inode && fattr->cf_flags & CIFS_FATTR_DELETE_PENDING)
1056-
cifs_mark_open_handles_for_deleted_file(inode, full_path);
1057-
}
10581055
out:
10591056
fattr->cf_cifstag = data->reparse.tag;
10601057
free_rsp_buf(rsp_buftype, rsp_iov.iov_base);
@@ -1109,9 +1106,9 @@ static int cifs_get_fattr(struct cifs_open_info_data *data,
11091106
full_path, fattr);
11101107
} else {
11111108
cifs_open_info_to_fattr(fattr, data, sb);
1112-
if (fattr->cf_flags & CIFS_FATTR_DELETE_PENDING)
1113-
cifs_mark_open_handles_for_deleted_file(*inode, full_path);
11141109
}
1110+
if (!rc && fattr->cf_flags & CIFS_FATTR_DELETE_PENDING)
1111+
cifs_mark_open_handles_for_deleted_file(*inode, full_path);
11151112
break;
11161113
case -EREMOTE:
11171114
/* DFS link, no metadata available on this server */
@@ -1340,6 +1337,8 @@ int smb311_posix_get_inode_info(struct inode **inode,
13401337
goto out;
13411338

13421339
rc = update_inode_info(sb, &fattr, inode);
1340+
if (!rc && fattr.cf_flags & CIFS_FATTR_DELETE_PENDING)
1341+
cifs_mark_open_handles_for_deleted_file(*inode, full_path);
13431342
out:
13441343
kfree(fattr.cf_symlink_target);
13451344
return rc;
@@ -1503,6 +1502,9 @@ struct inode *cifs_root_iget(struct super_block *sb)
15031502
goto out;
15041503
}
15051504

1505+
if (!rc && fattr.cf_flags & CIFS_FATTR_DELETE_PENDING)
1506+
cifs_mark_open_handles_for_deleted_file(inode, path);
1507+
15061508
if (rc && tcon->pipe) {
15071509
cifs_dbg(FYI, "ipc connection - fake read inode\n");
15081510
spin_lock(&inode->i_lock);

0 commit comments

Comments
 (0)