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 OBD_ALLOC(kbuf, count + 1);
205 if (copy_from_user(kbuf, buffer, count))
206 GOTO(out, rc = -EFAULT);
210 rc = upcall_cache_set_upcall(rsicache, kbuf, count, true);
212 CERROR("%s: incorrect rsi upcall %s. Valid value for sptlrpc.gss.rsi_upcall is an executable pathname: rc = %d\n",
213 rsicache->uc_name, kbuf, rc);
217 CDEBUG(D_CONFIG, "%s: rsi upcall set to %s\n", rsicache->uc_name,
218 rsicache->uc_upcall);
222 OBD_FREE(kbuf, count + 1);
225 LPROC_SEQ_FOPS(rsi_upcall);
227 static ssize_t lprocfs_rsi_info_seq_write(struct file *file,
228 const char __user *buffer,
229 size_t count, void *data)
231 struct rsi_downcall_data *param;
232 int size = sizeof(*param), rc, checked = 0;
236 CERROR("%s: invalid data count = %lu, size = %d\n",
237 rsicache->uc_name, (unsigned long)count, size);
241 OBD_ALLOC_LARGE(param, size);
245 if (copy_from_user(param, buffer, size)) {
246 CERROR("%s: bad rsi data\n", rsicache->uc_name);
247 GOTO(out, rc = -EFAULT);
252 if (param->sid_magic != RSI_DOWNCALL_MAGIC) {
253 CERROR("%s: rsi downcall bad params\n",
255 GOTO(out, rc = -EINVAL);
258 rc = param->sid_len; /* save sid_len */
259 OBD_FREE_LARGE(param, size);
260 size = offsetof(struct rsi_downcall_data, sid_val[rc]);
264 rc = upcall_cache_downcall(rsicache, param->sid_err,
265 param->sid_hash, param);
267 /* The caller, i.e. the userspace process writing to rsi_info, only
268 * needs to know about invalid values. Other errors are processed
269 * directly in the kernel.
276 OBD_FREE_LARGE(param, size);
278 return rc ? rc : count;
280 LPROC_SEQ_FOPS_WR_ONLY(gss, rsi_info);
282 static int rsi_entry_expire_seq_show(struct seq_file *m,
285 seq_printf(m, "%lld\n", rsicache->uc_entry_expire);
289 static ssize_t rsi_entry_expire_seq_write(struct file *file,
290 const char __user *buffer,
291 size_t count, loff_t *off)
296 rc = kstrtoll_from_user(buffer, count, 10, &val);
303 rsicache->uc_entry_expire = val;
307 LPROC_SEQ_FOPS(rsi_entry_expire);
309 static int rsi_acquire_expire_seq_show(struct seq_file *m,
312 seq_printf(m, "%lld\n", rsicache->uc_acquire_expire);
316 static ssize_t rsi_acquire_expire_seq_write(struct file *file,
317 const char __user *buffer,
318 size_t count, loff_t *off)
323 rc = kstrtoll_from_user(buffer, count, 10, &val);
327 if (val < 0 || val > INT_MAX)
330 rsicache->uc_acquire_expire = val;
334 LPROC_SEQ_FOPS(rsi_acquire_expire);
336 static ssize_t lprocfs_rsc_info_seq_write(struct file *file,
337 const char __user *buffer,
338 size_t count, void *data)
340 struct rsc_downcall_data *param;
341 int size = sizeof(*param), rc, checked = 0;
342 struct gss_rsc rsc = { 0 }, *rscp = NULL;
343 char *mesg, *handle_buf;
347 CERROR("%s: invalid data count = %lu, size = %d\n",
348 rsccache->uc_name, (unsigned long)count, size);
352 OBD_ALLOC_LARGE(param, size);
356 if (copy_from_user(param, buffer, size)) {
357 CERROR("%s: bad rsc data\n", rsccache->uc_name);
358 GOTO(out, rc = -EFAULT);
363 if (param->scd_magic != RSC_DOWNCALL_MAGIC) {
364 CERROR("%s: rsc downcall bad params\n",
366 GOTO(out, rc = -EINVAL);
369 rc = param->scd_len; /* save scd_len */
370 OBD_FREE_LARGE(param, size);
371 size = offsetof(struct rsc_downcall_data, scd_val[rc]);
375 /* scd_val starts with handle.
376 * Use it to create cache entry.
378 mesg = param->scd_val;
379 gss_u32_read(&mesg, &rsc.sc_handle.len);
380 if (!rsc.sc_handle.len) {
384 OBD_ALLOC_LARGE(handle_buf, rsc.sc_handle.len);
389 memset(handle_buf, 0, rsc.sc_handle.len);
390 mesg = param->scd_val;
391 rc = gss_buffer_read(&mesg, handle_buf, rsc.sc_handle.len);
393 OBD_FREE_LARGE(handle_buf, rsc.sc_handle.len);
397 rsc.sc_handle.data = handle_buf;
399 /* create cache entry on-the-fly */
400 rscp = rsc_entry_get(rsccache, &rsc);
403 if (IS_ERR_OR_NULL(rscp)) {
408 CERROR("%s: error in rsc_entry_get: rc = %d\n",
409 param->scd_mechname, rc);
413 /* now that entry has been created, downcall can be done,
414 * but we have to tell acquiring is in progress
416 upcall_cache_update_entry(rsccache, rscp->sc_uc_entry,
417 0, UC_CACHE_ACQUIRING);
418 rc = upcall_cache_downcall(rsccache, param->scd_err,
419 rscp->sc_uc_entry->ue_key, param);
422 if (!IS_ERR_OR_NULL(rscp))
423 rsc_entry_put(rsccache, rscp);
425 OBD_FREE_LARGE(param, size);
427 return rc ? rc : count;
429 LPROC_SEQ_FOPS_WR_ONLY(gss, rsc_info);
431 static struct ldebugfs_vars gss_debugfs_vars[] = {
433 .fops = &gss_proc_oos_fops },
434 { .name = "init_channel",
435 .fops = &gss_proc_secinit,
440 static struct lprocfs_vars gss_lprocfs_vars[] = {
441 { .name = "krb5_allow_old_client_csum",
442 .fops = &sptlrpc_krb5_allow_old_client_csum_fops },
443 #ifdef HAVE_GSS_KEYRING
444 { .name = "gss_check_upcall_ns",
445 .fops = &sptlrpc_gss_check_upcall_ns_fops },
447 { .name = "rsi_upcall",
448 .fops = &rsi_upcall_fops },
449 { .name = "rsi_info",
450 .fops = &gss_rsi_info_fops },
451 { .name = "rsi_entry_expire",
452 .fops = &rsi_entry_expire_fops },
453 { .name = "rsi_acquire_expire",
454 .fops = &rsi_acquire_expire_fops },
455 { .name = "rsc_info",
456 .fops = &gss_rsc_info_fops },
461 * for userspace helper lgss_keyring.
463 * debug_level: [0, 4], defined in utils/gss/lgss_utils.h
465 static int gss_lk_debug_level = 1;
467 static int gss_lk_proc_dl_seq_show(struct seq_file *m, void *v)
469 seq_printf(m, "%u\n", gss_lk_debug_level);
474 gss_lk_proc_dl_seq_write(struct file *file, const char __user *buffer,
475 size_t count, loff_t *off)
480 rc = kstrtouint_from_user(buffer, count, 0, &val);
487 gss_lk_debug_level = val;
491 LDEBUGFS_SEQ_FOPS(gss_lk_proc_dl);
493 static struct ldebugfs_vars gss_lk_debugfs_vars[] = {
494 { .name = "debug_level",
495 .fops = &gss_lk_proc_dl_fops },
499 void gss_exit_tunables(void)
501 debugfs_remove_recursive(gss_debugfs_dir_lk);
502 gss_debugfs_dir_lk = NULL;
504 debugfs_remove_recursive(gss_debugfs_dir);
505 gss_debugfs_dir = NULL;
507 if (!IS_ERR_OR_NULL(gss_lprocfs_dir))
508 lprocfs_remove(&gss_lprocfs_dir);
511 int gss_init_tunables(void)
515 spin_lock_init(&gss_stat_oos.oos_lock);
517 gss_debugfs_dir = debugfs_create_dir("gss", sptlrpc_debugfs_dir);
518 ldebugfs_add_vars(gss_debugfs_dir, gss_debugfs_vars, NULL);
520 gss_debugfs_dir_lk = debugfs_create_dir("lgss_keyring",
522 ldebugfs_add_vars(gss_debugfs_dir_lk, gss_lk_debugfs_vars, NULL);
524 gss_lprocfs_dir = lprocfs_register("gss", sptlrpc_lprocfs_dir,
525 gss_lprocfs_vars, NULL);
526 if (IS_ERR_OR_NULL(gss_lprocfs_dir)) {
527 rc = gss_lprocfs_dir ? PTR_ERR(gss_lprocfs_dir) : -ENOMEM;
528 gss_lprocfs_dir = NULL;
535 CERROR("failed to initialize gss lproc entries: %d\n", rc);