forked from torvalds/linux
Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
uaccess-buffer: add core code
Add the core code to support uaccess logging. Subsequent patches will hook this up to the arch-specific kernel entry and exit code for certain architectures. Link: https://linux-review.googlesource.com/id/I6581765646501a5631b281d670903945ebadc57d Signed-off-by: Peter Collingbourne <pcc@google.com>
- Loading branch information
1 parent
e3924f1
commit e050ed271bb00085068f2c9b6790c2e071154629
Showing
14 changed files
with
324 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| /* SPDX-License-Identifier: GPL-2.0 */ | ||
| #ifndef _LINUX_UACCESS_BUFFER_LOG_HOOKS_H | ||
| #define _LINUX_UACCESS_BUFFER_LOG_HOOKS_H | ||
|
|
||
| #ifdef CONFIG_HAVE_ARCH_UACCESS_BUFFER | ||
|
|
||
| struct uaccess_buffer_info { | ||
| /* | ||
| * The pointer to pointer to struct uaccess_descriptor. This is the | ||
| * value controlled by prctl(PR_SET_UACCESS_DESCRIPTOR_ADDR_ADDR). | ||
| */ | ||
| struct uaccess_descriptor __user *__user *desc_ptr_ptr; | ||
|
|
||
| /* | ||
| * The pointer to struct uaccess_descriptor read at syscall entry time. | ||
| */ | ||
| struct uaccess_descriptor __user *desc_ptr; | ||
|
|
||
| /* | ||
| * A pointer to the kernel's temporary copy of the uaccess log for the | ||
| * current syscall. We log to a kernel buffer in order to avoid leaking | ||
| * timing information to userspace. | ||
| */ | ||
| struct uaccess_buffer_entry *kbegin; | ||
|
|
||
| /* | ||
| * The position of the next uaccess buffer entry for the current | ||
| * syscall. | ||
| */ | ||
| struct uaccess_buffer_entry *kcur; | ||
|
|
||
| /* | ||
| * A pointer to the end of the kernel's uaccess log. | ||
| */ | ||
| struct uaccess_buffer_entry *kend; | ||
|
|
||
| /* | ||
| * The pointer to the userspace uaccess log, as read from the | ||
| * struct uaccess_descriptor. | ||
| */ | ||
| struct uaccess_buffer_entry __user *ubegin; | ||
| }; | ||
|
|
||
| void uaccess_buffer_log_read(const void __user *from, unsigned long n); | ||
| void uaccess_buffer_log_write(void __user *to, unsigned long n); | ||
|
|
||
| #else | ||
|
|
||
| static inline void uaccess_buffer_log_read(const void __user *from, | ||
| unsigned long n) | ||
| { | ||
| } | ||
| static inline void uaccess_buffer_log_write(void __user *to, unsigned long n) | ||
| { | ||
| } | ||
|
|
||
| #endif | ||
|
|
||
| #endif /* _LINUX_UACCESS_BUFFER_LOG_HOOKS_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| /* SPDX-License-Identifier: GPL-2.0 */ | ||
| #ifndef _LINUX_UACCESS_BUFFER_H | ||
| #define _LINUX_UACCESS_BUFFER_H | ||
|
|
||
| #include <linux/sched.h> | ||
| #include <uapi/linux/uaccess-buffer.h> | ||
|
|
||
| #include <asm-generic/errno-base.h> | ||
|
|
||
| #ifdef CONFIG_HAVE_ARCH_UACCESS_BUFFER | ||
|
|
||
| static inline bool uaccess_buffer_maybe_blocked(struct task_struct *tsk) | ||
| { | ||
| return tsk->uaccess_buffer.desc_ptr_ptr; | ||
| } | ||
|
|
||
| void __uaccess_buffer_syscall_entry(void); | ||
| static inline void uaccess_buffer_syscall_entry(void) | ||
| { | ||
| if (uaccess_buffer_maybe_blocked(current)) | ||
| __uaccess_buffer_syscall_entry(); | ||
| } | ||
|
|
||
| void __uaccess_buffer_syscall_exit(void); | ||
| static inline void uaccess_buffer_syscall_exit(void) | ||
| { | ||
| if (uaccess_buffer_maybe_blocked(current)) | ||
| __uaccess_buffer_syscall_exit(); | ||
| } | ||
|
|
||
| bool __uaccess_buffer_pre_exit_loop(void); | ||
| static inline bool uaccess_buffer_pre_exit_loop(void) | ||
| { | ||
| if (!uaccess_buffer_maybe_blocked(current)) | ||
| return false; | ||
| return __uaccess_buffer_pre_exit_loop(); | ||
| } | ||
|
|
||
| void __uaccess_buffer_post_exit_loop(void); | ||
| static inline void uaccess_buffer_post_exit_loop(bool pending) | ||
| { | ||
| if (pending) | ||
| __uaccess_buffer_post_exit_loop(); | ||
| } | ||
|
|
||
| void uaccess_buffer_cancel_log(struct task_struct *tsk); | ||
| int uaccess_buffer_set_descriptor_addr_addr(unsigned long addr); | ||
|
|
||
| #else | ||
|
|
||
| static inline bool uaccess_buffer_maybe_blocked(struct task_struct *tsk) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| static inline void uaccess_buffer_syscall_entry(void) | ||
| { | ||
| } | ||
| static inline void uaccess_buffer_syscall_exit(void) | ||
| { | ||
| } | ||
| static inline bool uaccess_buffer_pre_exit_loop(void) | ||
| { | ||
| return false; | ||
| } | ||
| static inline void uaccess_buffer_post_exit_loop(bool pending) | ||
| { | ||
| } | ||
| static inline void uaccess_buffer_cancel_log(struct task_struct *tsk) | ||
| { | ||
| } | ||
|
|
||
| static inline int uaccess_buffer_set_descriptor_addr_addr(unsigned long addr) | ||
| { | ||
| return -EINVAL; | ||
| } | ||
| #endif | ||
|
|
||
| #endif /* _LINUX_UACCESS_BUFFER_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ | ||
| #ifndef _UAPI_LINUX_UACCESS_BUFFER_H | ||
| #define _UAPI_LINUX_UACCESS_BUFFER_H | ||
|
|
||
| /* Location of the uaccess log. */ | ||
| struct uaccess_descriptor { | ||
| /* Address of the uaccess_buffer_entry array. */ | ||
| __u64 addr; | ||
| /* Size of the uaccess_buffer_entry array in number of elements. */ | ||
| __u64 size; | ||
| }; | ||
|
|
||
| /* Format of the entries in the uaccess log. */ | ||
| struct uaccess_buffer_entry { | ||
| /* Address being accessed. */ | ||
| __u64 addr; | ||
| /* Number of bytes that were accessed. */ | ||
| __u64 size; | ||
| /* UACCESS_BUFFER_* flags. */ | ||
| __u64 flags; | ||
| }; | ||
|
|
||
| #define UACCESS_BUFFER_FLAG_WRITE 1 /* access was a write */ | ||
|
|
||
| #endif /* _UAPI_LINUX_UACCESS_BUFFER_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.