1// SPDX-License-Identifier: BSD-3-Clause
2/*
3 * linux/net/sunrpc/auth_gss/auth_gss_internal.h
4 *
5 * Internal definitions for RPCSEC_GSS client authentication
6 *
7 * Copyright (c) 2000 The Regents of the University of Michigan.
8 * All rights reserved.
9 *
10 */
11#include <linux/err.h>
12#include <linux/string.h>
13#include <linux/sunrpc/xdr.h>
14
15static inline const void *
16simple_get_bytes(const void *p, const void *end, void *res, size_t len)
17{
18	const void *q = (const void *)((const char *)p + len);
19	if (unlikely(q > end || q < p))
20		return ERR_PTR(-EFAULT);
21	memcpy(res, p, len);
22	return q;
23}
24
25static inline const void *
26simple_get_netobj(const void *p, const void *end, struct xdr_netobj *dest)
27{
28	const void *q;
29	unsigned int len;
30
31	p = simple_get_bytes(p, end, &len, sizeof(len));
32	if (IS_ERR(p))
33		return p;
34	q = (const void *)((const char *)p + len);
35	if (unlikely(q > end || q < p))
36		return ERR_PTR(-EFAULT);
37	if (len) {
38		dest->data = kmemdup(p, len, GFP_KERNEL);
39		if (unlikely(dest->data == NULL))
40			return ERR_PTR(-ENOMEM);
41	} else
42		dest->data = NULL;
43	dest->len = len;
44	return q;
45}
46