18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: BSD-3-Clause 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * linux/net/sunrpc/auth_gss/auth_gss_internal.h 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Internal definitions for RPCSEC_GSS client authentication 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * Copyright (c) 2000 The Regents of the University of Michigan. 88c2ecf20Sopenharmony_ci * All rights reserved. 98c2ecf20Sopenharmony_ci * 108c2ecf20Sopenharmony_ci */ 118c2ecf20Sopenharmony_ci#include <linux/err.h> 128c2ecf20Sopenharmony_ci#include <linux/string.h> 138c2ecf20Sopenharmony_ci#include <linux/sunrpc/xdr.h> 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_cistatic inline const void * 168c2ecf20Sopenharmony_cisimple_get_bytes(const void *p, const void *end, void *res, size_t len) 178c2ecf20Sopenharmony_ci{ 188c2ecf20Sopenharmony_ci const void *q = (const void *)((const char *)p + len); 198c2ecf20Sopenharmony_ci if (unlikely(q > end || q < p)) 208c2ecf20Sopenharmony_ci return ERR_PTR(-EFAULT); 218c2ecf20Sopenharmony_ci memcpy(res, p, len); 228c2ecf20Sopenharmony_ci return q; 238c2ecf20Sopenharmony_ci} 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_cistatic inline const void * 268c2ecf20Sopenharmony_cisimple_get_netobj(const void *p, const void *end, struct xdr_netobj *dest) 278c2ecf20Sopenharmony_ci{ 288c2ecf20Sopenharmony_ci const void *q; 298c2ecf20Sopenharmony_ci unsigned int len; 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ci p = simple_get_bytes(p, end, &len, sizeof(len)); 328c2ecf20Sopenharmony_ci if (IS_ERR(p)) 338c2ecf20Sopenharmony_ci return p; 348c2ecf20Sopenharmony_ci q = (const void *)((const char *)p + len); 358c2ecf20Sopenharmony_ci if (unlikely(q > end || q < p)) 368c2ecf20Sopenharmony_ci return ERR_PTR(-EFAULT); 378c2ecf20Sopenharmony_ci if (len) { 388c2ecf20Sopenharmony_ci dest->data = kmemdup(p, len, GFP_NOFS); 398c2ecf20Sopenharmony_ci if (unlikely(dest->data == NULL)) 408c2ecf20Sopenharmony_ci return ERR_PTR(-ENOMEM); 418c2ecf20Sopenharmony_ci } else 428c2ecf20Sopenharmony_ci dest->data = NULL; 438c2ecf20Sopenharmony_ci dest->len = len; 448c2ecf20Sopenharmony_ci return q; 458c2ecf20Sopenharmony_ci} 46