4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2012, 2016, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
32 #define DEBUG_SUBSYSTEM S_SEC
33 #include <linux/init.h>
34 #include <linux/module.h>
35 #include <linux/slab.h>
36 #include <linux/dcache.h>
38 #include <linux/mutex.h>
41 #include <obd_class.h>
42 #include <obd_support.h>
43 #include <lustre_net.h>
44 #include <lustre_import.h>
45 #include <lprocfs_status.h>
46 #include <lustre_sec.h>
49 #include "gss_internal.h"
52 static struct dentry *gss_debugfs_dir_lk;
53 static struct dentry *gss_debugfs_dir;
54 static struct proc_dir_entry *gss_lprocfs_dir;
57 * statistic of "out-of-sequence-window"
61 atomic_t oos_cli_count; /* client occurrence */
62 int oos_cli_behind; /* client max seqs behind */
63 atomic_t oos_svc_replay[3]; /* server replay detected */
64 atomic_t oos_svc_pass[3]; /* server verified ok */
66 .oos_cli_count = ATOMIC_INIT(0),
68 .oos_svc_replay = { ATOMIC_INIT(0), },
69 .oos_svc_pass = { ATOMIC_INIT(0), },
72 void gss_stat_oos_record_cli(int behind)
74 atomic_inc(&gss_stat_oos.oos_cli_count);
76 spin_lock(&gss_stat_oos.oos_lock);
77 if (behind > gss_stat_oos.oos_cli_behind)
78 gss_stat_oos.oos_cli_behind = behind;
79 spin_unlock(&gss_stat_oos.oos_lock);
82 void gss_stat_oos_record_svc(int phase, int replay)
84 LASSERT(phase >= 0 && phase <= 2);
87 atomic_inc(&gss_stat_oos.oos_svc_replay[phase]);
89 atomic_inc(&gss_stat_oos.oos_svc_pass[phase]);
92 static int gss_proc_oos_seq_show(struct seq_file *m, void *v)
94 seq_printf(m, "seqwin: %u\n"
96 "client fall behind seqwin\n"
98 " max seq behind: %d\n"
99 "server replay detected:\n"
103 "server verify ok:\n"
107 atomic_read(&gss_stat_oos.oos_cli_count),
108 gss_stat_oos.oos_cli_behind,
109 atomic_read(&gss_stat_oos.oos_svc_replay[0]),
110 atomic_read(&gss_stat_oos.oos_svc_replay[1]),
111 atomic_read(&gss_stat_oos.oos_svc_replay[2]),
112 atomic_read(&gss_stat_oos.oos_svc_pass[2]));
115 LDEBUGFS_SEQ_FOPS_RO(gss_proc_oos);
118 gss_proc_write_secinit(struct file *file, const char *buffer,
119 size_t count, loff_t *off)
123 rc = gss_do_ctx_init_rpc((char *) buffer, count);
131 static const struct file_operations gss_proc_secinit = {
132 .write = gss_proc_write_secinit,
136 sptlrpc_krb5_allow_old_client_csum_seq_show(struct seq_file *m,
139 seq_printf(m, "%u\n", krb5_allow_old_client_csum);
144 sptlrpc_krb5_allow_old_client_csum_seq_write(struct file *file,
145 const char __user *buffer,
146 size_t count, loff_t *off)
151 rc = kstrtobool_from_user(buffer, count, &val);
155 krb5_allow_old_client_csum = val;
158 LPROC_SEQ_FOPS(sptlrpc_krb5_allow_old_client_csum);
160 #ifdef HAVE_GSS_KEYRING
161 static int sptlrpc_gss_check_upcall_ns_seq_show(struct seq_file *m, void *data)
163 seq_printf(m, "%u\n", gss_check_upcall_ns);
167 static ssize_t sptlrpc_gss_check_upcall_ns_seq_write(struct file *file,
168 const char __user *buffer,
169 size_t count, loff_t *off)
174 rc = kstrtobool_from_user(buffer, count, &val);
178 gss_check_upcall_ns = val;
181 LPROC_SEQ_FOPS(sptlrpc_gss_check_upcall_ns);
182 #endif /* HAVE_GSS_KEYRING */
184 static int rsi_upcall_seq_show(struct seq_file *m,
187 down_read(&rsicache->uc_upcall_rwsem);
188 seq_printf(m, "%s\n", rsicache->uc_upcall);
189 up_read(&rsicache->uc_upcall_rwsem);
194 static ssize_t rsi_upcall_seq_write(struct file *file,
195 const char __user *buffer,
196 size_t count, loff_t *off)
201 if (count >= UC_CACHE_UPCALL_MAXPATH) {
202 CERROR("%s: rsi upcall too long\n", rsicache->uc_name);
206 OBD_ALLOC(kbuf, count + 1);
210 if (copy_from_user(kbuf, buffer, count))
211 GOTO(out, rc = -EFAULT);
215 /* Remove any extraneous bits from the upcall (e.g. linefeeds) */
216 down_write(&rsicache->uc_upcall_rwsem);
217 rc = sscanf(kbuf, "%s", rsicache->uc_upcall);
218 up_write(&rsicache->uc_upcall_rwsem);
221 CERROR("%s: invalid rsi upcall provided\n", rsicache->uc_name);
222 GOTO(out, rc = -EINVAL);
225 CDEBUG(D_CONFIG, "%s: rsi upcall set to %s\n", rsicache->uc_name,
226 rsicache->uc_upcall);
229 OBD_FREE(kbuf, count + 1);
232 LPROC_SEQ_FOPS(rsi_upcall);
234 static ssize_t lprocfs_rsi_info_seq_write(struct file *file,
235 const char __user *buffer,
236 size_t count, void *data)
238 struct rsi_downcall_data *param;
239 int size = sizeof(*param), rc, checked = 0;
243 CERROR("%s: invalid data count = %lu, size = %d\n",
244 rsicache->uc_name, (unsigned long)count, size);
248 OBD_ALLOC_LARGE(param, size);
252 if (copy_from_user(param, buffer, size)) {
253 CERROR("%s: bad rsi data\n", rsicache->uc_name);
254 GOTO(out, rc = -EFAULT);
259 if (param->sid_magic != RSI_DOWNCALL_MAGIC) {
260 CERROR("%s: rsi downcall bad params\n",
262 GOTO(out, rc = -EINVAL);
265 rc = param->sid_len; /* save sid_len */
266 OBD_FREE_LARGE(param, size);
267 size = offsetof(struct rsi_downcall_data, sid_val[rc]);
271 rc = upcall_cache_downcall(rsicache, param->sid_err,
272 param->sid_hash, param);
274 /* The caller, i.e. the userspace process writing to rsi_info, only
275 * needs to know about invalid values. Other errors are processed
276 * directly in the kernel.
283 OBD_FREE_LARGE(param, size);
285 return rc ? rc : count;
287 LPROC_SEQ_FOPS_WR_ONLY(gss, rsi_info);
289 static int rsi_entry_expire_seq_show(struct seq_file *m,
292 seq_printf(m, "%lld\n", rsicache->uc_entry_expire);
296 static ssize_t rsi_entry_expire_seq_write(struct file *file,
297 const char __user *buffer,
298 size_t count, loff_t *off)
303 rc = kstrtoll_from_user(buffer, count, 10, &val);
310 rsicache->uc_entry_expire = val;
314 LPROC_SEQ_FOPS(rsi_entry_expire);
316 static int rsi_acquire_expire_seq_show(struct seq_file *m,
319 seq_printf(m, "%lld\n", rsicache->uc_acquire_expire);
323 static ssize_t rsi_acquire_expire_seq_write(struct file *file,
324 const char __user *buffer,
325 size_t count, loff_t *off)
330 rc = kstrtoll_from_user(buffer, count, 10, &val);
334 if (val < 0 || val > INT_MAX)
337 rsicache->uc_acquire_expire = val;
341 LPROC_SEQ_FOPS(rsi_acquire_expire);
343 static ssize_t lprocfs_rsc_info_seq_write(struct file *file,
344 const char __user *buffer,
345 size_t count, void *data)
347 struct rsc_downcall_data *param;
348 int size = sizeof(*param), rc, checked = 0;
349 struct gss_rsc rsc = { 0 }, *rscp = NULL;
350 char *mesg, *handle_buf;
354 CERROR("%s: invalid data count = %lu, size = %d\n",
355 rsccache->uc_name, (unsigned long)count, size);
359 OBD_ALLOC_LARGE(param, size);
363 if (copy_from_user(param, buffer, size)) {
364 CERROR("%s: bad rsc data\n", rsccache->uc_name);
365 GOTO(out, rc = -EFAULT);
370 if (param->scd_magic != RSC_DOWNCALL_MAGIC) {
371 CERROR("%s: rsc downcall bad params\n",
373 GOTO(out, rc = -EINVAL);
376 rc = param->scd_len; /* save scd_len */
377 OBD_FREE_LARGE(param, size);
378 size = offsetof(struct rsc_downcall_data, scd_val[rc]);
382 /* scd_val starts with handle.
383 * Use it to create cache entry.
385 mesg = param->scd_val;
386 gss_u32_read(&mesg, &rsc.sc_handle.len);
387 if (!rsc.sc_handle.len) {
391 OBD_ALLOC_LARGE(handle_buf, rsc.sc_handle.len);
396 memset(handle_buf, 0, rsc.sc_handle.len);
397 mesg = param->scd_val;
398 rc = gss_buffer_read(&mesg, handle_buf, rsc.sc_handle.len);
400 OBD_FREE_LARGE(handle_buf, rsc.sc_handle.len);
404 rsc.sc_handle.data = handle_buf;
406 /* create cache entry on-the-fly */
407 rscp = rsc_entry_get(rsccache, &rsc);
410 if (IS_ERR_OR_NULL(rscp)) {
415 CERROR("%s: error in rsc_entry_get: rc = %d\n",
416 param->scd_mechname, rc);
420 /* now that entry has been created, downcall can be done,
421 * but we have to tell acquiring is in progress
423 upcall_cache_update_entry(rsccache, rscp->sc_uc_entry,
424 0, UC_CACHE_ACQUIRING);
425 rc = upcall_cache_downcall(rsccache, param->scd_err,
426 rscp->sc_uc_entry->ue_key, param);
429 if (!IS_ERR_OR_NULL(rscp))
430 rsc_entry_put(rsccache, rscp);
432 OBD_FREE_LARGE(param, size);
434 return rc ? rc : count;
436 LPROC_SEQ_FOPS_WR_ONLY(gss, rsc_info);
438 static struct ldebugfs_vars gss_debugfs_vars[] = {
440 .fops = &gss_proc_oos_fops },
441 { .name = "init_channel",
442 .fops = &gss_proc_secinit,
447 static struct lprocfs_vars gss_lprocfs_vars[] = {
448 { .name = "krb5_allow_old_client_csum",
449 .fops = &sptlrpc_krb5_allow_old_client_csum_fops },
450 #ifdef HAVE_GSS_KEYRING
451 { .name = "gss_check_upcall_ns",
452 .fops = &sptlrpc_gss_check_upcall_ns_fops },
454 { .name = "rsi_upcall",
455 .fops = &rsi_upcall_fops },
456 { .name = "rsi_info",
457 .fops = &gss_rsi_info_fops },
458 { .name = "rsi_entry_expire",
459 .fops = &rsi_entry_expire_fops },
460 { .name = "rsi_acquire_expire",
461 .fops = &rsi_acquire_expire_fops },
462 { .name = "rsc_info",
463 .fops = &gss_rsc_info_fops },
468 * for userspace helper lgss_keyring.
470 * debug_level: [0, 4], defined in utils/gss/lgss_utils.h
472 static int gss_lk_debug_level = 1;
474 static int gss_lk_proc_dl_seq_show(struct seq_file *m, void *v)
476 seq_printf(m, "%u\n", gss_lk_debug_level);
481 gss_lk_proc_dl_seq_write(struct file *file, const char __user *buffer,
482 size_t count, loff_t *off)
487 rc = kstrtouint_from_user(buffer, count, 0, &val);
494 gss_lk_debug_level = val;
498 LDEBUGFS_SEQ_FOPS(gss_lk_proc_dl);
500 static struct ldebugfs_vars gss_lk_debugfs_vars[] = {
501 { .name = "debug_level",
502 .fops = &gss_lk_proc_dl_fops },
506 void gss_exit_tunables(void)
508 debugfs_remove_recursive(gss_debugfs_dir_lk);
509 gss_debugfs_dir_lk = NULL;
511 debugfs_remove_recursive(gss_debugfs_dir);
512 gss_debugfs_dir = NULL;
514 if (!IS_ERR_OR_NULL(gss_lprocfs_dir))
515 lprocfs_remove(&gss_lprocfs_dir);
518 int gss_init_tunables(void)
522 spin_lock_init(&gss_stat_oos.oos_lock);
524 gss_debugfs_dir = debugfs_create_dir("gss", sptlrpc_debugfs_dir);
525 ldebugfs_add_vars(gss_debugfs_dir, gss_debugfs_vars, NULL);
527 gss_debugfs_dir_lk = debugfs_create_dir("lgss_keyring",
529 ldebugfs_add_vars(gss_debugfs_dir_lk, gss_lk_debugfs_vars, NULL);
531 gss_lprocfs_dir = lprocfs_register("gss", sptlrpc_lprocfs_dir,
532 gss_lprocfs_vars, NULL);
533 if (IS_ERR_OR_NULL(gss_lprocfs_dir)) {
534 rc = gss_lprocfs_dir ? PTR_ERR(gss_lprocfs_dir) : -ENOMEM;
535 gss_lprocfs_dir = NULL;
542 CERROR("failed to initialize gss lproc entries: %d\n", rc);