hc
2024-02-19 1c055e55a242a33e574e48be530e06770a210dcd
kernel/net/sunrpc/auth_gss/gss_mech_switch.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: BSD-3-Clause
12 /*
23 * linux/net/sunrpc/gss_mech_switch.c
34 *
....@@ -5,32 +6,6 @@
56 * All rights reserved.
67 *
78 * J. Bruce Fields <bfields@umich.edu>
8
- *
9
- * Redistribution and use in source and binary forms, with or without
10
- * modification, are permitted provided that the following conditions
11
- * are met:
12
- *
13
- * 1. Redistributions of source code must retain the above copyright
14
- * notice, this list of conditions and the following disclaimer.
15
- * 2. Redistributions in binary form must reproduce the above copyright
16
- * notice, this list of conditions and the following disclaimer in the
17
- * documentation and/or other materials provided with the distribution.
18
- * 3. Neither the name of the University nor the names of its
19
- * contributors may be used to endorse or promote products derived
20
- * from this software without specific prior written permission.
21
- *
22
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
23
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
24
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25
- * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
29
- * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
- *
349 */
3510
3611 #include <linux/types.h>
....@@ -45,6 +20,7 @@
4520 #include <linux/sunrpc/sched.h>
4621 #include <linux/sunrpc/gss_api.h>
4722 #include <linux/sunrpc/clnt.h>
23
+#include <trace/events/rpcgss.h>
4824
4925 #if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
5026 # define RPCDBG_FACILITY RPCDBG_AUTH
....@@ -123,7 +99,7 @@
12399 if (status)
124100 return status;
125101 spin_lock(&registered_mechs_lock);
126
- list_add(&gm->gm_list, &registered_mechs);
102
+ list_add_rcu(&gm->gm_list, &registered_mechs);
127103 spin_unlock(&registered_mechs_lock);
128104 dprintk("RPC: registered gss mechanism %s\n", gm->gm_name);
129105 return 0;
....@@ -138,7 +114,7 @@
138114 void gss_mech_unregister(struct gss_api_mech *gm)
139115 {
140116 spin_lock(&registered_mechs_lock);
141
- list_del(&gm->gm_list);
117
+ list_del_rcu(&gm->gm_list);
142118 spin_unlock(&registered_mechs_lock);
143119 dprintk("RPC: unregistered gss mechanism %s\n", gm->gm_name);
144120 gss_mech_free(gm);
....@@ -157,15 +133,15 @@
157133 {
158134 struct gss_api_mech *pos, *gm = NULL;
159135
160
- spin_lock(&registered_mechs_lock);
161
- list_for_each_entry(pos, &registered_mechs, gm_list) {
136
+ rcu_read_lock();
137
+ list_for_each_entry_rcu(pos, &registered_mechs, gm_list) {
162138 if (0 == strcmp(name, pos->gm_name)) {
163139 if (try_module_get(pos->gm_owner))
164140 gm = pos;
165141 break;
166142 }
167143 }
168
- spin_unlock(&registered_mechs_lock);
144
+ rcu_read_unlock();
169145 return gm;
170146
171147 }
....@@ -189,11 +165,10 @@
189165
190166 if (sprint_oid(obj->data, obj->len, buf, sizeof(buf)) < 0)
191167 return NULL;
192
- dprintk("RPC: %s(%s)\n", __func__, buf);
193168 request_module("rpc-auth-gss-%s", buf);
194169
195
- spin_lock(&registered_mechs_lock);
196
- list_for_each_entry(pos, &registered_mechs, gm_list) {
170
+ rcu_read_lock();
171
+ list_for_each_entry_rcu(pos, &registered_mechs, gm_list) {
197172 if (obj->len == pos->gm_oid.len) {
198173 if (0 == memcmp(obj->data, pos->gm_oid.data, obj->len)) {
199174 if (try_module_get(pos->gm_owner))
....@@ -202,7 +177,9 @@
202177 }
203178 }
204179 }
205
- spin_unlock(&registered_mechs_lock);
180
+ rcu_read_unlock();
181
+ if (!gm)
182
+ trace_rpcgss_oid_to_mech(buf);
206183 return gm;
207184 }
208185
....@@ -222,15 +199,15 @@
222199 {
223200 struct gss_api_mech *gm = NULL, *pos;
224201
225
- spin_lock(&registered_mechs_lock);
226
- list_for_each_entry(pos, &registered_mechs, gm_list) {
202
+ rcu_read_lock();
203
+ list_for_each_entry_rcu(pos, &registered_mechs, gm_list) {
227204 if (!mech_supports_pseudoflavor(pos, pseudoflavor))
228205 continue;
229206 if (try_module_get(pos->gm_owner))
230207 gm = pos;
231208 break;
232209 }
233
- spin_unlock(&registered_mechs_lock);
210
+ rcu_read_unlock();
234211 return gm;
235212 }
236213
....@@ -246,35 +223,6 @@
246223 gm = _gss_mech_get_by_pseudoflavor(pseudoflavor);
247224 }
248225 return gm;
249
-}
250
-
251
-/**
252
- * gss_mech_list_pseudoflavors - Discover registered GSS pseudoflavors
253
- * @array: array to fill in
254
- * @size: size of "array"
255
- *
256
- * Returns the number of array items filled in, or a negative errno.
257
- *
258
- * The returned array is not sorted by any policy. Callers should not
259
- * rely on the order of the items in the returned array.
260
- */
261
-int gss_mech_list_pseudoflavors(rpc_authflavor_t *array_ptr, int size)
262
-{
263
- struct gss_api_mech *pos = NULL;
264
- int j, i = 0;
265
-
266
- spin_lock(&registered_mechs_lock);
267
- list_for_each_entry(pos, &registered_mechs, gm_list) {
268
- for (j = 0; j < pos->gm_pf_num; j++) {
269
- if (i >= size) {
270
- spin_unlock(&registered_mechs_lock);
271
- return -ENOMEM;
272
- }
273
- array_ptr[i++] = pos->gm_pfs[j].pseudoflavor;
274
- }
275
- }
276
- spin_unlock(&registered_mechs_lock);
277
- return i;
278226 }
279227
280228 /**
....@@ -405,7 +353,7 @@
405353 gss_import_sec_context(const void *input_token, size_t bufsize,
406354 struct gss_api_mech *mech,
407355 struct gss_ctx **ctx_id,
408
- time_t *endtime,
356
+ time64_t *endtime,
409357 gfp_t gfp_mask)
410358 {
411359 if (!(*ctx_id = kzalloc(sizeof(**ctx_id), gfp_mask)))
....@@ -469,10 +417,11 @@
469417 u32
470418 gss_unwrap(struct gss_ctx *ctx_id,
471419 int offset,
420
+ int len,
472421 struct xdr_buf *buf)
473422 {
474423 return ctx_id->mech_type->gm_ops
475
- ->gss_unwrap(ctx_id, offset, buf);
424
+ ->gss_unwrap(ctx_id, offset, len, buf);
476425 }
477426
478427