VisionFive2 Linux kernel

StarFive Tech Linux Kernel for VisionFive (JH7110) boards (mirror)

More than 9999 Commits   32 Branches   54 Tags
199a9afc3dbe9 (Dave Jones     2006-09-29 01:59:00 -0700  1) /*
199a9afc3dbe9 (Dave Jones     2006-09-29 01:59:00 -0700  2)  * Copyright 2006, Red Hat, Inc., Dave Jones
199a9afc3dbe9 (Dave Jones     2006-09-29 01:59:00 -0700  3)  * Released under the General Public License (GPL).
199a9afc3dbe9 (Dave Jones     2006-09-29 01:59:00 -0700  4)  *
d7c816733d501 (Kees Cook      2016-08-17 14:42:08 -0700  5)  * This file contains the linked list validation for DEBUG_LIST.
199a9afc3dbe9 (Dave Jones     2006-09-29 01:59:00 -0700  6)  */
199a9afc3dbe9 (Dave Jones     2006-09-29 01:59:00 -0700  7) 
8bc3bcc93a2b4 (Paul Gortmaker 2011-11-16 21:29:17 -0500  8) #include <linux/export.h>
199a9afc3dbe9 (Dave Jones     2006-09-29 01:59:00 -0700  9) #include <linux/list.h>
50af5ead3b44c (Paul Gortmaker 2012-01-20 18:35:53 -0500 10) #include <linux/bug.h>
b116ee4d77256 (Paul Gortmaker 2012-01-20 18:46:49 -0500 11) #include <linux/kernel.h>
559f9badd11dd (Dave Jones     2012-03-14 22:17:39 -0400 12) #include <linux/rculist.h>
199a9afc3dbe9 (Dave Jones     2006-09-29 01:59:00 -0700 13) 
199a9afc3dbe9 (Dave Jones     2006-09-29 01:59:00 -0700 14) /*
d7c816733d501 (Kees Cook      2016-08-17 14:42:08 -0700 15)  * Check that the data structures for the list manipulations are reasonably
d7c816733d501 (Kees Cook      2016-08-17 14:42:08 -0700 16)  * valid. Failures here indicate memory corruption (and possibly an exploit
d7c816733d501 (Kees Cook      2016-08-17 14:42:08 -0700 17)  * attempt).
199a9afc3dbe9 (Dave Jones     2006-09-29 01:59:00 -0700 18)  */
199a9afc3dbe9 (Dave Jones     2006-09-29 01:59:00 -0700 19) 
d7c816733d501 (Kees Cook      2016-08-17 14:42:08 -0700 20) bool __list_add_valid(struct list_head *new, struct list_head *prev,
d7c816733d501 (Kees Cook      2016-08-17 14:42:08 -0700 21) 		      struct list_head *next)
199a9afc3dbe9 (Dave Jones     2006-09-29 01:59:00 -0700 22) {
85caa95b9f19b (Kees Cook      2017-02-24 15:00:38 -0800 23) 	if (CHECK_DATA_CORRUPTION(next->prev != prev,
68c1f08203f2b (Matthew Wilcox 2018-04-10 16:33:06 -0700 24) 			"list_add corruption. next->prev should be prev (%px), but was %px. (next=%px).\n",
85caa95b9f19b (Kees Cook      2017-02-24 15:00:38 -0800 25) 			prev, next->prev, next) ||
85caa95b9f19b (Kees Cook      2017-02-24 15:00:38 -0800 26) 	    CHECK_DATA_CORRUPTION(prev->next != next,
68c1f08203f2b (Matthew Wilcox 2018-04-10 16:33:06 -0700 27) 			"list_add corruption. prev->next should be next (%px), but was %px. (prev=%px).\n",
85caa95b9f19b (Kees Cook      2017-02-24 15:00:38 -0800 28) 			next, prev->next, prev) ||
85caa95b9f19b (Kees Cook      2017-02-24 15:00:38 -0800 29) 	    CHECK_DATA_CORRUPTION(new == prev || new == next,
68c1f08203f2b (Matthew Wilcox 2018-04-10 16:33:06 -0700 30) 			"list_add double add: new=%px, prev=%px, next=%px.\n",
85caa95b9f19b (Kees Cook      2017-02-24 15:00:38 -0800 31) 			new, prev, next))
85caa95b9f19b (Kees Cook      2017-02-24 15:00:38 -0800 32) 		return false;
de54ebbe26bb3 (Kees Cook      2016-08-17 14:42:11 -0700 33) 
d7c816733d501 (Kees Cook      2016-08-17 14:42:08 -0700 34) 	return true;
199a9afc3dbe9 (Dave Jones     2006-09-29 01:59:00 -0700 35) }
d7c816733d501 (Kees Cook      2016-08-17 14:42:08 -0700 36) EXPORT_SYMBOL(__list_add_valid);
199a9afc3dbe9 (Dave Jones     2006-09-29 01:59:00 -0700 37) 
0cd340dcb05c4 (Kees Cook      2016-08-17 14:42:10 -0700 38) bool __list_del_entry_valid(struct list_head *entry)
3c18d4de86e4a (Linus Torvalds 2011-02-18 11:32:28 -0800 39) {
3c18d4de86e4a (Linus Torvalds 2011-02-18 11:32:28 -0800 40) 	struct list_head *prev, *next;
3c18d4de86e4a (Linus Torvalds 2011-02-18 11:32:28 -0800 41) 
3c18d4de86e4a (Linus Torvalds 2011-02-18 11:32:28 -0800 42) 	prev = entry->prev;
3c18d4de86e4a (Linus Torvalds 2011-02-18 11:32:28 -0800 43) 	next = entry->next;
3c18d4de86e4a (Linus Torvalds 2011-02-18 11:32:28 -0800 44) 
85caa95b9f19b (Kees Cook      2017-02-24 15:00:38 -0800 45) 	if (CHECK_DATA_CORRUPTION(next == LIST_POISON1,
68c1f08203f2b (Matthew Wilcox 2018-04-10 16:33:06 -0700 46) 			"list_del corruption, %px->next is LIST_POISON1 (%px)\n",
85caa95b9f19b (Kees Cook      2017-02-24 15:00:38 -0800 47) 			entry, LIST_POISON1) ||
85caa95b9f19b (Kees Cook      2017-02-24 15:00:38 -0800 48) 	    CHECK_DATA_CORRUPTION(prev == LIST_POISON2,
68c1f08203f2b (Matthew Wilcox 2018-04-10 16:33:06 -0700 49) 			"list_del corruption, %px->prev is LIST_POISON2 (%px)\n",
85caa95b9f19b (Kees Cook      2017-02-24 15:00:38 -0800 50) 			entry, LIST_POISON2) ||
85caa95b9f19b (Kees Cook      2017-02-24 15:00:38 -0800 51) 	    CHECK_DATA_CORRUPTION(prev->next != entry,
68c1f08203f2b (Matthew Wilcox 2018-04-10 16:33:06 -0700 52) 			"list_del corruption. prev->next should be %px, but was %px\n",
85caa95b9f19b (Kees Cook      2017-02-24 15:00:38 -0800 53) 			entry, prev->next) ||
85caa95b9f19b (Kees Cook      2017-02-24 15:00:38 -0800 54) 	    CHECK_DATA_CORRUPTION(next->prev != entry,
68c1f08203f2b (Matthew Wilcox 2018-04-10 16:33:06 -0700 55) 			"list_del corruption. next->prev should be %px, but was %px\n",
85caa95b9f19b (Kees Cook      2017-02-24 15:00:38 -0800 56) 			entry, next->prev))
85caa95b9f19b (Kees Cook      2017-02-24 15:00:38 -0800 57) 		return false;
85caa95b9f19b (Kees Cook      2017-02-24 15:00:38 -0800 58) 
0cd340dcb05c4 (Kees Cook      2016-08-17 14:42:10 -0700 59) 	return true;
3c18d4de86e4a (Linus Torvalds 2011-02-18 11:32:28 -0800 60) 
199a9afc3dbe9 (Dave Jones     2006-09-29 01:59:00 -0700 61) }
0cd340dcb05c4 (Kees Cook      2016-08-17 14:42:10 -0700 62) EXPORT_SYMBOL(__list_del_entry_valid);