Blame view
lib/list_debug.c
1.82 KB
199a9afc3
|
1 2 3 4 |
/* * Copyright 2006, Red Hat, Inc., Dave Jones * Released under the General Public License (GPL). * |
d7c816733
|
5 |
* This file contains the linked list validation for DEBUG_LIST. |
199a9afc3
|
6 |
*/ |
8bc3bcc93
|
7 |
#include <linux/export.h> |
199a9afc3
|
8 |
#include <linux/list.h> |
50af5ead3
|
9 |
#include <linux/bug.h> |
b116ee4d7
|
10 |
#include <linux/kernel.h> |
559f9badd
|
11 |
#include <linux/rculist.h> |
199a9afc3
|
12 13 |
/* |
d7c816733
|
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
|
17 |
*/ |
d7c816733
|
18 19 |
bool __list_add_valid(struct list_head *new, struct list_head *prev, struct list_head *next) |
199a9afc3
|
20 |
{ |
85caa95b9
|
21 |
if (CHECK_DATA_CORRUPTION(next->prev != prev, |
68c1f0820
|
22 23 |
"list_add corruption. next->prev should be prev (%px), but was %px. (next=%px). ", |
85caa95b9
|
24 25 |
prev, next->prev, next) || CHECK_DATA_CORRUPTION(prev->next != next, |
68c1f0820
|
26 27 |
"list_add corruption. prev->next should be next (%px), but was %px. (prev=%px). ", |
85caa95b9
|
28 29 |
next, prev->next, prev) || CHECK_DATA_CORRUPTION(new == prev || new == next, |
68c1f0820
|
30 31 |
"list_add double add: new=%px, prev=%px, next=%px. ", |
85caa95b9
|
32 33 |
new, prev, next)) return false; |
de54ebbe2
|
34 |
|
d7c816733
|
35 |
return true; |
199a9afc3
|
36 |
} |
d7c816733
|
37 |
EXPORT_SYMBOL(__list_add_valid); |
199a9afc3
|
38 |
|
0cd340dcb
|
39 |
bool __list_del_entry_valid(struct list_head *entry) |
3c18d4de8
|
40 41 42 43 44 |
{ struct list_head *prev, *next; prev = entry->prev; next = entry->next; |
85caa95b9
|
45 |
if (CHECK_DATA_CORRUPTION(next == LIST_POISON1, |
68c1f0820
|
46 47 |
"list_del corruption, %px->next is LIST_POISON1 (%px) ", |
85caa95b9
|
48 49 |
entry, LIST_POISON1) || CHECK_DATA_CORRUPTION(prev == LIST_POISON2, |
68c1f0820
|
50 51 |
"list_del corruption, %px->prev is LIST_POISON2 (%px) ", |
85caa95b9
|
52 53 |
entry, LIST_POISON2) || CHECK_DATA_CORRUPTION(prev->next != entry, |
68c1f0820
|
54 55 |
"list_del corruption. prev->next should be %px, but was %px ", |
85caa95b9
|
56 57 |
entry, prev->next) || CHECK_DATA_CORRUPTION(next->prev != entry, |
68c1f0820
|
58 59 |
"list_del corruption. next->prev should be %px, but was %px ", |
85caa95b9
|
60 61 |
entry, next->prev)) return false; |
0cd340dcb
|
62 |
return true; |
3c18d4de8
|
63 |
|
199a9afc3
|
64 |
} |
0cd340dcb
|
65 |
EXPORT_SYMBOL(__list_del_entry_valid); |