diff mbox series

[1/2] kernel-shark: Execute kshark-record from same dir as kshark-su-record

Message ID 20190723225238.701263380@goodmis.org (mailing list archive)
State Accepted
Commit 8eb0d753e658446b584b367a45edbc4884ec8bb5
Headers show
Series kernel-shark: Be more careful with kshark-su-record | expand

Commit Message

Steven Rostedt July 23, 2019, 10:50 p.m. UTC
From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>

Do not trust the PATH environment variable (and in fact that may not even be
available with the pkexec). Instead, use the same path as kshark-su-record
to find kshark-record. They should always be together anyway.

Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 kernel-shark/bin/kshark-su-record | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Yordan Karadzhov July 25, 2019, 9:01 a.m. UTC | #1
On 24.07.19 г. 1:50 ч., Steven Rostedt wrote:
> From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>
> 
> Do not trust the PATH environment variable (and in fact that may not even be
> available with the pkexec). Instead, use the same path as kshark-su-record
> to find kshark-record. They should always be together anyway.
> 
> Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
> ---
>   kernel-shark/bin/kshark-su-record | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/kernel-shark/bin/kshark-su-record b/kernel-shark/bin/kshark-su-record
> index 2477045f1710..7faff1cb3339 100755
> --- a/kernel-shark/bin/kshark-su-record
> +++ b/kernel-shark/bin/kshark-su-record
> @@ -5,4 +5,5 @@ then
>       xhost +si:localuser:root &>/dev/null
>   fi
>   
> -pkexec kshark-record -o ${PWD}/trace.dat
> +THIS_DIR=`dirname $0`
> +pkexec ${THIS_DIR}/kshark-record -o ${PWD}/trace.dat
> 

I just realized that there is one problem with the patch. With this 
modification, you can use only the installed version of the script (so 
you more or less depend on PATH).

This will work:
  kshark-su-record

This will work as well:
  /usr/local/bin/kshark-su-record

However this will not work:
  kernel-shark/bin/kshark-su-record

because you are trying to start with pkexec an executable from your $HOME

Thanks!
Yordan
Steven Rostedt July 25, 2019, 12:45 p.m. UTC | #2
On Thu, 25 Jul 2019 12:01:34 +0300
"Yordan Karadzhov (VMware)" <y.karadz@gmail.com> wrote:


> I just realized that there is one problem with the patch. With this 
> modification, you can use only the installed version of the script (so 
> you more or less depend on PATH).
> 
> This will work:
>   kshark-su-record
> 
> This will work as well:
>   /usr/local/bin/kshark-su-record
> 
> However this will not work:
>   kernel-shark/bin/kshark-su-record
> 
> because you are trying to start with pkexec an executable from your $HOME

What about this patch?

-- Steve

diff --git a/kernel-shark/bin/kshark-su-record b/kernel-shark/bin/kshark-su-record
index 8c9fbd02a351..152d0cdff3e7 100755
--- a/kernel-shark/bin/kshark-su-record
+++ b/kernel-shark/bin/kshark-su-record
@@ -6,4 +6,8 @@ then
 fi
 
 THIS_DIR=`dirname $0`
+if [ "${THIS_DIR#/}" == "${THIS_DIR}" ]
+then
+    THIS_DIR=`pwd`"/$THIS_DIR"
+fi
 pkexec env DISPLAY=${DISPLAY} ${THIS_DIR}/kshark-record -o ${PWD}/trace.dat
Yordan Karadzhov July 25, 2019, 1:59 p.m. UTC | #3
On 25.07.19 г. 15:45 ч., Steven Rostedt wrote:
> On Thu, 25 Jul 2019 12:01:34 +0300
> "Yordan Karadzhov (VMware)" <y.karadz@gmail.com> wrote:
> 
> 
>> I just realized that there is one problem with the patch. With this
>> modification, you can use only the installed version of the script (so
>> you more or less depend on PATH).
>>
>> This will work:
>>    kshark-su-record
>>
>> This will work as well:
>>    /usr/local/bin/kshark-su-record
>>
>> However this will not work:
>>    kernel-shark/bin/kshark-su-record
>>
>> because you are trying to start with pkexec an executable from your $HOME
> 
> What about this patch?
> 
> -- Steve
> 
> diff --git a/kernel-shark/bin/kshark-su-record b/kernel-shark/bin/kshark-su-record
> index 8c9fbd02a351..152d0cdff3e7 100755
> --- a/kernel-shark/bin/kshark-su-record
> +++ b/kernel-shark/bin/kshark-su-record
> @@ -6,4 +6,8 @@ then
>   fi
>   
>   THIS_DIR=`dirname $0`
> +if [ "${THIS_DIR#/}" == "${THIS_DIR}" ]
> +then
> +    THIS_DIR=`pwd`"/$THIS_DIR"
> +fi
>   pkexec env DISPLAY=${DISPLAY} ${THIS_DIR}/kshark-record -o ${PWD}/trace.dat
> 

I see that this works, however now I am really confused why it works.

I thought that pkexec will start an executable only from the path 
provided in

kernel-shark/org.freedesktop.kshark-record.policy

Thanks!
Yordan
Yordan Karadzhov July 25, 2019, 2 p.m. UTC | #4
On 25.07.19 г. 15:45 ч., Steven Rostedt wrote:
> On Thu, 25 Jul 2019 12:01:34 +0300
> "Yordan Karadzhov (VMware)" <y.karadz@gmail.com> wrote:
> 
> 
>> I just realized that there is one problem with the patch. With this
>> modification, you can use only the installed version of the script (so
>> you more or less depend on PATH).
>>
>> This will work:
>>    kshark-su-record
>>
>> This will work as well:
>>    /usr/local/bin/kshark-su-record
>>
>> However this will not work:
>>    kernel-shark/bin/kshark-su-record
>>
>> because you are trying to start with pkexec an executable from your $HOME
> 
> What about this patch?
> 
> -- Steve
> 
> diff --git a/kernel-shark/bin/kshark-su-record b/kernel-shark/bin/kshark-su-record
> index 8c9fbd02a351..152d0cdff3e7 100755
> --- a/kernel-shark/bin/kshark-su-record
> +++ b/kernel-shark/bin/kshark-su-record
> @@ -6,4 +6,8 @@ then
>   fi
>   
>   THIS_DIR=`dirname $0`
> +if [ "${THIS_DIR#/}" == "${THIS_DIR}" ]
> +then
> +    THIS_DIR=`pwd`"/$THIS_DIR"
> +fi
>   pkexec env DISPLAY=${DISPLAY} ${THIS_DIR}/kshark-record -o ${PWD}/trace.dat
> 

I see that this works, however now I am really confused why it works.

I thought that pkexec will start an executable only from the path 
provided in

kernel-shark/org.freedesktop.kshark-record.policy

Thanks!
Yordan
diff mbox series

Patch

diff --git a/kernel-shark/bin/kshark-su-record b/kernel-shark/bin/kshark-su-record
index 2477045f1710..7faff1cb3339 100755
--- a/kernel-shark/bin/kshark-su-record
+++ b/kernel-shark/bin/kshark-su-record
@@ -5,4 +5,5 @@  then
     xhost +si:localuser:root &>/dev/null
 fi
 
-pkexec kshark-record -o ${PWD}/trace.dat
+THIS_DIR=`dirname $0`
+pkexec ${THIS_DIR}/kshark-record -o ${PWD}/trace.dat