Skip to content

Commit c576edd

Browse files
tli16gregkh
authored andcommitted
drivers/misc: sram-exec: have the callers of set_memory_*() check the return value
Right now several architectures allow their set_memory_*() family of functions to fail, but callers may not be checking the return values. If set_memory_*() returns with an error, call-site assumptions may be infact wrong to assume that it would either succeed or not succeed at all. Ideally, the failure of set_memory_*() should be passed up the call stack, and callers should examine the failure and deal with it. Need to fix the callers and add the __must_check attribute. They also may not provide any level of atomicity, in the sense that the memory protections may be left incomplete on failure. This issue likely has a few steps on effects architectures: 1) Have all callers of set_memory_*() helpers check the return value. 2) Add __must_check to all set_memory_*() helpers so that new uses do not ignore the return value. 3) Add atomicity to the calls so that the memory protections aren't left in a partial state. This series is part of step 1. Make sram driver check the return value of set_memory_*(). Signed-off-by: Tianlin Li <tli@digitalocean.com> Reviewed-by: Kees Cook <keescook@chromium.org> Link: https://lore.kernel.org/r/20191217194528.16461-1-tli@digitalocean.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 2523816 commit c576edd

1 file changed

Lines changed: 17 additions & 4 deletions

File tree

‎drivers/misc/sram-exec.c‎

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ void *sram_exec_copy(struct gen_pool *pool, void *dst, void *src,
8585
unsigned long base;
8686
int pages;
8787
void *dst_cpy;
88+
int ret;
8889

8990
mutex_lock(&exec_pool_list_mutex);
9091
list_for_each_entry(p, &exec_pool_list, list) {
@@ -104,16 +105,28 @@ void *sram_exec_copy(struct gen_pool *pool, void *dst, void *src,
104105

105106
mutex_lock(&part->lock);
106107

107-
set_memory_nx((unsigned long)base, pages);
108-
set_memory_rw((unsigned long)base, pages);
108+
ret = set_memory_nx((unsigned long)base, pages);
109+
if (ret)
110+
goto error_out;
111+
ret = set_memory_rw((unsigned long)base, pages);
112+
if (ret)
113+
goto error_out;
109114

110115
dst_cpy = fncpy(dst, src, size);
111116

112-
set_memory_ro((unsigned long)base, pages);
113-
set_memory_x((unsigned long)base, pages);
117+
ret = set_memory_ro((unsigned long)base, pages);
118+
if (ret)
119+
goto error_out;
120+
ret = set_memory_x((unsigned long)base, pages);
121+
if (ret)
122+
goto error_out;
114123

115124
mutex_unlock(&part->lock);
116125

117126
return dst_cpy;
127+
128+
error_out:
129+
mutex_unlock(&part->lock);
130+
return NULL;
118131
}
119132
EXPORT_SYMBOL_GPL(sram_exec_copy);

0 commit comments

Comments
 (0)