shadow.c (3c206509826094e85ead0b056f484db96829248d) shadow.c (ce732a7520b093091c345cba1b84542d1abd83ed)
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * KMSAN shadow implementation.
4 *
5 * Copyright (C) 2017-2022 Google LLC
6 * Author: Alexander Potapenko <glider@google.com>
7 *
8 */
9
10#include <asm/kmsan.h>
11#include <asm/tlbflush.h>
12#include <linux/cacheflush.h>
13#include <linux/memblock.h>
14#include <linux/mm_types.h>
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * KMSAN shadow implementation.
4 *
5 * Copyright (C) 2017-2022 Google LLC
6 * Author: Alexander Potapenko <glider@google.com>
7 *
8 */
9
10#include <asm/kmsan.h>
11#include <asm/tlbflush.h>
12#include <linux/cacheflush.h>
13#include <linux/memblock.h>
14#include <linux/mm_types.h>
15#include <linux/percpu-defs.h>
16#include <linux/slab.h>
17#include <linux/smp.h>
18#include <linux/stddef.h>
19
20#include "../internal.h"
21#include "kmsan.h"
22
23#define shadow_page_for(page) ((page)->kmsan_shadow)

--- 97 unchanged lines hidden (view full) ---

121 * none. The caller must check the return value for being non-NULL if needed.
122 * The return value of this function should not depend on whether we're in the
123 * runtime or not.
124 */
125void *kmsan_get_metadata(void *address, bool is_origin)
126{
127 u64 addr = (u64)address, pad, off;
128 struct page *page;
15#include <linux/slab.h>
16#include <linux/smp.h>
17#include <linux/stddef.h>
18
19#include "../internal.h"
20#include "kmsan.h"
21
22#define shadow_page_for(page) ((page)->kmsan_shadow)

--- 97 unchanged lines hidden (view full) ---

120 * none. The caller must check the return value for being non-NULL if needed.
121 * The return value of this function should not depend on whether we're in the
122 * runtime or not.
123 */
124void *kmsan_get_metadata(void *address, bool is_origin)
125{
126 u64 addr = (u64)address, pad, off;
127 struct page *page;
128 void *ret;
129
130 if (is_origin && !IS_ALIGNED(addr, KMSAN_ORIGIN_SIZE)) {
131 pad = addr % KMSAN_ORIGIN_SIZE;
132 addr -= pad;
133 }
134 address = (void *)addr;
135 if (kmsan_internal_is_vmalloc_addr(address) ||
136 kmsan_internal_is_module_addr(address))
137 return (void *)vmalloc_meta(address, is_origin);
138
129
130 if (is_origin && !IS_ALIGNED(addr, KMSAN_ORIGIN_SIZE)) {
131 pad = addr % KMSAN_ORIGIN_SIZE;
132 addr -= pad;
133 }
134 address = (void *)addr;
135 if (kmsan_internal_is_vmalloc_addr(address) ||
136 kmsan_internal_is_module_addr(address))
137 return (void *)vmalloc_meta(address, is_origin);
138
139 ret = arch_kmsan_get_meta_or_null(address, is_origin);
140 if (ret)
141 return ret;
142
139 page = virt_to_page_or_null(address);
140 if (!page)
141 return NULL;
142 if (!page_has_metadata(page))
143 return NULL;
144 off = addr % PAGE_SIZE;
145
146 return (is_origin ? origin_ptr_for(page) : shadow_ptr_for(page)) + off;

--- 148 unchanged lines hidden ---
143 page = virt_to_page_or_null(address);
144 if (!page)
145 return NULL;
146 if (!page_has_metadata(page))
147 return NULL;
148 off = addr % PAGE_SIZE;
149
150 return (is_origin ? origin_ptr_for(page) : shadow_ptr_for(page)) + off;

--- 148 unchanged lines hidden ---