Skip to content

Commit ba6dfce

Browse files
DaveWysochanskiRHTrond Myklebust
authored and
Trond Myklebust
committed
SUNRPC: Move simple_get_bytes and simple_get_netobj into private header
Remove duplicated helper functions to parse opaque XDR objects and place inside new file net/sunrpc/auth_gss/auth_gss_internal.h. In the new file carry the license and copyright from the source file net/sunrpc/auth_gss/auth_gss.c. Finally, update the comment inside include/linux/sunrpc/xdr.h since lockd is not the only user of struct xdr_netobj. Signed-off-by: Dave Wysochanski <[email protected]> Signed-off-by: Trond Myklebust <[email protected]>
1 parent d29b468 commit ba6dfce

File tree

4 files changed

+46
-60
lines changed

4 files changed

+46
-60
lines changed

include/linux/sunrpc/xdr.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ struct rpc_rqst;
2525
#define XDR_QUADLEN(l) (((l) + 3) >> 2)
2626

2727
/*
28-
* Generic opaque `network object.' At the kernel level, this type
29-
* is used only by lockd.
28+
* Generic opaque `network object.'
3029
*/
3130
#define XDR_MAX_NETOBJ 1024
3231
struct xdr_netobj {

net/sunrpc/auth_gss/auth_gss.c

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <linux/uaccess.h>
3030
#include <linux/hashtable.h>
3131

32+
#include "auth_gss_internal.h"
3233
#include "../netns.h"
3334

3435
#include <trace/events/rpcgss.h>
@@ -125,35 +126,6 @@ gss_cred_set_ctx(struct rpc_cred *cred, struct gss_cl_ctx *ctx)
125126
clear_bit(RPCAUTH_CRED_NEW, &cred->cr_flags);
126127
}
127128

128-
static const void *
129-
simple_get_bytes(const void *p, const void *end, void *res, size_t len)
130-
{
131-
const void *q = (const void *)((const char *)p + len);
132-
if (unlikely(q > end || q < p))
133-
return ERR_PTR(-EFAULT);
134-
memcpy(res, p, len);
135-
return q;
136-
}
137-
138-
static inline const void *
139-
simple_get_netobj(const void *p, const void *end, struct xdr_netobj *dest)
140-
{
141-
const void *q;
142-
unsigned int len;
143-
144-
p = simple_get_bytes(p, end, &len, sizeof(len));
145-
if (IS_ERR(p))
146-
return p;
147-
q = (const void *)((const char *)p + len);
148-
if (unlikely(q > end || q < p))
149-
return ERR_PTR(-EFAULT);
150-
dest->data = kmemdup(p, len, GFP_NOFS);
151-
if (unlikely(dest->data == NULL))
152-
return ERR_PTR(-ENOMEM);
153-
dest->len = len;
154-
return q;
155-
}
156-
157129
static struct gss_cl_ctx *
158130
gss_cred_get_ctx(struct rpc_cred *cred)
159131
{
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
15+
static inline const void *
16+
simple_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+
25+
static inline const void *
26+
simple_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+
dest->data = kmemdup(p, len, GFP_NOFS);
38+
if (unlikely(dest->data == NULL))
39+
return ERR_PTR(-ENOMEM);
40+
dest->len = len;
41+
return q;
42+
}

net/sunrpc/auth_gss/gss_krb5_mech.c

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#include <linux/sunrpc/xdr.h>
2222
#include <linux/sunrpc/gss_krb5_enctypes.h>
2323

24+
#include "auth_gss_internal.h"
25+
2426
#if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
2527
# define RPCDBG_FACILITY RPCDBG_AUTH
2628
#endif
@@ -143,35 +145,6 @@ get_gss_krb5_enctype(int etype)
143145
return NULL;
144146
}
145147

146-
static const void *
147-
simple_get_bytes(const void *p, const void *end, void *res, int len)
148-
{
149-
const void *q = (const void *)((const char *)p + len);
150-
if (unlikely(q > end || q < p))
151-
return ERR_PTR(-EFAULT);
152-
memcpy(res, p, len);
153-
return q;
154-
}
155-
156-
static const void *
157-
simple_get_netobj(const void *p, const void *end, struct xdr_netobj *res)
158-
{
159-
const void *q;
160-
unsigned int len;
161-
162-
p = simple_get_bytes(p, end, &len, sizeof(len));
163-
if (IS_ERR(p))
164-
return p;
165-
q = (const void *)((const char *)p + len);
166-
if (unlikely(q > end || q < p))
167-
return ERR_PTR(-EFAULT);
168-
res->data = kmemdup(p, len, GFP_NOFS);
169-
if (unlikely(res->data == NULL))
170-
return ERR_PTR(-ENOMEM);
171-
res->len = len;
172-
return q;
173-
}
174-
175148
static inline const void *
176149
get_key(const void *p, const void *end,
177150
struct krb5_ctx *ctx, struct crypto_sync_skcipher **res)

0 commit comments

Comments
 (0)