Skip to content

Commit

Permalink
[PATCH] fault-injection: Clamp debugfs stacktrace-depth to MAX_STACK_…
Browse files Browse the repository at this point in the history
…TRACE_DEPTH

Clamp /debug/fail*/stacktrace-depth to MAX_STACK_TRACE_DEPTH.  Ensures that a
read of /debug/fail*/stacktrace-depth always returns a truthful answer.

Signed-off-by: Don Mullis <dwm@meer.net>
Cc: Akinobu Mita <akinobu.mita@gmail.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
  • Loading branch information
Don Mullis authored and Linus Torvalds committed Dec 8, 2006
1 parent 08b3df2 commit a124c28
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions lib/fault-inject.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ static bool fail_task(struct fault_attr *attr, struct task_struct *task)
return !in_interrupt() && task->make_it_fail;
}

#define MAX_STACK_TRACE_DEPTH 32

#ifdef CONFIG_STACK_UNWIND

static asmlinkage int fail_stacktrace_callback(struct unwind_frame_info *info,
Expand Down Expand Up @@ -98,8 +100,7 @@ static bool fail_stacktrace(struct fault_attr *attr)

trace.nr_entries = 0;
trace.entries = entries;
trace.max_entries = (depth < MAX_STACK_TRACE_DEPTH) ?
depth : MAX_STACK_TRACE_DEPTH;
trace.max_entries = depth;
trace.skip = 1;
trace.all_contexts = 0;

Expand Down Expand Up @@ -179,6 +180,13 @@ static void debugfs_ul_set(void *data, u64 val)
*(unsigned long *)data = val;
}

static void debugfs_ul_set_MAX_STACK_TRACE_DEPTH(void *data, u64 val)
{
*(unsigned long *)data =
val < MAX_STACK_TRACE_DEPTH ?
val : MAX_STACK_TRACE_DEPTH;
}

static u64 debugfs_ul_get(void *data)
{
return *(unsigned long *)data;
Expand All @@ -192,6 +200,17 @@ static struct dentry *debugfs_create_ul(const char *name, mode_t mode,
return debugfs_create_file(name, mode, parent, value, &fops_ul);
}

DEFINE_SIMPLE_ATTRIBUTE(fops_ul_MAX_STACK_TRACE_DEPTH, debugfs_ul_get,
debugfs_ul_set_MAX_STACK_TRACE_DEPTH, "%llu\n");

static struct dentry *debugfs_create_ul_MAX_STACK_TRACE_DEPTH(
const char *name, mode_t mode,
struct dentry *parent, unsigned long *value)
{
return debugfs_create_file(name, mode, parent, value,
&fops_ul_MAX_STACK_TRACE_DEPTH);
}

static void debugfs_atomic_t_set(void *data, u64 val)
{
atomic_set((atomic_t *)data, val);
Expand Down Expand Up @@ -284,8 +303,8 @@ int init_fault_attr_dentries(struct fault_attr *attr, const char *name)
mode, dir, &attr->task_filter);

attr->dentries.stacktrace_depth_file =
debugfs_create_ul("stacktrace-depth", mode, dir,
&attr->stacktrace_depth);
debugfs_create_ul_MAX_STACK_TRACE_DEPTH(
"stacktrace-depth", mode, dir, &attr->stacktrace_depth);

attr->dentries.require_start_file =
debugfs_create_ul("require-start", mode, dir, &attr->require_start);
Expand Down

0 comments on commit a124c28

Please sign in to comment.