Skip to content

Commit 85db6b7

Browse files
Ronnie Sahlbergsmfrench
authored andcommitted
cifs: make sure we do not overflow the max EA buffer size
RHBZ: 1752437 Before we add a new EA we should check that this will not overflow the maximum buffer we have available to read the EAs back. Otherwise we can get into a situation where the EAs are so big that we can not read them back to the client and thus we can not list EAs anymore or delete them. Signed-off-by: Ronnie Sahlberg <[email protected]> Signed-off-by: Steve French <[email protected]> CC: Stable <[email protected]>
1 parent 2c6251a commit 85db6b7

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

fs/cifs/smb2ops.c

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1116,7 +1116,8 @@ smb2_set_ea(const unsigned int xid, struct cifs_tcon *tcon,
11161116
void *data[1];
11171117
struct smb2_file_full_ea_info *ea = NULL;
11181118
struct kvec close_iov[1];
1119-
int rc;
1119+
struct smb2_query_info_rsp *rsp;
1120+
int rc, used_len = 0;
11201121

11211122
if (smb3_encryption_required(tcon))
11221123
flags |= CIFS_TRANSFORM_REQ;
@@ -1139,6 +1140,38 @@ smb2_set_ea(const unsigned int xid, struct cifs_tcon *tcon,
11391140
cifs_sb);
11401141
if (rc == -ENODATA)
11411142
goto sea_exit;
1143+
} else {
1144+
/* If we are adding a attribute we should first check
1145+
* if there will be enough space available to store
1146+
* the new EA. If not we should not add it since we
1147+
* would not be able to even read the EAs back.
1148+
*/
1149+
rc = smb2_query_info_compound(xid, tcon, utf16_path,
1150+
FILE_READ_EA,
1151+
FILE_FULL_EA_INFORMATION,
1152+
SMB2_O_INFO_FILE,
1153+
CIFSMaxBufSize -
1154+
MAX_SMB2_CREATE_RESPONSE_SIZE -
1155+
MAX_SMB2_CLOSE_RESPONSE_SIZE,
1156+
&rsp_iov[1], &resp_buftype[1], cifs_sb);
1157+
if (rc == 0) {
1158+
rsp = (struct smb2_query_info_rsp *)rsp_iov[1].iov_base;
1159+
used_len = le32_to_cpu(rsp->OutputBufferLength);
1160+
}
1161+
free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
1162+
resp_buftype[1] = CIFS_NO_BUFFER;
1163+
memset(&rsp_iov[1], 0, sizeof(rsp_iov[1]));
1164+
rc = 0;
1165+
1166+
/* Use a fudge factor of 256 bytes in case we collide
1167+
* with a different set_EAs command.
1168+
*/
1169+
if(CIFSMaxBufSize - MAX_SMB2_CREATE_RESPONSE_SIZE -
1170+
MAX_SMB2_CLOSE_RESPONSE_SIZE - 256 <
1171+
used_len + ea_name_len + ea_value_len + 1) {
1172+
rc = -ENOSPC;
1173+
goto sea_exit;
1174+
}
11421175
}
11431176
}
11441177

0 commit comments

Comments
 (0)