Back to home page

OSCL-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     if (CHECK_DATA_CORRUPTION(prev == NULL,
0024             "list_add corruption. prev is NULL.\n") ||
0025         CHECK_DATA_CORRUPTION(next == NULL,
0026             "list_add corruption. next is NULL.\n") ||
0027         CHECK_DATA_CORRUPTION(next->prev != prev,
0028             "list_add corruption. next->prev should be prev (%px), but was %px. (next=%px).\n",
0029             prev, next->prev, next) ||
0030         CHECK_DATA_CORRUPTION(prev->next != next,
0031             "list_add corruption. prev->next should be next (%px), but was %px. (prev=%px).\n",
0032             next, prev->next, prev) ||
0033         CHECK_DATA_CORRUPTION(new == prev || new == next,
0034             "list_add double add: new=%px, prev=%px, next=%px.\n",
0035             new, prev, next))
0036         return false;
0037 
0038     return true;
0039 }
0040 EXPORT_SYMBOL(__list_add_valid);
0041 
0042 bool __list_del_entry_valid(struct list_head *entry)
0043 {
0044     struct list_head *prev, *next;
0045 
0046     prev = entry->prev;
0047     next = entry->next;
0048 
0049     if (CHECK_DATA_CORRUPTION(next == NULL,
0050             "list_del corruption, %px->next is NULL\n", entry) ||
0051         CHECK_DATA_CORRUPTION(prev == NULL,
0052             "list_del corruption, %px->prev is NULL\n", entry) ||
0053         CHECK_DATA_CORRUPTION(next == LIST_POISON1,
0054             "list_del corruption, %px->next is LIST_POISON1 (%px)\n",
0055             entry, LIST_POISON1) ||
0056         CHECK_DATA_CORRUPTION(prev == LIST_POISON2,
0057             "list_del corruption, %px->prev is LIST_POISON2 (%px)\n",
0058             entry, LIST_POISON2) ||
0059         CHECK_DATA_CORRUPTION(prev->next != entry,
0060             "list_del corruption. prev->next should be %px, but was %px. (prev=%px)\n",
0061             entry, prev->next, prev) ||
0062         CHECK_DATA_CORRUPTION(next->prev != entry,
0063             "list_del corruption. next->prev should be %px, but was %px. (next=%px)\n",
0064             entry, next->prev, next))
0065         return false;
0066 
0067     return true;
0068 
0069 }
0070 EXPORT_SYMBOL(__list_del_entry_valid);