All of lore.kernel.org
 help / color / mirror / Atom feed
* [BUGFIX PATCH bpf-next] error-injection: Fix to prohibit jump optimization
@ 2018-03-12 10:00 Masami Hiramatsu
  2018-03-12 10:27 ` Masami Hiramatsu
  0 siblings, 1 reply; 5+ messages in thread
From: Masami Hiramatsu @ 2018-03-12 10:00 UTC (permalink / raw)
  To: Alexei Starovoitov, Josef Bacik
  Cc: rostedt, mingo, davem, netdev, linux-kernel, ast, kernel-team,
	daniel, linux-btrfs, darrick.wong, mhiramat, Josef Bacik,
	Akinobu Mita

Since the kprobe which was optimized by jump can not change
the execution path, the kprobe for error-injection must not
be optimized. To prohibit it, set a dummy post-handler as
officially stated in Documentation/kprobes.txt.

Fixes: 4b1a29a7f542 ("error-injection: Support fault injection framework")
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
 kernel/fail_function.c |   10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/kernel/fail_function.c b/kernel/fail_function.c
index 21b0122cb39c..1d5632d8bbcc 100644
--- a/kernel/fail_function.c
+++ b/kernel/fail_function.c
@@ -14,6 +14,15 @@
 
 static int fei_kprobe_handler(struct kprobe *kp, struct pt_regs *regs);
 
+static void fei_post_handler(struct kprobe *kp, struct pt_regs *regs,
+			     unsigned long flags)
+{
+	/*
+	 * A dummy post handler is required to prohibit optimizing, because
+	 * jump optimization does not support execution path overriding.
+	 */
+}
+
 struct fei_attr {
 	struct list_head list;
 	struct kprobe kp;
@@ -56,6 +65,7 @@ static struct fei_attr *fei_attr_new(const char *sym, unsigned long addr)
 			return NULL;
 		}
 		attr->kp.pre_handler = fei_kprobe_handler;
+		attr->kp.post_handler = fei_post_handler;
 		attr->retval = adjust_error_retval(addr, 0);
 		INIT_LIST_HEAD(&attr->list);
 	}


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [BUGFIX PATCH bpf-next] error-injection: Fix to prohibit jump optimization
  2018-03-12 10:00 [BUGFIX PATCH bpf-next] error-injection: Fix to prohibit jump optimization Masami Hiramatsu
@ 2018-03-12 10:27 ` Masami Hiramatsu
  2018-03-12 10:44   ` Daniel Borkmann
  0 siblings, 1 reply; 5+ messages in thread
From: Masami Hiramatsu @ 2018-03-12 10:27 UTC (permalink / raw)
  To: Masami Hiramatsu
  Cc: Alexei Starovoitov, Josef Bacik, rostedt, mingo, davem, netdev,
	linux-kernel, ast, kernel-team, daniel, linux-btrfs,
	darrick.wong, Josef Bacik, Akinobu Mita

On Mon, 12 Mar 2018 19:00:49 +0900
Masami Hiramatsu <mhiramat@kernel.org> wrote:

> Since the kprobe which was optimized by jump can not change
> the execution path, the kprobe for error-injection must not
> be optimized. To prohibit it, set a dummy post-handler as
> officially stated in Documentation/kprobes.txt.

Note that trace-probe based BPF is not affected, because it
ensures the trace-probe is based on ftrace, which is not
jump optimized.

Thanks,

> 
> Fixes: 4b1a29a7f542 ("error-injection: Support fault injection framework")
> Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
> ---
>  kernel/fail_function.c |   10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/kernel/fail_function.c b/kernel/fail_function.c
> index 21b0122cb39c..1d5632d8bbcc 100644
> --- a/kernel/fail_function.c
> +++ b/kernel/fail_function.c
> @@ -14,6 +14,15 @@
>  
>  static int fei_kprobe_handler(struct kprobe *kp, struct pt_regs *regs);
>  
> +static void fei_post_handler(struct kprobe *kp, struct pt_regs *regs,
> +			     unsigned long flags)
> +{
> +	/*
> +	 * A dummy post handler is required to prohibit optimizing, because
> +	 * jump optimization does not support execution path overriding.
> +	 */
> +}
> +
>  struct fei_attr {
>  	struct list_head list;
>  	struct kprobe kp;
> @@ -56,6 +65,7 @@ static struct fei_attr *fei_attr_new(const char *sym, unsigned long addr)
>  			return NULL;
>  		}
>  		attr->kp.pre_handler = fei_kprobe_handler;
> +		attr->kp.post_handler = fei_post_handler;
>  		attr->retval = adjust_error_retval(addr, 0);
>  		INIT_LIST_HEAD(&attr->list);
>  	}
> 


-- 
Masami Hiramatsu <mhiramat@kernel.org>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [BUGFIX PATCH bpf-next] error-injection: Fix to prohibit jump optimization
  2018-03-12 10:27 ` Masami Hiramatsu
@ 2018-03-12 10:44   ` Daniel Borkmann
  2018-03-12 14:06     ` Masami Hiramatsu
  0 siblings, 1 reply; 5+ messages in thread
From: Daniel Borkmann @ 2018-03-12 10:44 UTC (permalink / raw)
  To: Masami Hiramatsu
  Cc: Alexei Starovoitov, Josef Bacik, rostedt, mingo, davem, netdev,
	linux-kernel, ast, kernel-team, linux-btrfs, darrick.wong,
	Josef Bacik, Akinobu Mita

Hi Masami,

On 03/12/2018 11:27 AM, Masami Hiramatsu wrote:
> On Mon, 12 Mar 2018 19:00:49 +0900
> Masami Hiramatsu <mhiramat@kernel.org> wrote:
> 
>> Since the kprobe which was optimized by jump can not change
>> the execution path, the kprobe for error-injection must not
>> be optimized. To prohibit it, set a dummy post-handler as
>> officially stated in Documentation/kprobes.txt.
> 
> Note that trace-probe based BPF is not affected, because it
> ensures the trace-probe is based on ftrace, which is not
> jump optimized.

Thanks for the fix! I presume this should go via bpf instead of bpf-next
tree since 4b1a29a7f542 ("error-injection: Support fault injection framework")
is in Linus' tree as well. Unless there are objection I would rather route
it that way so it would be for 4.16.

Thanks,
Daniel

> Thanks,
> 
>>
>> Fixes: 4b1a29a7f542 ("error-injection: Support fault injection framework")
>> Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
>> ---
>>  kernel/fail_function.c |   10 ++++++++++
>>  1 file changed, 10 insertions(+)
>>
>> diff --git a/kernel/fail_function.c b/kernel/fail_function.c
>> index 21b0122cb39c..1d5632d8bbcc 100644
>> --- a/kernel/fail_function.c
>> +++ b/kernel/fail_function.c
>> @@ -14,6 +14,15 @@
>>  
>>  static int fei_kprobe_handler(struct kprobe *kp, struct pt_regs *regs);
>>  
>> +static void fei_post_handler(struct kprobe *kp, struct pt_regs *regs,
>> +			     unsigned long flags)
>> +{
>> +	/*
>> +	 * A dummy post handler is required to prohibit optimizing, because
>> +	 * jump optimization does not support execution path overriding.
>> +	 */
>> +}
>> +
>>  struct fei_attr {
>>  	struct list_head list;
>>  	struct kprobe kp;
>> @@ -56,6 +65,7 @@ static struct fei_attr *fei_attr_new(const char *sym, unsigned long addr)
>>  			return NULL;
>>  		}
>>  		attr->kp.pre_handler = fei_kprobe_handler;
>> +		attr->kp.post_handler = fei_post_handler;
>>  		attr->retval = adjust_error_retval(addr, 0);
>>  		INIT_LIST_HEAD(&attr->list);
>>  	}
>>
> 
> 


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [BUGFIX PATCH bpf-next] error-injection: Fix to prohibit jump optimization
  2018-03-12 10:44   ` Daniel Borkmann
@ 2018-03-12 14:06     ` Masami Hiramatsu
  2018-03-12 15:21       ` Daniel Borkmann
  0 siblings, 1 reply; 5+ messages in thread
From: Masami Hiramatsu @ 2018-03-12 14:06 UTC (permalink / raw)
  To: Daniel Borkmann
  Cc: Alexei Starovoitov, Josef Bacik, rostedt, mingo, davem, netdev,
	linux-kernel, ast, kernel-team, linux-btrfs, darrick.wong,
	Josef Bacik, Akinobu Mita

On Mon, 12 Mar 2018 11:44:21 +0100
Daniel Borkmann <daniel@iogearbox.net> wrote:

> Hi Masami,
> 
> On 03/12/2018 11:27 AM, Masami Hiramatsu wrote:
> > On Mon, 12 Mar 2018 19:00:49 +0900
> > Masami Hiramatsu <mhiramat@kernel.org> wrote:
> > 
> >> Since the kprobe which was optimized by jump can not change
> >> the execution path, the kprobe for error-injection must not
> >> be optimized. To prohibit it, set a dummy post-handler as
> >> officially stated in Documentation/kprobes.txt.
> > 
> > Note that trace-probe based BPF is not affected, because it
> > ensures the trace-probe is based on ftrace, which is not
> > jump optimized.
> 
> Thanks for the fix! I presume this should go via bpf instead of bpf-next
> tree since 4b1a29a7f542 ("error-injection: Support fault injection framework")
> is in Linus' tree as well. Unless there are objection I would rather route
> it that way so it would be for 4.16.

Ah, right! It should go into 4.16. It should be applicable cleanly either tree
since there is only the above commit on kernel/fail_function.c :)

Thanks,

> 
> Thanks,
> Daniel
> 
> > Thanks,
> > 
> >>
> >> Fixes: 4b1a29a7f542 ("error-injection: Support fault injection framework")
> >> Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
> >> ---
> >>  kernel/fail_function.c |   10 ++++++++++
> >>  1 file changed, 10 insertions(+)
> >>
> >> diff --git a/kernel/fail_function.c b/kernel/fail_function.c
> >> index 21b0122cb39c..1d5632d8bbcc 100644
> >> --- a/kernel/fail_function.c
> >> +++ b/kernel/fail_function.c
> >> @@ -14,6 +14,15 @@
> >>  
> >>  static int fei_kprobe_handler(struct kprobe *kp, struct pt_regs *regs);
> >>  
> >> +static void fei_post_handler(struct kprobe *kp, struct pt_regs *regs,
> >> +			     unsigned long flags)
> >> +{
> >> +	/*
> >> +	 * A dummy post handler is required to prohibit optimizing, because
> >> +	 * jump optimization does not support execution path overriding.
> >> +	 */
> >> +}
> >> +
> >>  struct fei_attr {
> >>  	struct list_head list;
> >>  	struct kprobe kp;
> >> @@ -56,6 +65,7 @@ static struct fei_attr *fei_attr_new(const char *sym, unsigned long addr)
> >>  			return NULL;
> >>  		}
> >>  		attr->kp.pre_handler = fei_kprobe_handler;
> >> +		attr->kp.post_handler = fei_post_handler;
> >>  		attr->retval = adjust_error_retval(addr, 0);
> >>  		INIT_LIST_HEAD(&attr->list);
> >>  	}
> >>
> > 
> > 
> 


-- 
Masami Hiramatsu <mhiramat@kernel.org>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [BUGFIX PATCH bpf-next] error-injection: Fix to prohibit jump optimization
  2018-03-12 14:06     ` Masami Hiramatsu
@ 2018-03-12 15:21       ` Daniel Borkmann
  0 siblings, 0 replies; 5+ messages in thread
From: Daniel Borkmann @ 2018-03-12 15:21 UTC (permalink / raw)
  To: Masami Hiramatsu
  Cc: Alexei Starovoitov, Josef Bacik, rostedt, mingo, davem, netdev,
	linux-kernel, ast, kernel-team, linux-btrfs, darrick.wong,
	Josef Bacik, Akinobu Mita

On 03/12/2018 03:06 PM, Masami Hiramatsu wrote:
> On Mon, 12 Mar 2018 11:44:21 +0100
> Daniel Borkmann <daniel@iogearbox.net> wrote:
>> On 03/12/2018 11:27 AM, Masami Hiramatsu wrote:
>>> On Mon, 12 Mar 2018 19:00:49 +0900
>>> Masami Hiramatsu <mhiramat@kernel.org> wrote:
>>>
>>>> Since the kprobe which was optimized by jump can not change
>>>> the execution path, the kprobe for error-injection must not
>>>> be optimized. To prohibit it, set a dummy post-handler as
>>>> officially stated in Documentation/kprobes.txt.
>>>
>>> Note that trace-probe based BPF is not affected, because it
>>> ensures the trace-probe is based on ftrace, which is not
>>> jump optimized.
>>
>> Thanks for the fix! I presume this should go via bpf instead of bpf-next
>> tree since 4b1a29a7f542 ("error-injection: Support fault injection framework")
>> is in Linus' tree as well. Unless there are objection I would rather route
>> it that way so it would be for 4.16.
> 
> Ah, right! It should go into 4.16. It should be applicable cleanly either tree
> since there is only the above commit on kernel/fail_function.c :)

Applied to bpf tree, thanks Masami!

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-03-12 15:21 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-12 10:00 [BUGFIX PATCH bpf-next] error-injection: Fix to prohibit jump optimization Masami Hiramatsu
2018-03-12 10:27 ` Masami Hiramatsu
2018-03-12 10:44   ` Daniel Borkmann
2018-03-12 14:06     ` Masami Hiramatsu
2018-03-12 15:21       ` Daniel Borkmann

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.