cifs: Remove intermediate object of failed create reparse call

BugLink: https://bugs.launchpad.net/bugs/2097301

[ Upstream commit c9432ad5e32f066875b1bf95939c363bc46d6a45 ]

If CREATE was successful but SMB2_OP_SET_REPARSE failed then remove the
intermediate object created by CREATE. Otherwise empty object stay on the
server when reparse call failed.

This ensures that if the creating of special files is unsupported by the
server then no empty file stay on the server as a result of unsupported
operation.

Fixes: 102466f303 ("smb: client: allow creating special files via reparse points")
Signed-off-by: Pali Rohár <pali@kernel.org>
Acked-by: Paulo Alcantara (Red Hat) <pc@manguebit.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Manuel Diewald <manuel.diewald@canonical.com>
Signed-off-by: Koichiro Den <koichiro.den@canonical.com>
This commit is contained in:
Pali Rohár
2024-09-30 22:25:10 +02:00
committed by Mehmet Basaran
parent f928619016
commit d858143d17
+22 -2
View File
@@ -980,10 +980,13 @@ struct inode *smb2_get_reparse_inode(struct cifs_open_info_data *data,
struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
struct cifsFileInfo *cfile;
struct inode *new = NULL;
int out_buftype[4] = {};
struct kvec out_iov[4] = {};
struct kvec in_iov[2];
int cmds[2];
int da, co, cd;
int rc;
int i;
da = SYNCHRONIZE | DELETE |
FILE_READ_ATTRIBUTES |
@@ -1000,7 +1003,7 @@ struct inode *smb2_get_reparse_inode(struct cifs_open_info_data *data,
cifs_get_writable_path(tcon, full_path, FIND_WR_ANY, &cfile);
rc = smb2_compound_op(xid, tcon, cifs_sb, full_path,
da, cd, co, ACL_NO_MODE, in_iov,
cmds, 2, cfile, NULL, NULL);
cmds, 2, cfile, out_iov, out_buftype);
if (!rc) {
rc = smb311_posix_get_inode_info(&new, full_path,
data, sb, xid);
@@ -1010,12 +1013,29 @@ struct inode *smb2_get_reparse_inode(struct cifs_open_info_data *data,
cifs_get_writable_path(tcon, full_path, FIND_WR_ANY, &cfile);
rc = smb2_compound_op(xid, tcon, cifs_sb, full_path,
da, cd, co, ACL_NO_MODE, in_iov,
cmds, 2, cfile, NULL, NULL);
cmds, 2, cfile, out_iov, out_buftype);
if (!rc) {
rc = cifs_get_inode_info(&new, full_path,
data, sb, xid, NULL);
}
}
/*
* If CREATE was successful but SMB2_OP_SET_REPARSE failed then
* remove the intermediate object created by CREATE. Otherwise
* empty object stay on the server when reparse call failed.
*/
if (rc &&
out_iov[0].iov_base != NULL && out_buftype[0] != CIFS_NO_BUFFER &&
((struct smb2_hdr *)out_iov[0].iov_base)->Status == STATUS_SUCCESS &&
(out_iov[1].iov_base == NULL || out_buftype[1] == CIFS_NO_BUFFER ||
((struct smb2_hdr *)out_iov[1].iov_base)->Status != STATUS_SUCCESS))
smb2_unlink(xid, tcon, full_path, cifs_sb);
for (i = 0; i < ARRAY_SIZE(out_buftype); i++)
free_rsp_buf(out_buftype[i], out_iov[i].iov_base);
return rc ? ERR_PTR(rc) : new;
}