Skip to content

Commit cc248d4

Browse files
author
J. Bruce Fields
committed
svcrpc: don't byte-swap sk_reclen in place
Byte-swapping in place is always a little dubious. Let's instead define this field to always be big-endian, and do the swapping on demand where we need it. Signed-off-by: J. Bruce Fields <bfields@redhat.com>
1 parent 6c1e82a commit cc248d4

2 files changed

Lines changed: 22 additions & 16 deletions

File tree

‎include/linux/sunrpc/svcsock.h‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,21 @@ struct svc_sock {
2626
void (*sk_owspace)(struct sock *);
2727

2828
/* private TCP part */
29-
u32 sk_reclen; /* length of record */
29+
__be32 sk_reclen; /* length of record */
3030
u32 sk_tcplen; /* current read length */
3131
struct page * sk_pages[RPCSVC_MAXPAGES]; /* received data */
3232
};
3333

34+
static inline u32 svc_sock_reclen(struct svc_sock *svsk)
35+
{
36+
return ntohl(svsk->sk_reclen) & RPC_FRAGMENT_SIZE_MASK;
37+
}
38+
39+
static inline u32 svc_sock_final_rec(struct svc_sock *svsk)
40+
{
41+
return ntohl(svsk->sk_reclen) & RPC_LAST_STREAM_FRAGMENT;
42+
}
43+
3444
/*
3545
* Function prototypes.
3646
*/

‎net/sunrpc/svcsock.c‎

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -950,8 +950,7 @@ static int svc_tcp_recv_record(struct svc_sock *svsk, struct svc_rqst *rqstp)
950950
return -EAGAIN;
951951
}
952952

953-
svsk->sk_reclen = ntohl(svsk->sk_reclen);
954-
if (!(svsk->sk_reclen & RPC_LAST_STREAM_FRAGMENT)) {
953+
if (!(svc_sock_final_rec(svsk))) {
955954
/* FIXME: technically, a record can be fragmented,
956955
* and non-terminal fragments will not have the top
957956
* bit set in the fragment length header.
@@ -961,21 +960,18 @@ static int svc_tcp_recv_record(struct svc_sock *svsk, struct svc_rqst *rqstp)
961960
goto err_delete;
962961
}
963962

964-
svsk->sk_reclen &= RPC_FRAGMENT_SIZE_MASK;
965-
dprintk("svc: TCP record, %d bytes\n", svsk->sk_reclen);
966-
if (svsk->sk_reclen > serv->sv_max_mesg) {
963+
dprintk("svc: TCP record, %d bytes\n", svc_sock_reclen(svsk));
964+
if (svc_sock_reclen(svsk) > serv->sv_max_mesg) {
967965
net_notice_ratelimited("RPC: fragment too large: 0x%08lx\n",
968-
(unsigned long)svsk->sk_reclen);
966+
(unsigned long)svc_sock_reclen(svsk));
969967
goto err_delete;
970968
}
971969
}
972970

973-
if (svsk->sk_reclen < 8)
971+
if (svc_sock_reclen(svsk) < 8)
974972
goto err_delete; /* client is nuts. */
975973

976-
len = svsk->sk_reclen;
977-
978-
return len;
974+
return svc_sock_reclen(svsk);
979975
error:
980976
dprintk("RPC: TCP recv_record got %d\n", len);
981977
return len;
@@ -1019,7 +1015,7 @@ static int receive_cb_reply(struct svc_sock *svsk, struct svc_rqst *rqstp)
10191015
if (dst->iov_len < src->iov_len)
10201016
return -EAGAIN; /* whatever; just giving up. */
10211017
memcpy(dst->iov_base, src->iov_base, src->iov_len);
1022-
xprt_complete_rqst(req->rq_task, svsk->sk_reclen);
1018+
xprt_complete_rqst(req->rq_task, rqstp->rq_arg.len);
10231019
rqstp->rq_arg.len = 0;
10241020
return 0;
10251021
}
@@ -1064,12 +1060,12 @@ static int svc_tcp_recvfrom(struct svc_rqst *rqstp)
10641060
goto error;
10651061

10661062
base = svc_tcp_restore_pages(svsk, rqstp);
1067-
want = svsk->sk_reclen - base;
1063+
want = svc_sock_reclen(svsk) - base;
10681064

10691065
vec = rqstp->rq_vec;
10701066

10711067
pnum = copy_pages_to_kvecs(&vec[0], &rqstp->rq_pages[0],
1072-
svsk->sk_reclen);
1068+
svc_sock_reclen(svsk));
10731069

10741070
rqstp->rq_respages = &rqstp->rq_pages[pnum];
10751071

@@ -1082,11 +1078,11 @@ static int svc_tcp_recvfrom(struct svc_rqst *rqstp)
10821078
if (len < 0 && len != -EAGAIN)
10831079
goto err_other;
10841080
dprintk("svc: incomplete TCP record (%d of %d)\n",
1085-
svsk->sk_tcplen, svsk->sk_reclen);
1081+
svsk->sk_tcplen, svc_sock_reclen(svsk));
10861082
goto err_noclose;
10871083
}
10881084

1089-
rqstp->rq_arg.len = svsk->sk_reclen;
1085+
rqstp->rq_arg.len = svc_sock_reclen(svsk);
10901086
rqstp->rq_arg.page_base = 0;
10911087
if (rqstp->rq_arg.len <= rqstp->rq_arg.head[0].iov_len) {
10921088
rqstp->rq_arg.head[0].iov_len = rqstp->rq_arg.len;

0 commit comments

Comments
 (0)