History

SUNRPC: Use struct xdr_stream when constructing RPC Call header

Modernize and harden the code path that constructs each RPC Call message.

Chuck Lever committed 7 years ago

Commit e8680a21 parent fe9a2708 files · +266 −181Browse files

Unified · Split

8 files
  1. include/linux/sunrpc/auth.h +10 −5
  2. include/linux/sunrpc/xdr.h +6 −0
  3. include/trace/events/sunrpc.h +29 −0
  4. net/sunrpc/auth.c +38 −18
  5. net/sunrpc/auth_gss/auth_gss.c +93 −98
  6. net/sunrpc/auth_null.c +15 −8
  7. net/sunrpc/auth_unix.c +40 −21
  8. net/sunrpc/clnt.c +35 −31
include/linux/sunrpc/auth.h+10−5
@@ -131,11 +131,12 @@ struct rpc_credops { · 130 unmodified lines
131131 void (*crdestroy)(struct rpc_cred *);
132132
133133 int (*crmatch)(struct auth_cred *, struct rpc_cred *, int);
134− __be32 * (*crmarshal)(struct rpc_task *, __be32 *);
134+ int (*crmarshal)(struct rpc_task *task,
135+ struct xdr_stream *xdr);
135136 int (*crrefresh)(struct rpc_task *);
136137 __be32 * (*crvalidate)(struct rpc_task *, __be32 *);
137− int (*crwrap_req)(struct rpc_task *, kxdreproc_t,
138− void *, __be32 *, void *);
138+ int (*crwrap_req)(struct rpc_task *task,
139+ struct xdr_stream *xdr);
139140 int (*crunwrap_resp)(struct rpc_task *, kxdrdproc_t,
140141 void *, __be32 *, void *);
141142 int (*crkey_timeout)(struct rpc_cred *);
@@ -165,9 +166,13 @@ struct rpc_cred * rpcauth_lookup_credcache(struct rpc_auth *, struct auth_cred * · 23 unmodified lines
165166 void rpcauth_init_cred(struct rpc_cred *, const struct auth_cred *, struct rpc_auth *, const struct rpc_credops *);
166167 struct rpc_cred * rpcauth_lookupcred(struct rpc_auth *, int);
167168 void put_rpccred(struct rpc_cred *);
168−__be32 * rpcauth_marshcred(struct rpc_task *, __be32 *);
169+int rpcauth_marshcred(struct rpc_task *task,
170+ struct xdr_stream *xdr);
169171 __be32 * rpcauth_checkverf(struct rpc_task *, __be32 *);
170−int rpcauth_wrap_req(struct rpc_task *task, kxdreproc_t encode, void *rqstp, __be32 *data, void *obj);
172+int rpcauth_wrap_req_encode(struct rpc_task *task,
173+ struct xdr_stream *xdr);
174+int rpcauth_wrap_req(struct rpc_task *task,
175+ struct xdr_stream *xdr);
171176 int rpcauth_unwrap_resp(struct rpc_task *task, kxdrdproc_t decode, void *rqstp, __be32 *data, void *obj);
172177 bool rpcauth_xmit_need_reencode(struct rpc_task *task);
173178 int rpcauth_refreshcred(struct rpc_task *);
include/linux/sunrpc/xdr.h+6−0
@@ -87,6 +87,12 @@ xdr_buf_init(struct xdr_buf *buf, void *start, size_t len) · 86 unmodified lines
8787 #define xdr_one cpu_to_be32(1)
8888 #define xdr_two cpu_to_be32(2)
8989
90+#define rpc_auth_null cpu_to_be32(RPC_AUTH_NULL)
91+#define rpc_auth_unix cpu_to_be32(RPC_AUTH_UNIX)
92+#define rpc_auth_gss cpu_to_be32(RPC_AUTH_GSS)
93+
94+#define rpc_call cpu_to_be32(RPC_CALL)
95+
9096 #define rpc_success cpu_to_be32(RPC_SUCCESS)
9197 #define rpc_prog_unavail cpu_to_be32(RPC_PROG_UNAVAIL)
9298 #define rpc_prog_mismatch cpu_to_be32(RPC_PROG_MISMATCH)
include/trace/events/sunrpc.h+29−0
@@ -213,6 +213,35 @@ DECLARE_EVENT_CLASS(rpc_task_queued, · 212 unmodified lines
213213 DEFINE_RPC_QUEUED_EVENT(sleep);
214214 DEFINE_RPC_QUEUED_EVENT(wakeup);
215215
216+DECLARE_EVENT_CLASS(rpc_failure,
217+
218+ TP_PROTO(const struct rpc_task *task),
219+
220+ TP_ARGS(task),
221+
222+ TP_STRUCT__entry(
223+ __field(unsigned int, task_id)
224+ __field(unsigned int, client_id)
225+ ),
226+
227+ TP_fast_assign(
228+ __entry->task_id = task->tk_pid;
229+ __entry->client_id = task->tk_client->cl_clid;
230+ ),
231+
232+ TP_printk("task:%u@%u",
233+ __entry->task_id, __entry->client_id)
234+);
235+
236+#define DEFINE_RPC_FAILURE(name) \
237+ DEFINE_EVENT(rpc_failure, rpc_bad_##name, \
238+ TP_PROTO( \
239+ const struct rpc_task *task \
240+ ), \
241+ TP_ARGS(task))
242+
243+DEFINE_RPC_FAILURE(callhdr);
244+
216245 TRACE_EVENT(rpc_stats_latency,
217246
218247 TP_PROTO(
net/sunrpc/auth.c+38−18
@@ -756,12 +756,21 @@ destroy: · 755 unmodified lines
756756 }
757757 EXPORT_SYMBOL_GPL(put_rpccred);
758758
759−__be32 *
760−rpcauth_marshcred(struct rpc_task *task, __be32 *p)
759+/**
760+ * rpcauth_marshcred - Append RPC credential to end of @xdr
761+ * @task: controlling RPC task
762+ * @xdr: xdr_stream containing initial portion of RPC Call header
763+ *
764+ * On success, an appropriate verifier is added to @xdr, @xdr is
765+ * updated to point past the verifier, and zero is returned.
766+ * Otherwise, @xdr is in an undefined state and a negative errno
767+ * is returned.
768+ */
769+int rpcauth_marshcred(struct rpc_task *task, struct xdr_stream *xdr)
761770 {
762− struct rpc_cred *cred = task->tk_rqstp->rq_cred;
771+ const struct rpc_credops *ops = task->tk_rqstp->rq_cred->cr_ops;
763772
764− return cred->cr_ops->crmarshal(task, p);
773+ return ops->crmarshal(task, xdr);
765774 }
766775
767776 __be32 *
@@ -772,26 +781,37 @@ rpcauth_checkverf(struct rpc_task *task, __be32 *p) · 4 unmodified lines
772781 return cred->cr_ops->crvalidate(task, p);
773782 }
774783
775−static void rpcauth_wrap_req_encode(kxdreproc_t encode, struct rpc_rqst *rqstp,
776− __be32 *data, void *obj)
784+/**
785+ * rpcauth_wrap_req_encode - XDR encode the RPC procedure
786+ * @task: controlling RPC task
787+ * @xdr: stream where on-the-wire bytes are to be marshalled
788+ *
789+ * On success, @xdr contains the encoded and wrapped message.
790+ * Otherwise, @xdr is in an undefined state.
791+ */
792+int rpcauth_wrap_req_encode(struct rpc_task *task, struct xdr_stream *xdr)
777793 {
778− struct xdr_stream xdr;
794+ kxdreproc_t encode = task->tk_msg.rpc_proc->p_encode;
779795
780− xdr_init_encode(&xdr, &rqstp->rq_snd_buf, data, rqstp);
781− encode(rqstp, &xdr, obj);
796+ encode(task->tk_rqstp, xdr, task->tk_msg.rpc_argp);
797+ return 0;
782798 }
799+EXPORT_SYMBOL_GPL(rpcauth_wrap_req_encode);
783800
784−int
785−rpcauth_wrap_req(struct rpc_task *task, kxdreproc_t encode, void *rqstp,
786− __be32 *data, void *obj)
801+/**
802+ * rpcauth_wrap_req - XDR encode and wrap the RPC procedure
803+ * @task: controlling RPC task
804+ * @xdr: stream where on-the-wire bytes are to be marshalled
805+ *
806+ * On success, @xdr contains the encoded and wrapped message,
807+ * and zero is returned. Otherwise, @xdr is in an undefined
808+ * state and a negative errno is returned.
809+ */
810+int rpcauth_wrap_req(struct rpc_task *task, struct xdr_stream *xdr)
787811 {
788− struct rpc_cred *cred = task->tk_rqstp->rq_cred;
812+ const struct rpc_credops *ops = task->tk_rqstp->rq_cred->cr_ops;
789813
790− if (cred->cr_ops->crwrap_req)
791− return cred->cr_ops->crwrap_req(task, encode, rqstp, data, obj);
792− /* By default, we encode the arguments normally. */
793− rpcauth_wrap_req_encode(encode, rqstp, data, obj);
794− return 0;
814+ return ops->crwrap_req(task, xdr);
795815 }
796816
797817 static int
net/sunrpc/auth_gss/auth_gss.c+93−98
@@ -1526,18 +1526,20 @@ out: · 1525 unmodified lines
15261526 }
15271527
15281528 /*
1529−* Marshal credentials.
1530−* Maybe we should keep a cached credential for performance reasons.
1531−*/
1532−static __be32 *
1533−gss_marshal(struct rpc_task *task, __be32 *p)
1529+ * Marshal credentials.
1530+ *
1531+ * The expensive part is computing the verifier. We can't cache a
1532+ * pre-computed version of the verifier because the seqno, which
1533+ * is different every time, is included in the MIC.
1534+ */
1535+static int gss_marshal(struct rpc_task *task, struct xdr_stream *xdr)
15341536 {
15351537 struct rpc_rqst *req = task->tk_rqstp;
15361538 struct rpc_cred *cred = req->rq_cred;
15371539 struct gss_cred *gss_cred = container_of(cred, struct gss_cred,
15381540 gc_base);
15391541 struct gss_cl_ctx *ctx = gss_cred_get_ctx(cred);
1540− __be32 *cred_len;
1542+ __be32 *p, *cred_len;
15411543 u32 maj_stat = 0;
15421544 struct xdr_netobj mic;
15431545 struct kvec iov;
@@ -1545,7 +1547,13 @@ gss_marshal(struct rpc_task *task, __be32 *p) · 1 unmodified line
15451547
15461548 dprintk("RPC: %5u %s\n", task->tk_pid, __func__);
15471549
1548− *p++ = htonl(RPC_AUTH_GSS);
1550+ /* Credential */
1551+
1552+ p = xdr_reserve_space(xdr, 7 * sizeof(*p) +
1553+ ctx->gc_wire_ctx.len);
1554+ if (!p)
1555+ goto out_put_ctx;
1556+ *p++ = rpc_auth_gss;
15491557 cred_len = p++;
15501558
15511559 spin_lock(&ctx->gc_seq_lock);
@@ -1554,12 +1562,14 @@ gss_marshal(struct rpc_task *task, __be32 *p) · 2 unmodified lines
15541562 if (req->rq_seqno == MAXSEQ)
15551563 goto out_expired;
15561564
1557− *p++ = htonl((u32) RPC_GSS_VERSION);
1558− *p++ = htonl((u32) ctx->gc_proc);
1559− *p++ = htonl((u32) req->rq_seqno);
1560− *p++ = htonl((u32) gss_cred->gc_service);
1565+ *p++ = cpu_to_be32(RPC_GSS_VERSION);
1566+ *p++ = cpu_to_be32(ctx->gc_proc);
1567+ *p++ = cpu_to_be32(req->rq_seqno);
1568+ *p++ = cpu_to_be32(gss_cred->gc_service);
15611569 p = xdr_encode_netobj(p, &ctx->gc_wire_ctx);
1562− *cred_len = htonl((p - (cred_len + 1)) << 2);
1570+ *cred_len = cpu_to_be32((p - (cred_len + 1)) << 2);
1571+
1572+ /* Verifier */
15631573
15641574 /* We compute the checksum for the verifier over the xdr-encoded bytes
15651575 * starting with the xid and ending at the end of the credential: */
@@ -1567,27 +1577,27 @@ gss_marshal(struct rpc_task *task, __be32 *p) · 1 unmodified line
15671577 iov.iov_len = (u8 *)p - (u8 *)iov.iov_base;
15681578 xdr_buf_from_iov(&iov, &verf_buf);
15691579
1570− /* set verifier flavor*/
1571− *p++ = htonl(RPC_AUTH_GSS);
1572−
1580+ p = xdr_reserve_space(xdr, sizeof(*p));
1581+ if (!p)
1582+ goto out_put_ctx;
1583+ *p++ = rpc_auth_gss;
15731584 mic.data = (u8 *)(p + 1);
15741585 maj_stat = gss_get_mic(ctx->gc_gss_ctx, &verf_buf, &mic);
1575− if (maj_stat == GSS_S_CONTEXT_EXPIRED) {
1586+ if (maj_stat == GSS_S_CONTEXT_EXPIRED)
15761587 goto out_expired;
1577− } else if (maj_stat != 0) {
1578− pr_warn("gss_marshal: gss_get_mic FAILED (%d)\n", maj_stat);
1579− task->tk_status = -EIO;
1588+ else if (maj_stat != 0)
1589+ goto out_put_ctx;
1590+ if (xdr_stream_encode_opaque_inline(xdr, (void **)&p, mic.len) < 0)
15801591 goto out_put_ctx;
1581− }
1582− p = xdr_encode_opaque(p, NULL, mic.len);
15831592 gss_put_ctx(ctx);
1584− return p;
1593+ return 0;
15851594 out_expired:
1595+ gss_put_ctx(ctx);
15861596 clear_bit(RPCAUTH_CRED_UPTODATE, &cred->cr_flags);
1587− task->tk_status = -EKEYEXPIRED;
1597+ return -EKEYEXPIRED;
15881598 out_put_ctx:
15891599 gss_put_ctx(ctx);
1590− return NULL;
1600+ return -EMSGSIZE;
15911601 }
15921602
15931603 static int gss_renew_cred(struct rpc_task *task)
@@ -1716,61 +1726,45 @@ out_bad: · 122 unmodified lines
17161726 return ret;
17171727 }
17181728
1719−static void gss_wrap_req_encode(kxdreproc_t encode, struct rpc_rqst *rqstp,
1720− __be32 *p, void *obj)
1721−{
1722− struct xdr_stream xdr;
1723−
1724− xdr_init_encode(&xdr, &rqstp->rq_snd_buf, p, rqstp);
1725− encode(rqstp, &xdr, obj);
1726−}
1727−
1728−static inline int
1729−gss_wrap_req_integ(struct rpc_cred *cred, struct gss_cl_ctx *ctx,
1730− kxdreproc_t encode, struct rpc_rqst *rqstp,
1731− __be32 *p, void *obj)
1729+static int gss_wrap_req_integ(struct rpc_cred *cred, struct gss_cl_ctx *ctx,
1730+ struct rpc_task *task, struct xdr_stream *xdr)
17321731 {
1733− struct xdr_buf *snd_buf = &rqstp->rq_snd_buf;
1734− struct xdr_buf integ_buf;
1735− __be32 *integ_len = NULL;
1732+ struct rpc_rqst *rqstp = task->tk_rqstp;
1733+ struct xdr_buf integ_buf, *snd_buf = &rqstp->rq_snd_buf;
17361734 struct xdr_netobj mic;
1737− u32 offset;
1738− __be32 *q;
1739− struct kvec *iov;
1740− u32 maj_stat = 0;
1741− int status = -EIO;
1735+ __be32 *p, *integ_len;
1736+ u32 offset, maj_stat;
17421737
1738+ p = xdr_reserve_space(xdr, 2 * sizeof(*p));
1739+ if (!p)
1740+ goto wrap_failed;
17431741 integ_len = p++;
1744− offset = (u8 *)p - (u8 *)snd_buf->head[0].iov_base;
1745− *p++ = htonl(rqstp->rq_seqno);
1742+ *p = cpu_to_be32(rqstp->rq_seqno);
17461743
1747− gss_wrap_req_encode(encode, rqstp, p, obj);
1744+ if (rpcauth_wrap_req_encode(task, xdr))
1745+ goto wrap_failed;
17481746
1747+ offset = (u8 *)p - (u8 *)snd_buf->head[0].iov_base;
17491748 if (xdr_buf_subsegment(snd_buf, &integ_buf,
17501749 offset, snd_buf->len - offset))
1751− return status;
1752− *integ_len = htonl(integ_buf.len);
1750+ goto wrap_failed;
1751+ *integ_len = cpu_to_be32(integ_buf.len);
17531752
1754− /* guess whether we're in the head or the tail: */
1755− if (snd_buf->page_len || snd_buf->tail[0].iov_len)
1756− iov = snd_buf->tail;
1757− else
1758− iov = snd_buf->head;
1759− p = iov->iov_base + iov->iov_len;
1753+ p = xdr_reserve_space(xdr, 0);
1754+ if (!p)
1755+ goto wrap_failed;
17601756 mic.data = (u8 *)(p + 1);
1761−
17621757 maj_stat = gss_get_mic(ctx->gc_gss_ctx, &integ_buf, &mic);
1763− status = -EIO; /* XXX? */
17641758 if (maj_stat == GSS_S_CONTEXT_EXPIRED)
17651759 clear_bit(RPCAUTH_CRED_UPTODATE, &cred->cr_flags);
17661760 else if (maj_stat)
1767− return status;
1768− q = xdr_encode_opaque(p, NULL, mic.len);
1769−
1770− offset = (u8 *)q - (u8 *)p;
1771− iov->iov_len += offset;
1772− snd_buf->len += offset;
1761+ goto wrap_failed;
1762+ /* Check that the trailing MIC fit in the buffer, after the fact */
1763+ if (xdr_stream_encode_opaque_inline(xdr, (void **)&p, mic.len) < 0)
1764+ goto wrap_failed;
17731765 return 0;
1766+wrap_failed:
1767+ return -EMSGSIZE;
17741768 }
17751769
17761770 static void
@@ -1821,61 +1815,63 @@ out: · 44 unmodified lines
18211815 return -EAGAIN;
18221816 }
18231817
1824−static inline int
1825−gss_wrap_req_priv(struct rpc_cred *cred, struct gss_cl_ctx *ctx,
1826− kxdreproc_t encode, struct rpc_rqst *rqstp,
1827− __be32 *p, void *obj)
1818+static int gss_wrap_req_priv(struct rpc_cred *cred, struct gss_cl_ctx *ctx,
1819+ struct rpc_task *task, struct xdr_stream *xdr)
18281820 {
1821+ struct rpc_rqst *rqstp = task->tk_rqstp;
18291822 struct xdr_buf *snd_buf = &rqstp->rq_snd_buf;
1830− u32 offset;
1831− u32 maj_stat;
1823+ u32 pad, offset, maj_stat;
18321824 int status;
1833− __be32 *opaque_len;
1825+ __be32 *p, *opaque_len;
18341826 struct page **inpages;
18351827 int first;
1836− int pad;
18371828 struct kvec *iov;
1838− char *tmp;
18391829
1830+ status = -EIO;
1831+ p = xdr_reserve_space(xdr, 2 * sizeof(*p));
1832+ if (!p)
1833+ goto wrap_failed;
18401834 opaque_len = p++;
1841− offset = (u8 *)p - (u8 *)snd_buf->head[0].iov_base;
1842− *p++ = htonl(rqstp->rq_seqno);
1835+ *p = cpu_to_be32(rqstp->rq_seqno);
18431836
1844− gss_wrap_req_encode(encode, rqstp, p, obj);
1837+ if (rpcauth_wrap_req_encode(task, xdr))
1838+ goto wrap_failed;
18451839
18461840 status = alloc_enc_pages(rqstp);
1847− if (status)
1848− return status;
1841+ if (unlikely(status))
1842+ goto wrap_failed;
18491843 first = snd_buf->page_base >> PAGE_SHIFT;
18501844 inpages = snd_buf->pages + first;
18511845 snd_buf->pages = rqstp->rq_enc_pages;
18521846 snd_buf->page_base -= first << PAGE_SHIFT;
18531847 /*
1854− * Give the tail its own page, in case we need extra space in the
1855− * head when wrapping:
1848+ * Move the tail into its own page, in case gss_wrap needs
1849+ * more space in the head when wrapping.
18561850 *
1857− * call_allocate() allocates twice the slack space required
1858− * by the authentication flavor to rq_callsize.
1859− * For GSS, slack is GSS_CRED_SLACK.
1851+ * Still... Why can't gss_wrap just slide the tail down?
18601852 */
18611853 if (snd_buf->page_len || snd_buf->tail[0].iov_len) {
1854+ char *tmp;
1855+
18621856 tmp = page_address(rqstp->rq_enc_pages[rqstp->rq_enc_pages_num - 1]);
18631857 memcpy(tmp, snd_buf->tail[0].iov_base, snd_buf->tail[0].iov_len);
18641858 snd_buf->tail[0].iov_base = tmp;
18651859 }
1860+ status = -EIO;
1861+ offset = (u8 *)p - (u8 *)snd_buf->head[0].iov_base;
18661862 maj_stat = gss_wrap(ctx->gc_gss_ctx, offset, snd_buf, inpages);
18671863 /* slack space should prevent this ever happening: */
1868− BUG_ON(snd_buf->len > snd_buf->buflen);
1869− status = -EIO;
1864+ if (unlikely(snd_buf->len > snd_buf->buflen))
1865+ goto wrap_failed;
18701866 /* We're assuming that when GSS_S_CONTEXT_EXPIRED, the encryption was
18711867 * done anyway, so it's safe to put the request on the wire: */
18721868 if (maj_stat == GSS_S_CONTEXT_EXPIRED)
18731869 clear_bit(RPCAUTH_CRED_UPTODATE, &cred->cr_flags);
18741870 else if (maj_stat)
1875− return status;
1871+ goto wrap_failed;
18761872
1877− *opaque_len = htonl(snd_buf->len - offset);
1878− /* guess whether we're in the head or the tail: */
1873+ *opaque_len = cpu_to_be32(snd_buf->len - offset);
1874+ /* guess whether the pad goes into the head or the tail: */
18791875 if (snd_buf->page_len || snd_buf->tail[0].iov_len)
18801876 iov = snd_buf->tail;
18811877 else
@@ -1887,37 +1883,36 @@ gss_wrap_req_priv(struct rpc_cred *cred, struct gss_cl_ctx *ctx, · 5 unmodified lines
18871883 snd_buf->len += pad;
18881884
18891885 return 0;
1886+wrap_failed:
1887+ return status;
18901888 }
18911889
1892−static int
1893−gss_wrap_req(struct rpc_task *task,
1894− kxdreproc_t encode, void *rqstp, __be32 *p, void *obj)
1890+static int gss_wrap_req(struct rpc_task *task, struct xdr_stream *xdr)
18951891 {
18961892 struct rpc_cred *cred = task->tk_rqstp->rq_cred;
18971893 struct gss_cred *gss_cred = container_of(cred, struct gss_cred,
18981894 gc_base);
18991895 struct gss_cl_ctx *ctx = gss_cred_get_ctx(cred);
1900− int status = -EIO;
1896+ int status;
19011897
19021898 dprintk("RPC: %5u %s\n", task->tk_pid, __func__);
1899+ status = -EIO;
19031900 if (ctx->gc_proc != RPC_GSS_PROC_DATA) {
19041901 /* The spec seems a little ambiguous here, but I think that not
19051902 * wrapping context destruction requests makes the most sense.
19061903 */
1907− gss_wrap_req_encode(encode, rqstp, p, obj);
1908− status = 0;
1904+ status = rpcauth_wrap_req_encode(task, xdr);
19091905 goto out;
19101906 }
19111907 switch (gss_cred->gc_service) {
19121908 case RPC_GSS_SVC_NONE:
1913− gss_wrap_req_encode(encode, rqstp, p, obj);
1914− status = 0;
1909+ status = rpcauth_wrap_req_encode(task, xdr);
19151910 break;
19161911 case RPC_GSS_SVC_INTEGRITY:
1917− status = gss_wrap_req_integ(cred, ctx, encode, rqstp, p, obj);
1912+ status = gss_wrap_req_integ(cred, ctx, task, xdr);
19181913 break;
19191914 case RPC_GSS_SVC_PRIVACY:
1920− status = gss_wrap_req_priv(cred, ctx, encode, rqstp, p, obj);
1915+ status = gss_wrap_req_priv(cred, ctx, task, xdr);
19211916 break;
19221917 }
19231918 out:
net/sunrpc/auth_null.c+15−8
@@ -59,15 +59,21 @@ nul_match(struct auth_cred *acred, struct rpc_cred *cred, int taskflags) · 58 unmodified lines
5959 /*
6060 * Marshal credential.
6161 */
62−static __be32 *
63−nul_marshal(struct rpc_task *task, __be32 *p)
62+static int
63+nul_marshal(struct rpc_task *task, struct xdr_stream *xdr)
6464 {
65− *p++ = htonl(RPC_AUTH_NULL);
66− *p++ = 0;
67− *p++ = htonl(RPC_AUTH_NULL);
68− *p++ = 0;
69−
70− return p;
65+ __be32 *p;
66+
67+ p = xdr_reserve_space(xdr, 4 * sizeof(*p));
68+ if (!p)
69+ return -EMSGSIZE;
70+ /* Credential */
71+ *p++ = rpc_auth_null;
72+ *p++ = xdr_zero;
73+ /* Verifier */
74+ *p++ = rpc_auth_null;
75+ *p = xdr_zero;
76+ return 0;
7177 }
7278
7379 /*
@@ -125,6 +131,7 @@ const struct rpc_credops null_credops = { · 51 unmodified lines
125131 .crdestroy = nul_destroy_cred,
126132 .crmatch = nul_match,
127133 .crmarshal = nul_marshal,
134+ .crwrap_req = rpcauth_wrap_req_encode,
128135 .crrefresh = nul_refresh,
129136 .crvalidate = nul_validate,
130137 };
net/sunrpc/auth_unix.c+40−21
@@ -99,37 +99,55 @@ unx_match(struct auth_cred *acred, struct rpc_cred *cred, int flags) · 98 unmodified lines
9999 * Marshal credentials.
100100 * Maybe we should keep a cached credential for performance reasons.
101101 */
102−static __be32 *
103−unx_marshal(struct rpc_task *task, __be32 *p)
102+static int
103+unx_marshal(struct rpc_task *task, struct xdr_stream *xdr)
104104 {
105105 struct rpc_clnt *clnt = task->tk_client;
106106 struct rpc_cred *cred = task->tk_rqstp->rq_cred;
107− __be32 *base, *hold;
107+ __be32 *p, *cred_len, *gidarr_len;
108108 int i;
109109 struct group_info *gi = cred->cr_cred->group_info;
110110
111− *p++ = htonl(RPC_AUTH_UNIX);
112− base = p++;
113− *p++ = htonl(jiffies/HZ);
114−
115− /*
116− * Copy the UTS nodename captured when the client was created.
117− */
118− p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
119−
120− *p++ = htonl((u32) from_kuid(&init_user_ns, cred->cr_cred->fsuid));
121− *p++ = htonl((u32) from_kgid(&init_user_ns, cred->cr_cred->fsgid));
122− hold = p++;
111+ /* Credential */
112+
113+ p = xdr_reserve_space(xdr, 3 * sizeof(*p));
114+ if (!p)
115+ goto marshal_failed;
116+ *p++ = rpc_auth_unix;
117+ cred_len = p++;
118+ *p++ = xdr_zero; /* stamp */
119+ if (xdr_stream_encode_opaque(xdr, clnt->cl_nodename,
120+ clnt->cl_nodelen) < 0)
121+ goto marshal_failed;
122+ p = xdr_reserve_space(xdr, 3 * sizeof(*p));
123+ if (!p)
124+ goto marshal_failed;
125+ *p++ = cpu_to_be32(from_kuid(&init_user_ns, cred->cr_cred->fsuid));
126+ *p++ = cpu_to_be32(from_kgid(&init_user_ns, cred->cr_cred->fsgid));
127+
128+ gidarr_len = p++;
123129 if (gi)
124130 for (i = 0; i < UNX_NGROUPS && i < gi->ngroups; i++)
125− *p++ = htonl((u32) from_kgid(&init_user_ns, gi->gid[i]));
126− *hold = htonl(p - hold - 1); /* gid array length */
127− *base = htonl((p - base - 1) << 2); /* cred length */
131+ *p++ = cpu_to_be32(from_kgid(&init_user_ns,
132+ gi->gid[i]));
133+ *gidarr_len = cpu_to_be32(p - gidarr_len - 1);
134+ *cred_len = cpu_to_be32((p - cred_len - 1) << 2);
135+ p = xdr_reserve_space(xdr, (p - gidarr_len - 1) << 2);
136+ if (!p)
137+ goto marshal_failed;
138+
139+ /* Verifier */
140+
141+ p = xdr_reserve_space(xdr, 2 * sizeof(*p));
142+ if (!p)
143+ goto marshal_failed;
144+ *p++ = rpc_auth_null;
145+ *p = xdr_zero;
128146
129− *p++ = htonl(RPC_AUTH_NULL);
130− *p++ = htonl(0);
147+ return 0;
131148
132− return p;
149+marshal_failed:
150+ return -EMSGSIZE;
133151 }
134152
135153 /*
@@ -202,6 +220,7 @@ const struct rpc_credops unix_credops = { · 66 unmodified lines
202220 .crdestroy = unx_destroy_cred,
203221 .crmatch = unx_match,
204222 .crmarshal = unx_marshal,
223+ .crwrap_req = rpcauth_wrap_req_encode,
205224 .crrefresh = unx_refresh,
206225 .crvalidate = unx_validate,
207226 };
net/sunrpc/clnt.c+35−31
@@ -77,7 +77,8 @@ static void call_timeout(struct rpc_task *task); · 76 unmodified lines
7777 static void call_connect(struct rpc_task *task);
7878 static void call_connect_status(struct rpc_task *task);
7979
80−static __be32 *rpc_encode_header(struct rpc_task *task);
80+static int rpc_encode_header(struct rpc_task *task,
81+ struct xdr_stream *xdr);
8182 static __be32 *rpc_verify_header(struct rpc_task *task);
8283 static int rpc_ping(struct rpc_clnt *clnt);
8384
@@ -1728,10 +1729,7 @@ static void · 1644 unmodified lines
17281729 rpc_xdr_encode(struct rpc_task *task)
17291730 {
17301731 struct rpc_rqst *req = task->tk_rqstp;
1731− kxdreproc_t encode;
1732− __be32 *p;
1733−
1734− dprint_status(task);
1732+ struct xdr_stream xdr;
17351733
17361734 xdr_buf_init(&req->rq_snd_buf,
17371735 req->rq_buffer,
@@ -1740,18 +1738,13 @@ rpc_xdr_encode(struct rpc_task *task) · 2 unmodified lines
17401738 req->rq_rbuffer,
17411739 req->rq_rcvsize);
17421740
1743− p = rpc_encode_header(task);
1744− if (p == NULL)
1741+ req->rq_snd_buf.head[0].iov_len = 0;
1742+ xdr_init_encode(&xdr, &req->rq_snd_buf,
1743+ req->rq_snd_buf.head[0].iov_base, req);
1744+ if (rpc_encode_header(task, &xdr))
17451745 return;
17461746
1747− encode = task->tk_msg.rpc_proc->p_encode;
1748− if (encode == NULL)
1749− return;
1750−
1751− task->tk_status = rpcauth_wrap_req(task, encode, req, p,
1752− task->tk_msg.rpc_argp);
1753− if (task->tk_status == 0)
1754− xprt_request_prepare(req);
1747+ task->tk_status = rpcauth_wrap_req(task, &xdr);
17551748 }
17561749
17571750 /*
@@ -1762,6 +1755,7 @@ call_encode(struct rpc_task *task) · 4 unmodified lines
17621755 {
17631756 if (!rpc_task_need_encode(task))
17641757 goto out;
1758+ dprint_status(task);
17651759 /* Encode here so that rpcsec_gss can use correct sequence number. */
17661760 rpc_xdr_encode(task);
17671761 /* Did the encode result in an error condition? */
@@ -1779,6 +1773,8 @@ call_encode(struct rpc_task *task) · 11 unmodified lines
17791773 rpc_exit(task, task->tk_status);
17801774 }
17811775 return;
1776+ } else {
1777+ xprt_request_prepare(task->tk_rqstp);
17821778 }
17831779
17841780 /* Add task to reply queue before transmission to avoid races */
@@ -2322,25 +2318,33 @@ out_retry: · 537 unmodified lines
23222318 }
23232319 }
23242320
2325−static __be32 *
2326−rpc_encode_header(struct rpc_task *task)
2321+static int
2322+rpc_encode_header(struct rpc_task *task, struct xdr_stream *xdr)
23272323 {
23282324 struct rpc_clnt *clnt = task->tk_client;
23292325 struct rpc_rqst *req = task->tk_rqstp;
2330− __be32 *p = req->rq_svec[0].iov_base;
2331−
2332− /* FIXME: check buffer size? */
2333−
2334− *p++ = req->rq_xid; /* XID */
2335− *p++ = htonl(RPC_CALL); /* CALL */
2336− *p++ = htonl(RPC_VERSION); /* RPC version */
2337− *p++ = htonl(clnt->cl_prog); /* program number */
2338− *p++ = htonl(clnt->cl_vers); /* program version */
2339− *p++ = htonl(task->tk_msg.rpc_proc->p_proc); /* procedure */
2340− p = rpcauth_marshcred(task, p);
2341− if (p)
2342− req->rq_slen = xdr_adjust_iovec(&req->rq_svec[0], p);
2343− return p;
2326+ __be32 *p;
2327+ int error;
2328+
2329+ error = -EMSGSIZE;
2330+ p = xdr_reserve_space(xdr, RPC_CALLHDRSIZE << 2);
2331+ if (!p)
2332+ goto out_fail;
2333+ *p++ = req->rq_xid;
2334+ *p++ = rpc_call;
2335+ *p++ = cpu_to_be32(RPC_VERSION);
2336+ *p++ = cpu_to_be32(clnt->cl_prog);
2337+ *p++ = cpu_to_be32(clnt->cl_vers);
2338+ *p = cpu_to_be32(task->tk_msg.rpc_proc->p_proc);
2339+
2340+ error = rpcauth_marshcred(task, xdr);
2341+ if (error < 0)
2342+ goto out_fail;
2343+ return 0;
2344+out_fail:
2345+ trace_rpc_bad_callhdr(task);
2346+ rpc_exit(task, error);
2347+ return error;
23442348 }
23452349
23462350 static __be32 *

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t