summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorChristophe Leroy <christophe.leroy@csgroup.eu>2024-03-08 06:38:07 +0100
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2024-07-05 09:31:47 +0200
commite4f602e3ff749ba770bf8ff10196e18358de6720 (patch)
tree26bc5adbfcc9388171b0d4e53b4e8a07d5226c39 /include
parentefb27ad05949403848f487823b597ed67060e007 (diff)
downloadlinux-e4f602e3ff749ba770bf8ff10196e18358de6720.tar.gz
linux-e4f602e3ff749ba770bf8ff10196e18358de6720.tar.bz2
linux-e4f602e3ff749ba770bf8ff10196e18358de6720.zip
bpf: Take return from set_memory_ro() into account with bpf_prog_lock_ro()
[ Upstream commit 7d2cc63eca0c993c99d18893214abf8f85d566d8 ] set_memory_ro() can fail, leaving memory unprotected. Check its return and take it into account as an error. Link: https://github.com/KSPP/linux/issues/7 Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu> Cc: linux-hardening@vger.kernel.org <linux-hardening@vger.kernel.org> Reviewed-by: Kees Cook <keescook@chromium.org> Message-ID: <286def78955e04382b227cb3e4b6ba272a7442e3.1709850515.git.christophe.leroy@csgroup.eu> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'include')
-rw-r--r--include/linux/filter.h5
1 files changed, 3 insertions, 2 deletions
diff --git a/include/linux/filter.h b/include/linux/filter.h
index face590b24e1..01f97956572c 100644
--- a/include/linux/filter.h
+++ b/include/linux/filter.h
@@ -850,14 +850,15 @@ bpf_ctx_narrow_access_offset(u32 off, u32 size, u32 size_default)
#define bpf_classic_proglen(fprog) (fprog->len * sizeof(fprog->filter[0]))
-static inline void bpf_prog_lock_ro(struct bpf_prog *fp)
+static inline int __must_check bpf_prog_lock_ro(struct bpf_prog *fp)
{
#ifndef CONFIG_BPF_JIT_ALWAYS_ON
if (!fp->jited) {
set_vm_flush_reset_perms(fp);
- set_memory_ro((unsigned long)fp, fp->pages);
+ return set_memory_ro((unsigned long)fp, fp->pages);
}
#endif
+ return 0;
}
static inline void bpf_jit_binary_lock_ro(struct bpf_binary_header *hdr)