Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2)  * Copyright 2006, Red Hat, Inc., Dave Jones
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3)  * Released under the General Public License (GPL).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5)  * This file contains the linked list validation for DEBUG_LIST.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/bug.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/rculist.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)  * Check that the data structures for the list manipulations are reasonably
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)  * valid. Failures here indicate memory corruption (and possibly an exploit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)  * attempt).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) bool __list_add_valid(struct list_head *new, struct list_head *prev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) 		      struct list_head *next)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) 	if (CHECK_DATA_CORRUPTION(next->prev != prev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) 			"list_add corruption. next->prev should be prev (%px), but was %px. (next=%px).\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) 			prev, next->prev, next) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) 	    CHECK_DATA_CORRUPTION(prev->next != next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) 			"list_add corruption. prev->next should be next (%px), but was %px. (prev=%px).\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) 			next, prev->next, prev) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) 	    CHECK_DATA_CORRUPTION(new == prev || new == next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) 			"list_add double add: new=%px, prev=%px, next=%px.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) 			new, prev, next))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) 	return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) EXPORT_SYMBOL(__list_add_valid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) bool __list_del_entry_valid(struct list_head *entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) 	struct list_head *prev, *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) 	prev = entry->prev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) 	next = entry->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) 	if (CHECK_DATA_CORRUPTION(next == LIST_POISON1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) 			"list_del corruption, %px->next is LIST_POISON1 (%px)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) 			entry, LIST_POISON1) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) 	    CHECK_DATA_CORRUPTION(prev == LIST_POISON2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) 			"list_del corruption, %px->prev is LIST_POISON2 (%px)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) 			entry, LIST_POISON2) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) 	    CHECK_DATA_CORRUPTION(prev->next != entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) 			"list_del corruption. prev->next should be %px, but was %px\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) 			entry, prev->next) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) 	    CHECK_DATA_CORRUPTION(next->prev != entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) 			"list_del corruption. next->prev should be %px, but was %px\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) 			entry, next->prev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) 	return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) EXPORT_SYMBOL(__list_del_entry_valid);