Back to home page

LXR

 
 

    


0001 /*
0002  * Copyright 2006, Red Hat, Inc., Dave Jones
0003  * Released under the General Public License (GPL).
0004  *
0005  * This file contains the linked list validation for DEBUG_LIST.
0006  */
0007 
0008 #include <linux/export.h>
0009 #include <linux/list.h>
0010 #include <linux/bug.h>
0011 #include <linux/kernel.h>
0012 #include <linux/rculist.h>
0013 
0014 /*
0015  * Check that the data structures for the list manipulations are reasonably
0016  * valid. Failures here indicate memory corruption (and possibly an exploit
0017  * attempt).
0018  */
0019 
0020 bool __list_add_valid(struct list_head *new, struct list_head *prev,
0021               struct list_head *next)
0022 {
0023     CHECK_DATA_CORRUPTION(next->prev != prev,
0024         "list_add corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
0025         prev, next->prev, next);
0026     CHECK_DATA_CORRUPTION(prev->next != next,
0027         "list_add corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
0028         next, prev->next, prev);
0029     CHECK_DATA_CORRUPTION(new == prev || new == next,
0030         "list_add double add: new=%p, prev=%p, next=%p.\n",
0031         new, prev, next);
0032 
0033     return true;
0034 }
0035 EXPORT_SYMBOL(__list_add_valid);
0036 
0037 bool __list_del_entry_valid(struct list_head *entry)
0038 {
0039     struct list_head *prev, *next;
0040 
0041     prev = entry->prev;
0042     next = entry->next;
0043 
0044     CHECK_DATA_CORRUPTION(next == LIST_POISON1,
0045         "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
0046         entry, LIST_POISON1);
0047     CHECK_DATA_CORRUPTION(prev == LIST_POISON2,
0048         "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
0049         entry, LIST_POISON2);
0050     CHECK_DATA_CORRUPTION(prev->next != entry,
0051         "list_del corruption. prev->next should be %p, but was %p\n",
0052         entry, prev->next);
0053     CHECK_DATA_CORRUPTION(next->prev != entry,
0054         "list_del corruption. next->prev should be %p, but was %p\n",
0055         entry, next->prev);
0056     return true;
0057 
0058 }
0059 EXPORT_SYMBOL(__list_del_entry_valid);