Blame view

lib/list_debug.c 1.72 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
  {
de54ebbe2   Kees Cook   bug: Provide togg...
21
22
23
24
25
26
27
28
29
30
31
32
  	CHECK_DATA_CORRUPTION(next->prev != prev,
  		"list_add corruption. next->prev should be prev (%p), but was %p. (next=%p).
  ",
  		prev, next->prev, next);
  	CHECK_DATA_CORRUPTION(prev->next != next,
  		"list_add corruption. prev->next should be next (%p), but was %p. (prev=%p).
  ",
  		next, prev->next, prev);
  	CHECK_DATA_CORRUPTION(new == prev || new == next,
  		"list_add double add: new=%p, prev=%p, next=%p.
  ",
  		new, prev, next);
d7c816733   Kees Cook   list: Split list_...
33
  	return true;
199a9afc3   Dave Jones   [PATCH] Debug var...
34
  }
d7c816733   Kees Cook   list: Split list_...
35
  EXPORT_SYMBOL(__list_add_valid);
199a9afc3   Dave Jones   [PATCH] Debug var...
36

0cd340dcb   Kees Cook   list: Split list_...
37
  bool __list_del_entry_valid(struct list_head *entry)
3c18d4de8   Linus Torvalds   Expand CONFIG_DEB...
38
39
40
41
42
  {
  	struct list_head *prev, *next;
  
  	prev = entry->prev;
  	next = entry->next;
de54ebbe2   Kees Cook   bug: Provide togg...
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
  	CHECK_DATA_CORRUPTION(next == LIST_POISON1,
  		"list_del corruption, %p->next is LIST_POISON1 (%p)
  ",
  		entry, LIST_POISON1);
  	CHECK_DATA_CORRUPTION(prev == LIST_POISON2,
  		"list_del corruption, %p->prev is LIST_POISON2 (%p)
  ",
  		entry, LIST_POISON2);
  	CHECK_DATA_CORRUPTION(prev->next != entry,
  		"list_del corruption. prev->next should be %p, but was %p
  ",
  		entry, prev->next);
  	CHECK_DATA_CORRUPTION(next->prev != entry,
  		"list_del corruption. next->prev should be %p, but was %p
  ",
  		entry, next->prev);
0cd340dcb   Kees Cook   list: Split list_...
59
  	return true;
3c18d4de8   Linus Torvalds   Expand CONFIG_DEB...
60

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