bpf: Prevent memory disambiguation attack
[linux/fpc-iii.git] / drivers / firmware / google / coreboot_table.c
blob0019d3ec18dd4979dadb2cb6c9b3f2d5d3fde0fa
1 /*
2 * coreboot_table.c
4 * Module providing coreboot table access.
6 * Copyright 2017 Google Inc.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License v2.0 as published by
10 * the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
18 #include <linux/err.h>
19 #include <linux/init.h>
20 #include <linux/io.h>
21 #include <linux/kernel.h>
22 #include <linux/module.h>
24 #include "coreboot_table.h"
26 struct coreboot_table_entry {
27 u32 tag;
28 u32 size;
31 static struct coreboot_table_header __iomem *ptr_header;
34 * This function parses the coreboot table for an entry that contains the base
35 * address of the given entry tag. The coreboot table consists of a header
36 * directly followed by a number of small, variable-sized entries, which each
37 * contain an identifying tag and their length as the first two fields.
39 int coreboot_table_find(int tag, void *data, size_t data_size)
41 struct coreboot_table_header header;
42 struct coreboot_table_entry entry;
43 void *ptr_entry;
44 int i;
46 if (!ptr_header)
47 return -EPROBE_DEFER;
49 memcpy_fromio(&header, ptr_header, sizeof(header));
51 if (strncmp(header.signature, "LBIO", sizeof(header.signature))) {
52 pr_warn("coreboot_table: coreboot table missing or corrupt!\n");
53 return -ENODEV;
56 ptr_entry = (void *)ptr_header + header.header_bytes;
58 for (i = 0; i < header.table_entries; i++) {
59 memcpy_fromio(&entry, ptr_entry, sizeof(entry));
60 if (entry.tag == tag) {
61 if (data_size < entry.size)
62 return -EINVAL;
64 memcpy_fromio(data, ptr_entry, entry.size);
66 return 0;
69 ptr_entry += entry.size;
72 return -ENOENT;
74 EXPORT_SYMBOL(coreboot_table_find);
76 int coreboot_table_init(void __iomem *ptr)
78 ptr_header = ptr;
80 return 0;
82 EXPORT_SYMBOL(coreboot_table_init);
84 int coreboot_table_exit(void)
86 if (ptr_header)
87 iounmap(ptr_header);
89 return 0;
91 EXPORT_SYMBOL(coreboot_table_exit);
93 MODULE_AUTHOR("Google, Inc.");
94 MODULE_LICENSE("GPL");