Skip to content

Commit 5866efa

Browse files
chuckleverJ. Bruce Fields
authored andcommitted
SUNRPC: Fix svcauth_gss_proxy_init()
gss_read_proxy_verf() assumes things about the XDR buffer containing the RPC Call that are not true for buffers generated by svc_rdma_recv(). RDMA's buffers look more like what the upper layer generates for sending: head is a kmalloc'd buffer; it does not point to a page whose contents are contiguous with the first page in the buffers' page array. The result is that ACCEPT_SEC_CONTEXT via RPC/RDMA has stopped working on Linux NFS servers that use gssproxy. This does not affect clients that use only TCP to send their ACCEPT_SEC_CONTEXT operation (that's all Linux clients). Other clients, like Solaris NFS clients, send ACCEPT_SEC_CONTEXT on the same transport as they send all other NFS operations. Such clients can send ACCEPT_SEC_CONTEXT via RPC/RDMA. I thought I had found every direct reference in the server RPC code to the rqstp->rq_pages field. Bug found at the 2019 Westford NFS bake-a-thon. Fixes: 3316f06 ("svcrdma: Persistently allocate and DMA- ... ") Signed-off-by: Chuck Lever <[email protected]> Tested-by: Bill Baker <[email protected]> Reviewed-by: Simo Sorce <[email protected]> Signed-off-by: J. Bruce Fields <[email protected]>
1 parent ff27e9f commit 5866efa

File tree

1 file changed

+63
-21
lines changed

1 file changed

+63
-21
lines changed

net/sunrpc/auth_gss/svcauth_gss.c

Lines changed: 63 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,24 +1078,32 @@ gss_read_verf(struct rpc_gss_wire_cred *gc,
10781078
return 0;
10791079
}
10801080

1081-
/* Ok this is really heavily depending on a set of semantics in
1082-
* how rqstp is set up by svc_recv and pages laid down by the
1083-
* server when reading a request. We are basically guaranteed that
1084-
* the token lays all down linearly across a set of pages, starting
1085-
* at iov_base in rq_arg.head[0] which happens to be the first of a
1086-
* set of pages stored in rq_pages[].
1087-
* rq_arg.head[0].iov_base will provide us the page_base to pass
1088-
* to the upcall.
1089-
*/
1090-
static inline int
1091-
gss_read_proxy_verf(struct svc_rqst *rqstp,
1092-
struct rpc_gss_wire_cred *gc, __be32 *authp,
1093-
struct xdr_netobj *in_handle,
1094-
struct gssp_in_token *in_token)
1081+
static void gss_free_in_token_pages(struct gssp_in_token *in_token)
10951082
{
1096-
struct kvec *argv = &rqstp->rq_arg.head[0];
10971083
u32 inlen;
1098-
int res;
1084+
int i;
1085+
1086+
i = 0;
1087+
inlen = in_token->page_len;
1088+
while (inlen) {
1089+
if (in_token->pages[i])
1090+
put_page(in_token->pages[i]);
1091+
inlen -= inlen > PAGE_SIZE ? PAGE_SIZE : inlen;
1092+
}
1093+
1094+
kfree(in_token->pages);
1095+
in_token->pages = NULL;
1096+
}
1097+
1098+
static int gss_read_proxy_verf(struct svc_rqst *rqstp,
1099+
struct rpc_gss_wire_cred *gc, __be32 *authp,
1100+
struct xdr_netobj *in_handle,
1101+
struct gssp_in_token *in_token)
1102+
{
1103+
struct kvec *argv = &rqstp->rq_arg.head[0];
1104+
unsigned int page_base, length;
1105+
int pages, i, res;
1106+
size_t inlen;
10991107

11001108
res = gss_read_common_verf(gc, argv, authp, in_handle);
11011109
if (res)
@@ -1105,10 +1113,36 @@ gss_read_proxy_verf(struct svc_rqst *rqstp,
11051113
if (inlen > (argv->iov_len + rqstp->rq_arg.page_len))
11061114
return SVC_DENIED;
11071115

1108-
in_token->pages = rqstp->rq_pages;
1109-
in_token->page_base = (ulong)argv->iov_base & ~PAGE_MASK;
1116+
pages = DIV_ROUND_UP(inlen, PAGE_SIZE);
1117+
in_token->pages = kcalloc(pages, sizeof(struct page *), GFP_KERNEL);
1118+
if (!in_token->pages)
1119+
return SVC_DENIED;
1120+
in_token->page_base = 0;
11101121
in_token->page_len = inlen;
1122+
for (i = 0; i < pages; i++) {
1123+
in_token->pages[i] = alloc_page(GFP_KERNEL);
1124+
if (!in_token->pages[i]) {
1125+
gss_free_in_token_pages(in_token);
1126+
return SVC_DENIED;
1127+
}
1128+
}
11111129

1130+
length = min_t(unsigned int, inlen, argv->iov_len);
1131+
memcpy(page_address(in_token->pages[0]), argv->iov_base, length);
1132+
inlen -= length;
1133+
1134+
i = 1;
1135+
page_base = rqstp->rq_arg.page_base;
1136+
while (inlen) {
1137+
length = min_t(unsigned int, inlen, PAGE_SIZE);
1138+
memcpy(page_address(in_token->pages[i]),
1139+
page_address(rqstp->rq_arg.pages[i]) + page_base,
1140+
length);
1141+
1142+
inlen -= length;
1143+
page_base = 0;
1144+
i++;
1145+
}
11121146
return 0;
11131147
}
11141148

@@ -1282,8 +1316,11 @@ static int svcauth_gss_proxy_init(struct svc_rqst *rqstp,
12821316
break;
12831317
case GSS_S_COMPLETE:
12841318
status = gss_proxy_save_rsc(sn->rsc_cache, &ud, &handle);
1285-
if (status)
1319+
if (status) {
1320+
pr_info("%s: gss_proxy_save_rsc failed (%d)\n",
1321+
__func__, status);
12861322
goto out;
1323+
}
12871324
cli_handle.data = (u8 *)&handle;
12881325
cli_handle.len = sizeof(handle);
12891326
break;
@@ -1294,15 +1331,20 @@ static int svcauth_gss_proxy_init(struct svc_rqst *rqstp,
12941331

12951332
/* Got an answer to the upcall; use it: */
12961333
if (gss_write_init_verf(sn->rsc_cache, rqstp,
1297-
&cli_handle, &ud.major_status))
1334+
&cli_handle, &ud.major_status)) {
1335+
pr_info("%s: gss_write_init_verf failed\n", __func__);
12981336
goto out;
1337+
}
12991338
if (gss_write_resv(resv, PAGE_SIZE,
13001339
&cli_handle, &ud.out_token,
1301-
ud.major_status, ud.minor_status))
1340+
ud.major_status, ud.minor_status)) {
1341+
pr_info("%s: gss_write_resv failed\n", __func__);
13021342
goto out;
1343+
}
13031344

13041345
ret = SVC_COMPLETE;
13051346
out:
1347+
gss_free_in_token_pages(&ud.in_token);
13061348
gssp_free_upcall_data(&ud);
13071349
return ret;
13081350
}

0 commit comments

Comments
 (0)