* Re: [PATCH] bpf: whitelist syscalls for error injection
[not found] <20180313231627.1247-1-hmclauchlan@fb.com>
@ 2018-03-13 23:45 ` Omar Sandoval
2018-03-13 23:49 ` Yonghong Song
0 siblings, 1 reply; 3+ messages in thread
From: Omar Sandoval @ 2018-03-13 23:45 UTC (permalink / raw)
To: Howard McLauchlan
Cc: linux-kernel, linux-api, Al Viro, Thomas Gleixner, Yonghong Song,
David S . Miller, Thomas Garnier, kernel-team, Steven Rostedt,
Ingo Molnar, Josef Bacik, Alexei Starovoitov, netdev
On Tue, Mar 13, 2018 at 04:16:27PM -0700, Howard McLauchlan wrote:
> Error injection is a useful mechanism to fail arbitrary kernel
> functions. However, it is often hard to guarantee an error propagates
> appropriately to user space programs. By injecting into syscalls, we can
> return arbitrary values to user space directly; this increases
> flexibility and robustness in testing, allowing us to test user space
> error paths effectively.
>
> The following script, for example, fails calls to sys_open() from a
> given pid:
>
> from bcc import BPF
> from sys import argv
>
> pid = argv[1]
>
> prog = r"""
>
> int kprobe__SyS_open(struct pt_regs *ctx, const char *pathname, int flags)
> {
> u32 pid = bpf_get_current_pid_tgid();
> if (pid == %s)
> bpf_override_return(ctx, -ENOENT);
> return 0;
> }
> """ % pid
>
> b = BPF(text = prog)
> while 1:
> b.perf_buffer_poll()
>
> This patch whitelists all syscalls defined with SYSCALL_DEFINE for error
> injection.
>
> Signed-off-by: Howard McLauchlan <hmclauchlan@fb.com>
> ---
> based on 4.16-rc5
> include/linux/syscalls.h | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
> index a78186d826d7..e8c6d63ace78 100644
> --- a/include/linux/syscalls.h
> +++ b/include/linux/syscalls.h
> @@ -191,6 +191,8 @@ static inline int is_syscall_trace_event(struct trace_event_call *tp_event)
>
> #define SYSCALL_DEFINE0(sname) \
> SYSCALL_METADATA(_##sname, 0); \
> + asmlinkage long sys_##sname(void); \
> + ALLOW_ERROR_INJECTION(sys_##sname, ERRNO); \
> asmlinkage long sys_##sname(void)
>
> #define SYSCALL_DEFINE1(name, ...) SYSCALL_DEFINEx(1, _##name, __VA_ARGS__)
> @@ -210,6 +212,7 @@ static inline int is_syscall_trace_event(struct trace_event_call *tp_event)
> #define __SYSCALL_DEFINEx(x, name, ...) \
> asmlinkage long sys##name(__MAP(x,__SC_DECL,__VA_ARGS__)) \
> __attribute__((alias(__stringify(SyS##name)))); \
> + ALLOW_ERROR_INJECTION(sys##name, ERRNO); \
> static inline long SYSC##name(__MAP(x,__SC_DECL,__VA_ARGS__)); \
> asmlinkage long SyS##name(__MAP(x,__SC_LONG,__VA_ARGS__)); \
> asmlinkage long SyS##name(__MAP(x,__SC_LONG,__VA_ARGS__)) \
> --
> 2.14.1
>
Adding a few more people to Cc
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] bpf: whitelist syscalls for error injection
2018-03-13 23:45 ` [PATCH] bpf: whitelist syscalls for error injection Omar Sandoval
@ 2018-03-13 23:49 ` Yonghong Song
2018-03-14 0:00 ` Howard McLauchlan
0 siblings, 1 reply; 3+ messages in thread
From: Yonghong Song @ 2018-03-13 23:49 UTC (permalink / raw)
To: Omar Sandoval, Howard McLauchlan
Cc: linux-kernel, linux-api, Al Viro, Thomas Gleixner,
David S . Miller, Thomas Garnier, kernel-team, Steven Rostedt,
Ingo Molnar, Josef Bacik, Alexei Starovoitov, netdev
On 3/13/18 4:45 PM, Omar Sandoval wrote:
> On Tue, Mar 13, 2018 at 04:16:27PM -0700, Howard McLauchlan wrote:
>> Error injection is a useful mechanism to fail arbitrary kernel
>> functions. However, it is often hard to guarantee an error propagates
>> appropriately to user space programs. By injecting into syscalls, we can
>> return arbitrary values to user space directly; this increases
>> flexibility and robustness in testing, allowing us to test user space
>> error paths effectively.
>>
>> The following script, for example, fails calls to sys_open() from a
>> given pid:
>>
>> from bcc import BPF
>> from sys import argv
>>
>> pid = argv[1]
>>
>> prog = r"""
>>
>> int kprobe__SyS_open(struct pt_regs *ctx, const char *pathname, int flags)
>> {
>> u32 pid = bpf_get_current_pid_tgid();
>> if (pid == %s)
>> bpf_override_return(ctx, -ENOENT);
>> return 0;
>> }
>> """ % pid
>>
>> b = BPF(text = prog)
>> while 1:
>> b.perf_buffer_poll()
>>
>> This patch whitelists all syscalls defined with SYSCALL_DEFINE for error
>> injection.
>>
>> Signed-off-by: Howard McLauchlan <hmclauchlan@fb.com>
>> ---
>> based on 4.16-rc5
>> include/linux/syscalls.h | 3 +++
>> 1 file changed, 3 insertions(+)
>>
>> diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
>> index a78186d826d7..e8c6d63ace78 100644
>> --- a/include/linux/syscalls.h
>> +++ b/include/linux/syscalls.h
>> @@ -191,6 +191,8 @@ static inline int is_syscall_trace_event(struct trace_event_call *tp_event)
>>
>> #define SYSCALL_DEFINE0(sname) \
>> SYSCALL_METADATA(_##sname, 0); \
>> + asmlinkage long sys_##sname(void); \
>> + ALLOW_ERROR_INJECTION(sys_##sname, ERRNO); \
>> asmlinkage long sys_##sname(void)
duplication of asmlinkage in the above?
>>
>> #define SYSCALL_DEFINE1(name, ...) SYSCALL_DEFINEx(1, _##name, __VA_ARGS__)
>> @@ -210,6 +212,7 @@ static inline int is_syscall_trace_event(struct trace_event_call *tp_event)
>> #define __SYSCALL_DEFINEx(x, name, ...) \
>> asmlinkage long sys##name(__MAP(x,__SC_DECL,__VA_ARGS__)) \
>> __attribute__((alias(__stringify(SyS##name)))); \
>> + ALLOW_ERROR_INJECTION(sys##name, ERRNO); \
>> static inline long SYSC##name(__MAP(x,__SC_DECL,__VA_ARGS__)); \
>> asmlinkage long SyS##name(__MAP(x,__SC_LONG,__VA_ARGS__)); \
>> asmlinkage long SyS##name(__MAP(x,__SC_LONG,__VA_ARGS__)) \
>> --
>> 2.14.1
>>
>
> Adding a few more people to Cc
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] bpf: whitelist syscalls for error injection
2018-03-13 23:49 ` Yonghong Song
@ 2018-03-14 0:00 ` Howard McLauchlan
0 siblings, 0 replies; 3+ messages in thread
From: Howard McLauchlan @ 2018-03-14 0:00 UTC (permalink / raw)
To: Yonghong Song, Omar Sandoval
Cc: linux-kernel, linux-api, Al Viro, Thomas Gleixner,
David S . Miller, Thomas Garnier, kernel-team, Steven Rostedt,
Ingo Molnar, Josef Bacik, Alexei Starovoitov, netdev
On 03/13/2018 04:49 PM, Yonghong Song wrote:
>
>
> On 3/13/18 4:45 PM, Omar Sandoval wrote:
>> On Tue, Mar 13, 2018 at 04:16:27PM -0700, Howard McLauchlan wrote:
>>> Error injection is a useful mechanism to fail arbitrary kernel
>>> functions. However, it is often hard to guarantee an error propagates
>>> appropriately to user space programs. By injecting into syscalls, we can
>>> return arbitrary values to user space directly; this increases
>>> flexibility and robustness in testing, allowing us to test user space
>>> error paths effectively.
>>>
>>> The following script, for example, fails calls to sys_open() from a
>>> given pid:
>>>
>>> from bcc import BPF
>>> from sys import argv
>>>
>>> pid = argv[1]
>>>
>>> prog = r"""
>>>
>>> int kprobe__SyS_open(struct pt_regs *ctx, const char *pathname, int flags)
>>> {
>>> u32 pid = bpf_get_current_pid_tgid();
>>> if (pid == %s)
>>> bpf_override_return(ctx, -ENOENT);
>>> return 0;
>>> }
>>> """ % pid
>>>
>>> b = BPF(text = prog)
>>> while 1:
>>> b.perf_buffer_poll()
>>>
>>> This patch whitelists all syscalls defined with SYSCALL_DEFINE for error
>>> injection.
>>>
>>> Signed-off-by: Howard McLauchlan <hmclauchlan@fb.com>
>>> ---
>>> based on 4.16-rc5
>>> include/linux/syscalls.h | 3 +++
>>> 1 file changed, 3 insertions(+)
>>>
>>> diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
>>> index a78186d826d7..e8c6d63ace78 100644
>>> --- a/include/linux/syscalls.h
>>> +++ b/include/linux/syscalls.h
>>> @@ -191,6 +191,8 @@ static inline int is_syscall_trace_event(struct trace_event_call *tp_event)
>>> #define SYSCALL_DEFINE0(sname) \
>>> SYSCALL_METADATA(_##sname, 0); \
>>> + asmlinkage long sys_##sname(void); \
>>> + ALLOW_ERROR_INJECTION(sys_##sname, ERRNO); \
>>> asmlinkage long sys_##sname(void)
>
> duplication of asmlinkage in the above?
>
The pre-declaration is necessary to ensure ALLOW_ERROR_INJECTION works appropriately. There can be syscalls
that are not pre-declared elsewhere which will fail compilation if not declared in this block.
>>> #define SYSCALL_DEFINE1(name, ...) SYSCALL_DEFINEx(1, _##name, __VA_ARGS__)
>>> @@ -210,6 +212,7 @@ static inline int is_syscall_trace_event(struct trace_event_call *tp_event)
>>> #define __SYSCALL_DEFINEx(x, name, ...) \
>>> asmlinkage long sys##name(__MAP(x,__SC_DECL,__VA_ARGS__)) \
>>> __attribute__((alias(__stringify(SyS##name)))); \
>>> + ALLOW_ERROR_INJECTION(sys##name, ERRNO); \
>>> static inline long SYSC##name(__MAP(x,__SC_DECL,__VA_ARGS__)); \
>>> asmlinkage long SyS##name(__MAP(x,__SC_LONG,__VA_ARGS__)); \
>>> asmlinkage long SyS##name(__MAP(x,__SC_LONG,__VA_ARGS__)) \
>>> --
>>> 2.14.1
>>>
>>
>> Adding a few more people to Cc
>>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-03-14 0:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20180313231627.1247-1-hmclauchlan@fb.com>
2018-03-13 23:45 ` [PATCH] bpf: whitelist syscalls for error injection Omar Sandoval
2018-03-13 23:49 ` Yonghong Song
2018-03-14 0:00 ` Howard McLauchlan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).