Blame view

lib/list_debug.c 1.82 KB
199a9afc3   Dave Jones   [PATCH] Debug var...
1
2
3
4
  /*
   * Copyright 2006, Red Hat, Inc., Dave Jones
   * Released under the General Public License (GPL).
   *
d7c816733   Kees Cook   list: Split list_...
5
   * This file contains the linked list validation for DEBUG_LIST.
199a9afc3   Dave Jones   [PATCH] Debug var...
6
   */
8bc3bcc93   Paul Gortmaker   lib: reduce the u...
7
  #include <linux/export.h>
199a9afc3   Dave Jones   [PATCH] Debug var...
8
  #include <linux/list.h>
50af5ead3   Paul Gortmaker   bug.h: add includ...
9
  #include <linux/bug.h>
b116ee4d7   Paul Gortmaker   lib: fix implicit...
10
  #include <linux/kernel.h>
559f9badd   Dave Jones   rcu: List-debug v...
11
  #include <linux/rculist.h>
199a9afc3   Dave Jones   [PATCH] Debug var...
12
13
  
  /*
d7c816733   Kees Cook   list: Split list_...
14
15
16
   * Check that the data structures for the list manipulations are reasonably
   * valid. Failures here indicate memory corruption (and possibly an exploit
   * attempt).
199a9afc3   Dave Jones   [PATCH] Debug var...
17
   */
d7c816733   Kees Cook   list: Split list_...
18
19
  bool __list_add_valid(struct list_head *new, struct list_head *prev,
  		      struct list_head *next)
199a9afc3   Dave Jones   [PATCH] Debug var...
20
  {
85caa95b9   Kees Cook   bug: switch data ...
21
  	if (CHECK_DATA_CORRUPTION(next->prev != prev,
68c1f0820   Matthew Wilcox   lib/list_debug.c:...
22
23
  			"list_add corruption. next->prev should be prev (%px), but was %px. (next=%px).
  ",
85caa95b9   Kees Cook   bug: switch data ...
24
25
  			prev, next->prev, next) ||
  	    CHECK_DATA_CORRUPTION(prev->next != next,
68c1f0820   Matthew Wilcox   lib/list_debug.c:...
26
27
  			"list_add corruption. prev->next should be next (%px), but was %px. (prev=%px).
  ",
85caa95b9   Kees Cook   bug: switch data ...
28
29
  			next, prev->next, prev) ||
  	    CHECK_DATA_CORRUPTION(new == prev || new == next,
68c1f0820   Matthew Wilcox   lib/list_debug.c:...
30
31
  			"list_add double add: new=%px, prev=%px, next=%px.
  ",
85caa95b9   Kees Cook   bug: switch data ...
32
33
  			new, prev, next))
  		return false;
de54ebbe2   Kees Cook   bug: Provide togg...
34

d7c816733   Kees Cook   list: Split list_...
35
  	return true;
199a9afc3   Dave Jones   [PATCH] Debug var...
36
  }
d7c816733   Kees Cook   list: Split list_...
37
  EXPORT_SYMBOL(__list_add_valid);
199a9afc3   Dave Jones   [PATCH] Debug var...
38

0cd340dcb   Kees Cook   list: Split list_...
39
  bool __list_del_entry_valid(struct list_head *entry)
3c18d4de8   Linus Torvalds   Expand CONFIG_DEB...
40
41
42
43
44
  {
  	struct list_head *prev, *next;
  
  	prev = entry->prev;
  	next = entry->next;
85caa95b9   Kees Cook   bug: switch data ...
45
  	if (CHECK_DATA_CORRUPTION(next == LIST_POISON1,
68c1f0820   Matthew Wilcox   lib/list_debug.c:...
46
47
  			"list_del corruption, %px->next is LIST_POISON1 (%px)
  ",
85caa95b9   Kees Cook   bug: switch data ...
48
49
  			entry, LIST_POISON1) ||
  	    CHECK_DATA_CORRUPTION(prev == LIST_POISON2,
68c1f0820   Matthew Wilcox   lib/list_debug.c:...
50
51
  			"list_del corruption, %px->prev is LIST_POISON2 (%px)
  ",
85caa95b9   Kees Cook   bug: switch data ...
52
53
  			entry, LIST_POISON2) ||
  	    CHECK_DATA_CORRUPTION(prev->next != entry,
68c1f0820   Matthew Wilcox   lib/list_debug.c:...
54
55
  			"list_del corruption. prev->next should be %px, but was %px
  ",
85caa95b9   Kees Cook   bug: switch data ...
56
57
  			entry, prev->next) ||
  	    CHECK_DATA_CORRUPTION(next->prev != entry,
68c1f0820   Matthew Wilcox   lib/list_debug.c:...
58
59
  			"list_del corruption. next->prev should be %px, but was %px
  ",
85caa95b9   Kees Cook   bug: switch data ...
60
61
  			entry, next->prev))
  		return false;
0cd340dcb   Kees Cook   list: Split list_...
62
  	return true;
3c18d4de8   Linus Torvalds   Expand CONFIG_DEB...
63

199a9afc3   Dave Jones   [PATCH] Debug var...
64
  }
0cd340dcb   Kees Cook   list: Split list_...
65
  EXPORT_SYMBOL(__list_del_entry_valid);