Commit 9637c3f318374e2fcc37e354f9782a705b517387

Authored by Michael Holzheu
Committed by Heiko Carstens
1 parent 9f7819c1e5

[S390] Add debug_register_mode() function to debug feature API

The new function supports setting of permissions for the debugfs files
created by the debug feature. In addition to that, the function provides
uid and gid as parameters for future use. Currently only root is allowed
for uid and gid.

Signed-off-by: Michael Holzheu <holzheu@de.ibm.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>

Showing 3 changed files with 64 additions and 13 deletions Side-by-side Diff

Documentation/s390/s390dbf.txt
... ... @@ -115,6 +115,27 @@
115 115 Description: Allocates memory for a debug log
116 116 Must not be called within an interrupt handler
117 117  
  118 +----------------------------------------------------------------------------
  119 +debug_info_t *debug_register_mode(char *name, int pages, int nr_areas,
  120 + int buf_size, mode_t mode, uid_t uid,
  121 + gid_t gid);
  122 +
  123 +Parameter: name: Name of debug log (e.g. used for debugfs entry)
  124 + pages: Number of pages, which will be allocated per area
  125 + nr_areas: Number of debug areas
  126 + buf_size: Size of data area in each debug entry
  127 + mode: File mode for debugfs files. E.g. S_IRWXUGO
  128 + uid: User ID for debugfs files. Currently only 0 is
  129 + supported.
  130 + gid: Group ID for debugfs files. Currently only 0 is
  131 + supported.
  132 +
  133 +Return Value: Handle for generated debug area
  134 + NULL if register failed
  135 +
  136 +Description: Allocates memory for a debug log
  137 + Must not be called within an interrupt handler
  138 +
118 139 ---------------------------------------------------------------------------
119 140 void debug_unregister (debug_info_t * id);
120 141  
arch/s390/kernel/debug.c
... ... @@ -73,7 +73,7 @@
73 73 static int debug_open(struct inode *inode, struct file *file);
74 74 static int debug_close(struct inode *inode, struct file *file);
75 75 static debug_info_t* debug_info_create(char *name, int pages_per_area,
76   - int nr_areas, int buf_size);
  76 + int nr_areas, int buf_size, mode_t mode);
77 77 static void debug_info_get(debug_info_t *);
78 78 static void debug_info_put(debug_info_t *);
79 79 static int debug_prolog_level_fn(debug_info_t * id,
... ... @@ -327,7 +327,8 @@
327 327 */
328 328  
329 329 static debug_info_t*
330   -debug_info_create(char *name, int pages_per_area, int nr_areas, int buf_size)
  330 +debug_info_create(char *name, int pages_per_area, int nr_areas, int buf_size,
  331 + mode_t mode)
331 332 {
332 333 debug_info_t* rc;
333 334  
... ... @@ -336,6 +337,8 @@
336 337 if(!rc)
337 338 goto out;
338 339  
  340 + rc->mode = mode & ~S_IFMT;
  341 +
339 342 /* create root directory */
340 343 rc->debugfs_root_entry = debugfs_create_dir(rc->name,
341 344 debug_debugfs_root_entry);
342 345  
343 346  
344 347  
... ... @@ -676,23 +679,30 @@
676 679 }
677 680  
678 681 /*
679   - * debug_register:
680   - * - creates and initializes debug area for the caller
681   - * - returns handle for debug area
  682 + * debug_register_mode:
  683 + * - Creates and initializes debug area for the caller
  684 + * The mode parameter allows to specify access rights for the s390dbf files
  685 + * - Returns handle for debug area
682 686 */
683 687  
684   -debug_info_t*
685   -debug_register (char *name, int pages_per_area, int nr_areas, int buf_size)
  688 +debug_info_t *debug_register_mode(char *name, int pages_per_area, int nr_areas,
  689 + int buf_size, mode_t mode, uid_t uid,
  690 + gid_t gid)
686 691 {
687 692 debug_info_t *rc = NULL;
688 693  
  694 + /* Since debugfs currently does not support uid/gid other than root, */
  695 + /* we do not allow gid/uid != 0 until we get support for that. */
  696 + if ((uid != 0) || (gid != 0))
  697 + printk(KERN_WARNING "debug: Warning - Currently only uid/gid "
  698 + "= 0 are supported. Using root as owner now!");
689 699 if (!initialized)
690 700 BUG();
691 701 mutex_lock(&debug_mutex);
692 702  
693 703 /* create new debug_info */
694 704  
695   - rc = debug_info_create(name, pages_per_area, nr_areas, buf_size);
  705 + rc = debug_info_create(name, pages_per_area, nr_areas, buf_size, mode);
696 706 if(!rc)
697 707 goto out;
698 708 debug_register_view(rc, &debug_level_view);
699 709  
... ... @@ -705,8 +715,22 @@
705 715 mutex_unlock(&debug_mutex);
706 716 return rc;
707 717 }
  718 +EXPORT_SYMBOL(debug_register_mode);
708 719  
709 720 /*
  721 + * debug_register:
  722 + * - creates and initializes debug area for the caller
  723 + * - returns handle for debug area
  724 + */
  725 +
  726 +debug_info_t *debug_register(char *name, int pages_per_area, int nr_areas,
  727 + int buf_size)
  728 +{
  729 + return debug_register_mode(name, pages_per_area, nr_areas, buf_size,
  730 + S_IRUSR | S_IWUSR, 0, 0);
  731 +}
  732 +
  733 +/*
710 734 * debug_unregister:
711 735 * - give back debug area
712 736 */
713 737  
... ... @@ -1073,15 +1097,16 @@
1073 1097 int rc = 0;
1074 1098 int i;
1075 1099 unsigned long flags;
1076   - mode_t mode = S_IFREG;
  1100 + mode_t mode;
1077 1101 struct dentry *pde;
1078 1102  
1079 1103 if (!id)
1080 1104 goto out;
1081   - if (view->prolog_proc || view->format_proc || view->header_proc)
1082   - mode |= S_IRUSR;
1083   - if (view->input_proc)
1084   - mode |= S_IWUSR;
  1105 + mode = (id->mode | S_IFREG) & ~S_IXUGO;
  1106 + if (!(view->prolog_proc || view->format_proc || view->header_proc))
  1107 + mode &= ~(S_IRUSR | S_IRGRP | S_IROTH);
  1108 + if (!view->input_proc)
  1109 + mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH);
1085 1110 pde = debugfs_create_file(view->name, mode, id->debugfs_root_entry,
1086 1111 id , &debug_file_ops);
1087 1112 if (!pde){
include/asm-s390/debug.h
... ... @@ -73,6 +73,7 @@
73 73 struct dentry* debugfs_entries[DEBUG_MAX_VIEWS];
74 74 struct debug_view* views[DEBUG_MAX_VIEWS];
75 75 char name[DEBUG_MAX_NAME_LEN];
  76 + mode_t mode;
76 77 } debug_info_t;
77 78  
78 79 typedef int (debug_header_proc_t) (debug_info_t* id,
... ... @@ -121,6 +122,10 @@
121 122  
122 123 debug_info_t* debug_register(char* name, int pages, int nr_areas,
123 124 int buf_size);
  125 +
  126 +debug_info_t *debug_register_mode(char *name, int pages, int nr_areas,
  127 + int buf_size, mode_t mode, uid_t uid,
  128 + gid_t gid);
124 129  
125 130 void debug_unregister(debug_info_t* id);
126 131