Skip to content

Commit

Permalink
SUNRPC: Set rq_auth_stat in the pg_authenticate() callout
Browse files Browse the repository at this point in the history
In a few moments, rq_auth_stat will need to be explicitly set to
rpc_auth_ok before execution gets to the dispatcher.

svc_authenticate() already sets it, but it often gets reset to
rpc_autherr_badcred right after that call, even when authentication
is successful. Let's ensure that the pg_authenticate callout and
svc_set_client() set it properly in every case.

Signed-off-by: Chuck Lever <[email protected]>
Signed-off-by: Anna Schumaker <[email protected]>
  • Loading branch information
chucklever authored and amschuma-ntap committed Aug 10, 2021
1 parent 438623a commit 5c2465d
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 4 deletions.
2 changes: 2 additions & 0 deletions fs/lockd/svc.c
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,7 @@ static int lockd_authenticate(struct svc_rqst *rqstp)
switch (rqstp->rq_authop->flavour) {
case RPC_AUTH_NULL:
case RPC_AUTH_UNIX:
rqstp->rq_auth_stat = rpc_auth_ok;
if (rqstp->rq_proc == 0)
return SVC_OK;
if (is_callback(rqstp->rq_proc)) {
Expand All @@ -659,6 +660,7 @@ static int lockd_authenticate(struct svc_rqst *rqstp)
}
return svc_set_client(rqstp);
}
rqstp->rq_auth_stat = rpc_autherr_badcred;
return SVC_DENIED;
}

Expand Down
4 changes: 4 additions & 0 deletions fs/nfs/callback.c
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,8 @@ check_gss_callback_principal(struct nfs_client *clp, struct svc_rqst *rqstp)
*/
static int nfs_callback_authenticate(struct svc_rqst *rqstp)
{
rqstp->rq_auth_stat = rpc_autherr_badcred;

switch (rqstp->rq_authop->flavour) {
case RPC_AUTH_NULL:
if (rqstp->rq_proc != CB_NULL)
Expand All @@ -439,6 +441,8 @@ static int nfs_callback_authenticate(struct svc_rqst *rqstp)
if (svc_is_backchannel(rqstp))
return SVC_DENIED;
}

rqstp->rq_auth_stat = rpc_auth_ok;
return SVC_OK;
}

Expand Down
4 changes: 4 additions & 0 deletions net/sunrpc/auth_gss/svcauth_gss.c
Original file line number Diff line number Diff line change
Expand Up @@ -1038,6 +1038,8 @@ svcauth_gss_set_client(struct svc_rqst *rqstp)
struct rpc_gss_wire_cred *gc = &svcdata->clcred;
int stat;

rqstp->rq_auth_stat = rpc_autherr_badcred;

/*
* A gss export can be specified either by:
* export *(sec=krb5,rw)
Expand All @@ -1053,6 +1055,8 @@ svcauth_gss_set_client(struct svc_rqst *rqstp)
stat = svcauth_unix_set_client(rqstp);
if (stat == SVC_DROP || stat == SVC_CLOSE)
return stat;

rqstp->rq_auth_stat = rpc_auth_ok;
return SVC_OK;
}

Expand Down
4 changes: 1 addition & 3 deletions net/sunrpc/svc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1328,10 +1328,8 @@ svc_process_common(struct svc_rqst *rqstp, struct kvec *argv, struct kvec *resv)
*/
auth_res = svc_authenticate(rqstp);
/* Also give the program a chance to reject this call: */
if (auth_res == SVC_OK && progp) {
rqstp->rq_auth_stat = rpc_autherr_badcred;
if (auth_res == SVC_OK && progp)
auth_res = progp->pg_authenticate(rqstp);
}
if (auth_res != SVC_OK)
trace_svc_authenticate(rqstp, auth_res);
switch (auth_res) {
Expand Down
6 changes: 5 additions & 1 deletion net/sunrpc/svcauth_unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -681,8 +681,9 @@ svcauth_unix_set_client(struct svc_rqst *rqstp)

rqstp->rq_client = NULL;
if (rqstp->rq_proc == 0)
return SVC_OK;
goto out;

rqstp->rq_auth_stat = rpc_autherr_badcred;
ipm = ip_map_cached_get(xprt);
if (ipm == NULL)
ipm = __ip_map_lookup(sn->ip_map_cache, rqstp->rq_server->sv_program->pg_class,
Expand Down Expand Up @@ -719,6 +720,9 @@ svcauth_unix_set_client(struct svc_rqst *rqstp)
put_group_info(cred->cr_group_info);
cred->cr_group_info = gi;
}

out:
rqstp->rq_auth_stat = rpc_auth_ok;
return SVC_OK;
}

Expand Down

0 comments on commit 5c2465d

Please sign in to comment.