Skip to content

Commit 69a4e06

Browse files
Paulo Alcantarasmfrench
authored andcommitted
smb: client: reduce stack usage in cifs_try_adding_channels()
Clang warns about exceeded stack frame size fs/smb/client/sess.c:160:5: warning: stack frame size (1368) exceeds limit (1024) in 'cifs_try_adding_channels' [-Wframe-larger-than] It turns out that cifs_ses_add_channel() got inlined into cifs_try_adding_channels() which had a stack-allocated variable @ctx of 624 bytes in size. Fix this by making it heap-allocated. Reported-by: kernel test robot <[email protected]> Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/ Signed-off-by: Paulo Alcantara (SUSE) <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent a18280e commit 69a4e06

File tree

1 file changed

+41
-27
lines changed

1 file changed

+41
-27
lines changed

fs/smb/client/sess.c

Lines changed: 41 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -360,11 +360,11 @@ cifs_ses_add_channel(struct cifs_sb_info *cifs_sb, struct cifs_ses *ses,
360360
{
361361
struct TCP_Server_Info *chan_server;
362362
struct cifs_chan *chan;
363-
struct smb3_fs_context ctx = {NULL};
363+
struct smb3_fs_context *ctx;
364364
static const char unc_fmt[] = "\\%s\\foo";
365-
char unc[sizeof(unc_fmt)+SERVER_NAME_LEN_WITH_NULL] = {0};
366365
struct sockaddr_in *ipv4 = (struct sockaddr_in *)&iface->sockaddr;
367366
struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *)&iface->sockaddr;
367+
size_t len;
368368
int rc;
369369
unsigned int xid = get_xid();
370370

@@ -388,54 +388,64 @@ cifs_ses_add_channel(struct cifs_sb_info *cifs_sb, struct cifs_ses *ses,
388388
* the session and server without caring about memory
389389
* management.
390390
*/
391+
ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
392+
if (!ctx) {
393+
rc = -ENOMEM;
394+
goto out_free_xid;
395+
}
391396

392397
/* Always make new connection for now (TODO?) */
393-
ctx.nosharesock = true;
398+
ctx->nosharesock = true;
394399

395400
/* Auth */
396-
ctx.domainauto = ses->domainAuto;
397-
ctx.domainname = ses->domainName;
401+
ctx->domainauto = ses->domainAuto;
402+
ctx->domainname = ses->domainName;
398403

399404
/* no hostname for extra channels */
400-
ctx.server_hostname = "";
405+
ctx->server_hostname = "";
401406

402-
ctx.username = ses->user_name;
403-
ctx.password = ses->password;
404-
ctx.sectype = ses->sectype;
405-
ctx.sign = ses->sign;
407+
ctx->username = ses->user_name;
408+
ctx->password = ses->password;
409+
ctx->sectype = ses->sectype;
410+
ctx->sign = ses->sign;
406411

407412
/* UNC and paths */
408413
/* XXX: Use ses->server->hostname? */
409-
sprintf(unc, unc_fmt, ses->ip_addr);
410-
ctx.UNC = unc;
411-
ctx.prepath = "";
414+
len = sizeof(unc_fmt) + SERVER_NAME_LEN_WITH_NULL;
415+
ctx->UNC = kzalloc(len, GFP_KERNEL);
416+
if (!ctx->UNC) {
417+
rc = -ENOMEM;
418+
goto out_free_ctx;
419+
}
420+
scnprintf(ctx->UNC, len, unc_fmt, ses->ip_addr);
421+
ctx->prepath = "";
412422

413423
/* Reuse same version as master connection */
414-
ctx.vals = ses->server->vals;
415-
ctx.ops = ses->server->ops;
424+
ctx->vals = ses->server->vals;
425+
ctx->ops = ses->server->ops;
416426

417-
ctx.noblocksnd = ses->server->noblocksnd;
418-
ctx.noautotune = ses->server->noautotune;
419-
ctx.sockopt_tcp_nodelay = ses->server->tcp_nodelay;
420-
ctx.echo_interval = ses->server->echo_interval / HZ;
421-
ctx.max_credits = ses->server->max_credits;
427+
ctx->noblocksnd = ses->server->noblocksnd;
428+
ctx->noautotune = ses->server->noautotune;
429+
ctx->sockopt_tcp_nodelay = ses->server->tcp_nodelay;
430+
ctx->echo_interval = ses->server->echo_interval / HZ;
431+
ctx->max_credits = ses->server->max_credits;
422432

423433
/*
424434
* This will be used for encoding/decoding user/domain/pw
425435
* during sess setup auth.
426436
*/
427-
ctx.local_nls = cifs_sb->local_nls;
437+
ctx->local_nls = cifs_sb->local_nls;
428438

429439
/* Use RDMA if possible */
430-
ctx.rdma = iface->rdma_capable;
431-
memcpy(&ctx.dstaddr, &iface->sockaddr, sizeof(struct sockaddr_storage));
440+
ctx->rdma = iface->rdma_capable;
441+
memcpy(&ctx->dstaddr, &iface->sockaddr, sizeof(ctx->dstaddr));
432442

433443
/* reuse master con client guid */
434-
memcpy(&ctx.client_guid, ses->server->client_guid,
435-
SMB2_CLIENT_GUID_SIZE);
436-
ctx.use_client_guid = true;
444+
memcpy(&ctx->client_guid, ses->server->client_guid,
445+
sizeof(ctx->client_guid));
446+
ctx->use_client_guid = true;
437447

438-
chan_server = cifs_get_tcp_session(&ctx, ses->server);
448+
chan_server = cifs_get_tcp_session(ctx, ses->server);
439449

440450
spin_lock(&ses->chan_lock);
441451
chan = &ses->chans[ses->chan_count];
@@ -497,6 +507,10 @@ cifs_ses_add_channel(struct cifs_sb_info *cifs_sb, struct cifs_ses *ses,
497507
cifs_put_tcp_session(chan->server, 0);
498508
}
499509

510+
kfree(ctx->UNC);
511+
out_free_ctx:
512+
kfree(ctx);
513+
out_free_xid:
500514
free_xid(xid);
501515
return rc;
502516
}

0 commit comments

Comments
 (0)