summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Coddington <bcodding@redhat.com>2019-09-16 07:59:38 -0400
committerAnna Schumaker <Anna.Schumaker@Netapp.com>2019-09-20 15:15:24 -0400
commitf925ab926d1a9c2112d34ecb59fbb050bb58646c (patch)
tree200787e79b6689856bee0537499aefb50047c044
parent5f1bc39979d868a0358c683864bec3fc8395440b (diff)
SUNRPC: Rename xdr_buf_read_netobj to xdr_buf_read_mic
Let the name reflect the single use. The function now assumes the GSS MIC is the last object in the buffer. Signed-off-by: Benjamin Coddington <bcodding@redhat.com> Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
-rw-r--r--include/linux/sunrpc/xdr.h2
-rw-r--r--net/sunrpc/auth_gss/auth_gss.c2
-rw-r--r--net/sunrpc/xdr.c52
3 files changed, 32 insertions, 24 deletions
diff --git a/include/linux/sunrpc/xdr.h b/include/linux/sunrpc/xdr.h
index 8a87d8bcb197..f33e5013bdfb 100644
--- a/include/linux/sunrpc/xdr.h
+++ b/include/linux/sunrpc/xdr.h
@@ -186,7 +186,7 @@ xdr_adjust_iovec(struct kvec *iov, __be32 *p)
186extern void xdr_shift_buf(struct xdr_buf *, size_t); 186extern void xdr_shift_buf(struct xdr_buf *, size_t);
187extern void xdr_buf_from_iov(struct kvec *, struct xdr_buf *); 187extern void xdr_buf_from_iov(struct kvec *, struct xdr_buf *);
188extern int xdr_buf_subsegment(struct xdr_buf *, struct xdr_buf *, unsigned int, unsigned int); 188extern int xdr_buf_subsegment(struct xdr_buf *, struct xdr_buf *, unsigned int, unsigned int);
189extern int xdr_buf_read_netobj(struct xdr_buf *, struct xdr_netobj *, unsigned int); 189extern int xdr_buf_read_mic(struct xdr_buf *, struct xdr_netobj *, unsigned int);
190extern int read_bytes_from_xdr_buf(struct xdr_buf *, unsigned int, void *, unsigned int); 190extern int read_bytes_from_xdr_buf(struct xdr_buf *, unsigned int, void *, unsigned int);
191extern int write_bytes_to_xdr_buf(struct xdr_buf *, unsigned int, void *, unsigned int); 191extern int write_bytes_to_xdr_buf(struct xdr_buf *, unsigned int, void *, unsigned int);
192 192
diff --git a/net/sunrpc/auth_gss/auth_gss.c b/net/sunrpc/auth_gss/auth_gss.c
index 4ce42c62458e..d75fddca44c9 100644
--- a/net/sunrpc/auth_gss/auth_gss.c
+++ b/net/sunrpc/auth_gss/auth_gss.c
@@ -1960,7 +1960,7 @@ gss_unwrap_resp_integ(struct rpc_task *task, struct rpc_cred *cred,
1960 1960
1961 if (xdr_buf_subsegment(rcv_buf, &integ_buf, data_offset, integ_len)) 1961 if (xdr_buf_subsegment(rcv_buf, &integ_buf, data_offset, integ_len))
1962 goto unwrap_failed; 1962 goto unwrap_failed;
1963 if (xdr_buf_read_netobj(rcv_buf, &mic, mic_offset)) 1963 if (xdr_buf_read_mic(rcv_buf, &mic, mic_offset))
1964 goto unwrap_failed; 1964 goto unwrap_failed;
1965 maj_stat = gss_verify_mic(ctx->gc_gss_ctx, &integ_buf, &mic); 1965 maj_stat = gss_verify_mic(ctx->gc_gss_ctx, &integ_buf, &mic);
1966 if (maj_stat == GSS_S_CONTEXT_EXPIRED) 1966 if (maj_stat == GSS_S_CONTEXT_EXPIRED)
diff --git a/net/sunrpc/xdr.c b/net/sunrpc/xdr.c
index 24ec2ab5bfa5..14ba9e72a204 100644
--- a/net/sunrpc/xdr.c
+++ b/net/sunrpc/xdr.c
@@ -1236,52 +1236,60 @@ xdr_encode_word(struct xdr_buf *buf, unsigned int base, u32 obj)
1236} 1236}
1237EXPORT_SYMBOL_GPL(xdr_encode_word); 1237EXPORT_SYMBOL_GPL(xdr_encode_word);
1238 1238
1239/* If the netobj starting offset bytes from the start of xdr_buf is contained 1239/**
1240 * entirely in the head, pages, or tail, set object to point to it; otherwise 1240 * xdr_buf_read_mic() - obtain the address of the GSS mic from xdr buf
1241 * shift the buffer until it is contained entirely within the pages or tail. 1241 * @buf: pointer to buffer containing a mic
1242 * @mic: on success, returns the address of the mic
1243 * @offset: the offset in buf where mic may be found
1244 *
1245 * This function may modify the xdr buf if the mic is found to be straddling
1246 * a boundary between head, pages, and tail. On success the mic can be read
1247 * from the address returned. There is no need to free the mic.
1248 *
1249 * Return: Success returns 0, otherwise an integer error.
1242 */ 1250 */
1243int xdr_buf_read_netobj(struct xdr_buf *buf, struct xdr_netobj *obj, unsigned int offset) 1251int xdr_buf_read_mic(struct xdr_buf *buf, struct xdr_netobj *mic, unsigned int offset)
1244{ 1252{
1245 struct xdr_buf subbuf; 1253 struct xdr_buf subbuf;
1246 unsigned int boundary; 1254 unsigned int boundary;
1247 1255
1248 if (xdr_decode_word(buf, offset, &obj->len)) 1256 if (xdr_decode_word(buf, offset, &mic->len))
1249 return -EFAULT; 1257 return -EFAULT;
1250 offset += 4; 1258 offset += 4;
1251 1259
1252 /* Is the obj partially in the head? */ 1260 /* Is the mic partially in the head? */
1253 boundary = buf->head[0].iov_len; 1261 boundary = buf->head[0].iov_len;
1254 if (offset < boundary && (offset + obj->len) > boundary) 1262 if (offset < boundary && (offset + mic->len) > boundary)
1255 xdr_shift_buf(buf, boundary - offset); 1263 xdr_shift_buf(buf, boundary - offset);
1256 1264
1257 /* Is the obj partially in the pages? */ 1265 /* Is the mic partially in the pages? */
1258 boundary += buf->page_len; 1266 boundary += buf->page_len;
1259 if (offset < boundary && (offset + obj->len) > boundary) 1267 if (offset < boundary && (offset + mic->len) > boundary)
1260 xdr_shrink_pagelen(buf, boundary - offset); 1268 xdr_shrink_pagelen(buf, boundary - offset);
1261 1269
1262 if (xdr_buf_subsegment(buf, &subbuf, offset, obj->len)) 1270 if (xdr_buf_subsegment(buf, &subbuf, offset, mic->len))
1263 return -EFAULT; 1271 return -EFAULT;
1264 1272
1265 /* Is the obj contained entirely in the head? */ 1273 /* Is the mic contained entirely in the head? */
1266 obj->data = subbuf.head[0].iov_base; 1274 mic->data = subbuf.head[0].iov_base;
1267 if (subbuf.head[0].iov_len == obj->len) 1275 if (subbuf.head[0].iov_len == mic->len)
1268 return 0; 1276 return 0;
1269 /* ..or is the obj contained entirely in the tail? */ 1277 /* ..or is the mic contained entirely in the tail? */
1270 obj->data = subbuf.tail[0].iov_base; 1278 mic->data = subbuf.tail[0].iov_base;
1271 if (subbuf.tail[0].iov_len == obj->len) 1279 if (subbuf.tail[0].iov_len == mic->len)
1272 return 0; 1280 return 0;
1273 1281
1274 /* Find a contiguous area in @buf to hold all of @obj */ 1282 /* Find a contiguous area in @buf to hold all of @mic */
1275 if (obj->len > buf->buflen - buf->len) 1283 if (mic->len > buf->buflen - buf->len)
1276 return -ENOMEM; 1284 return -ENOMEM;
1277 if (buf->tail[0].iov_len != 0) 1285 if (buf->tail[0].iov_len != 0)
1278 obj->data = buf->tail[0].iov_base + buf->tail[0].iov_len; 1286 mic->data = buf->tail[0].iov_base + buf->tail[0].iov_len;
1279 else 1287 else
1280 obj->data = buf->head[0].iov_base + buf->head[0].iov_len; 1288 mic->data = buf->head[0].iov_base + buf->head[0].iov_len;
1281 __read_bytes_from_xdr_buf(&subbuf, obj->data, obj->len); 1289 __read_bytes_from_xdr_buf(&subbuf, mic->data, mic->len);
1282 return 0; 1290 return 0;
1283} 1291}
1284EXPORT_SYMBOL_GPL(xdr_buf_read_netobj); 1292EXPORT_SYMBOL_GPL(xdr_buf_read_mic);
1285 1293
1286/* Returns 0 on success, or else a negative error code. */ 1294/* Returns 0 on success, or else a negative error code. */
1287static int 1295static int