Skip to content

Commit f4e5ceb

Browse files
Paulo AlcantaraSteve French
authored andcommitted
smb: client: reduce stack usage in smb2_set_ea()
Clang warns about exceeded stack frame size fs/smb/client/smb2ops.c:1080:1: warning: stack frame size (1432) exceeds limit (1024) in 'smb2_set_ea' [-Wframe-larger-than] Fix this by allocating a structure that will hold most of the large variables. Signed-off-by: Paulo Alcantara (SUSE) <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent 933148a commit f4e5ceb

File tree

3 files changed

+37
-47
lines changed

3 files changed

+37
-47
lines changed

fs/smb/client/cifsglob.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2214,4 +2214,17 @@ static inline void cifs_sg_set_buf(struct sg_table *sgtable,
22142214
}
22152215
}
22162216

2217+
struct smb2_compound_vars {
2218+
struct cifs_open_parms oparms;
2219+
struct kvec rsp_iov[3];
2220+
struct smb_rqst rqst[3];
2221+
struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
2222+
struct kvec qi_iov;
2223+
struct kvec io_iov[SMB2_IOCTL_IOV_SIZE];
2224+
struct kvec si_iov[SMB2_SET_INFO_IOV_SIZE];
2225+
struct kvec close_iov;
2226+
struct smb2_file_rename_info rename_info;
2227+
struct smb2_file_link_info link_info;
2228+
};
2229+
22172230
#endif /* _CIFS_GLOB_H */

fs/smb/client/smb2inode.c

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,6 @@ free_set_inf_compound(struct smb_rqst *rqst)
3535
SMB2_close_free(&rqst[2]);
3636
}
3737

38-
39-
struct cop_vars {
40-
struct cifs_open_parms oparms;
41-
struct kvec rsp_iov[3];
42-
struct smb_rqst rqst[3];
43-
struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
44-
struct kvec qi_iov[1];
45-
struct kvec si_iov[SMB2_SET_INFO_IOV_SIZE];
46-
struct kvec close_iov[1];
47-
struct smb2_file_rename_info rename_info;
48-
struct smb2_file_link_info link_info;
49-
};
50-
5138
/*
5239
* note: If cfile is passed, the reference to it is dropped here.
5340
* So make sure that you do not reuse cfile after return from this func.
@@ -63,7 +50,7 @@ static int smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon,
6350
__u8 **extbuf, size_t *extbuflen,
6451
struct kvec *out_iov, int *out_buftype)
6552
{
66-
struct cop_vars *vars = NULL;
53+
struct smb2_compound_vars *vars = NULL;
6754
struct kvec *rsp_iov;
6855
struct smb_rqst *rqst;
6956
int rc;
@@ -134,7 +121,7 @@ static int smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon,
134121
/* Operation */
135122
switch (command) {
136123
case SMB2_OP_QUERY_INFO:
137-
rqst[num_rqst].rq_iov = &vars->qi_iov[0];
124+
rqst[num_rqst].rq_iov = &vars->qi_iov;
138125
rqst[num_rqst].rq_nvec = 1;
139126

140127
if (cfile)
@@ -168,7 +155,7 @@ static int smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon,
168155
full_path);
169156
break;
170157
case SMB2_OP_POSIX_QUERY_INFO:
171-
rqst[num_rqst].rq_iov = &vars->qi_iov[0];
158+
rqst[num_rqst].rq_iov = &vars->qi_iov;
172159
rqst[num_rqst].rq_nvec = 1;
173160

174161
if (cfile)
@@ -376,7 +363,7 @@ static int smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon,
376363
goto after_close;
377364
/* Close */
378365
flags |= CIFS_CP_CREATE_CLOSE_OP;
379-
rqst[num_rqst].rq_iov = &vars->close_iov[0];
366+
rqst[num_rqst].rq_iov = &vars->close_iov;
380367
rqst[num_rqst].rq_nvec = 1;
381368
rc = SMB2_close_init(tcon, server,
382369
&rqst[num_rqst], COMPOUND_FID,

fs/smb/client/smb2ops.c

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,31 +1075,28 @@ smb2_query_eas(const unsigned int xid, struct cifs_tcon *tcon,
10751075
return rc;
10761076
}
10771077

1078-
10791078
static int
10801079
smb2_set_ea(const unsigned int xid, struct cifs_tcon *tcon,
10811080
const char *path, const char *ea_name, const void *ea_value,
10821081
const __u16 ea_value_len, const struct nls_table *nls_codepage,
10831082
struct cifs_sb_info *cifs_sb)
10841083
{
1084+
struct smb2_compound_vars *vars;
10851085
struct cifs_ses *ses = tcon->ses;
10861086
struct TCP_Server_Info *server = cifs_pick_channel(ses);
1087+
struct smb_rqst *rqst;
1088+
struct kvec *rsp_iov;
10871089
__le16 *utf16_path = NULL;
10881090
int ea_name_len = strlen(ea_name);
10891091
int flags = CIFS_CP_CREATE_CLOSE_OP;
10901092
int len;
1091-
struct smb_rqst rqst[3];
10921093
int resp_buftype[3];
1093-
struct kvec rsp_iov[3];
1094-
struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
10951094
struct cifs_open_parms oparms;
10961095
__u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
10971096
struct cifs_fid fid;
1098-
struct kvec si_iov[SMB2_SET_INFO_IOV_SIZE];
10991097
unsigned int size[1];
11001098
void *data[1];
11011099
struct smb2_file_full_ea_info *ea = NULL;
1102-
struct kvec close_iov[1];
11031100
struct smb2_query_info_rsp *rsp;
11041101
int rc, used_len = 0;
11051102

@@ -1113,9 +1110,14 @@ smb2_set_ea(const unsigned int xid, struct cifs_tcon *tcon,
11131110
if (!utf16_path)
11141111
return -ENOMEM;
11151112

1116-
memset(rqst, 0, sizeof(rqst));
11171113
resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
1118-
memset(rsp_iov, 0, sizeof(rsp_iov));
1114+
vars = kzalloc(sizeof(*vars), GFP_KERNEL);
1115+
if (!vars) {
1116+
rc = -ENOMEM;
1117+
goto out_free_path;
1118+
}
1119+
rqst = vars->rqst;
1120+
rsp_iov = vars->rsp_iov;
11191121

11201122
if (ses->server->ops->query_all_EAs) {
11211123
if (!ea_value) {
@@ -1160,8 +1162,7 @@ smb2_set_ea(const unsigned int xid, struct cifs_tcon *tcon,
11601162
}
11611163

11621164
/* Open */
1163-
memset(&open_iov, 0, sizeof(open_iov));
1164-
rqst[0].rq_iov = open_iov;
1165+
rqst[0].rq_iov = vars->open_iov;
11651166
rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
11661167

11671168
oparms = (struct cifs_open_parms) {
@@ -1181,8 +1182,7 @@ smb2_set_ea(const unsigned int xid, struct cifs_tcon *tcon,
11811182

11821183

11831184
/* Set Info */
1184-
memset(&si_iov, 0, sizeof(si_iov));
1185-
rqst[1].rq_iov = si_iov;
1185+
rqst[1].rq_iov = vars->si_iov;
11861186
rqst[1].rq_nvec = 1;
11871187

11881188
len = sizeof(*ea) + ea_name_len + ea_value_len + 1;
@@ -1210,10 +1210,8 @@ smb2_set_ea(const unsigned int xid, struct cifs_tcon *tcon,
12101210
smb2_set_next_command(tcon, &rqst[1]);
12111211
smb2_set_related(&rqst[1]);
12121212

1213-
12141213
/* Close */
1215-
memset(&close_iov, 0, sizeof(close_iov));
1216-
rqst[2].rq_iov = close_iov;
1214+
rqst[2].rq_iov = &vars->close_iov;
12171215
rqst[2].rq_nvec = 1;
12181216
rc = SMB2_close_init(tcon, server,
12191217
&rqst[2], COMPOUND_FID, COMPOUND_FID, false);
@@ -1228,13 +1226,15 @@ smb2_set_ea(const unsigned int xid, struct cifs_tcon *tcon,
12281226

12291227
sea_exit:
12301228
kfree(ea);
1231-
kfree(utf16_path);
12321229
SMB2_open_free(&rqst[0]);
12331230
SMB2_set_info_free(&rqst[1]);
12341231
SMB2_close_free(&rqst[2]);
12351232
free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
12361233
free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
12371234
free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
1235+
kfree(vars);
1236+
out_free_path:
1237+
kfree(utf16_path);
12381238
return rc;
12391239
}
12401240
#endif
@@ -1445,24 +1445,14 @@ SMB2_request_res_key(const unsigned int xid, struct cifs_tcon *tcon,
14451445
return rc;
14461446
}
14471447

1448-
struct iqi_vars {
1449-
struct smb_rqst rqst[3];
1450-
struct kvec rsp_iov[3];
1451-
struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
1452-
struct kvec qi_iov[1];
1453-
struct kvec io_iov[SMB2_IOCTL_IOV_SIZE];
1454-
struct kvec si_iov[SMB2_SET_INFO_IOV_SIZE];
1455-
struct kvec close_iov[1];
1456-
};
1457-
14581448
static int
14591449
smb2_ioctl_query_info(const unsigned int xid,
14601450
struct cifs_tcon *tcon,
14611451
struct cifs_sb_info *cifs_sb,
14621452
__le16 *path, int is_dir,
14631453
unsigned long p)
14641454
{
1465-
struct iqi_vars *vars;
1455+
struct smb2_compound_vars *vars;
14661456
struct smb_rqst *rqst;
14671457
struct kvec *rsp_iov;
14681458
struct cifs_ses *ses = tcon->ses;
@@ -1580,7 +1570,7 @@ smb2_ioctl_query_info(const unsigned int xid,
15801570
rc = -EINVAL;
15811571
goto free_open_req;
15821572
}
1583-
rqst[1].rq_iov = &vars->si_iov[0];
1573+
rqst[1].rq_iov = vars->si_iov;
15841574
rqst[1].rq_nvec = 1;
15851575

15861576
/* MS-FSCC 2.4.13 FileEndOfFileInformation */
@@ -1592,7 +1582,7 @@ smb2_ioctl_query_info(const unsigned int xid,
15921582
SMB2_O_INFO_FILE, 0, data, size);
15931583
free_req1_func = SMB2_set_info_free;
15941584
} else if (qi.flags == PASSTHRU_QUERY_INFO) {
1595-
rqst[1].rq_iov = &vars->qi_iov[0];
1585+
rqst[1].rq_iov = &vars->qi_iov;
15961586
rqst[1].rq_nvec = 1;
15971587

15981588
rc = SMB2_query_info_init(tcon, server,
@@ -1614,7 +1604,7 @@ smb2_ioctl_query_info(const unsigned int xid,
16141604
smb2_set_related(&rqst[1]);
16151605

16161606
/* Close */
1617-
rqst[2].rq_iov = &vars->close_iov[0];
1607+
rqst[2].rq_iov = &vars->close_iov;
16181608
rqst[2].rq_nvec = 1;
16191609

16201610
rc = SMB2_close_init(tcon, server,

0 commit comments

Comments
 (0)