Skip to content

Commit ff7d975

Browse files
Olga KornievskaiaJ. Bruce Fields
authored andcommitted
nfsd: use static memory for callback program and stats
There's no need to dynamically allocate this memory, and doing so may create the possibility of races on shutdown of the rpc client. (We've witnessed it only after adding rpcsec_gss support to the server, after which the rpc code can send destroys calls that expect to still be able to access the rpc_stats structure after it has been destroyed.) Such races are in theory possible if the module containing this "static" memory is removed very quickly after an rpc client is destroyed, but we haven't seen that happen. Signed-off-by: J. Bruce Fields <bfields@citi.umich.edu>
1 parent 8774282 commit ff7d975

1 file changed

Lines changed: 17 additions & 11 deletions

File tree

‎fs/nfsd/nfs4callback.c‎

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,21 @@ static struct rpc_version * nfs_cb_version[] = {
344344
&nfs_cb_version4,
345345
};
346346

347+
static struct rpc_program cb_program;
348+
349+
static struct rpc_stat cb_stats = {
350+
.program = &cb_program
351+
};
352+
353+
#define NFS4_CALLBACK 0x40000000
354+
static struct rpc_program cb_program = {
355+
.name = "nfs4_cb",
356+
.number = NFS4_CALLBACK,
357+
.nrvers = ARRAY_SIZE(nfs_cb_version),
358+
.version = nfs_cb_version,
359+
.stats = &cb_stats,
360+
};
361+
347362
/* Reference counting, callback cleanup, etc., all look racy as heck.
348363
* And why is cb_set an atomic? */
349364

@@ -358,13 +373,12 @@ static int do_probe_callback(void *data)
358373
.to_maxval = (NFSD_LEASE_TIME/2) * HZ,
359374
.to_exponential = 1,
360375
};
361-
struct rpc_program * program = &cb->cb_program;
362376
struct rpc_create_args args = {
363377
.protocol = IPPROTO_TCP,
364378
.address = (struct sockaddr *)&addr,
365379
.addrsize = sizeof(addr),
366380
.timeout = &timeparms,
367-
.program = program,
381+
.program = &cb_program,
368382
.version = nfs_cb_version[1]->number,
369383
.authflavor = RPC_AUTH_UNIX, /* XXX: need AUTH_GSS... */
370384
.flags = (RPC_CLNT_CREATE_NOPING),
@@ -382,16 +396,8 @@ static int do_probe_callback(void *data)
382396
addr.sin_port = htons(cb->cb_port);
383397
addr.sin_addr.s_addr = htonl(cb->cb_addr);
384398

385-
/* Initialize rpc_program */
386-
program->name = "nfs4_cb";
387-
program->number = cb->cb_prog;
388-
program->nrvers = ARRAY_SIZE(nfs_cb_version);
389-
program->version = nfs_cb_version;
390-
program->stats = &cb->cb_stat;
391-
392399
/* Initialize rpc_stat */
393-
memset(program->stats, 0, sizeof(cb->cb_stat));
394-
program->stats->program = program;
400+
memset(args.program->stats, 0, sizeof(struct rpc_stat));
395401

396402
/* Create RPC client */
397403
client = rpc_create(&args);

0 commit comments

Comments
 (0)