public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Are there any changes to the access control to /proc/<PID>/fd/1 in cygwin 3?
@ 2019-06-15 18:28 Till Riedel
  2019-06-16 15:42 ` Brian Inglis
  0 siblings, 1 reply; 4+ messages in thread
From: Till Riedel @ 2019-06-15 18:28 UTC (permalink / raw)
  To: cygwin

Hi,

I have been using a very handy sudo hack, that broke lately (I think) 
when updating cygwin: https://github.com/imachug/win-sudo

The trick is to spawn an elevated process using powershell and hook up 
the calling file descripters. I now get "write error: Bad file descriptor"

To reproduce call:

powershell.exe Start-Process bash  \"-c\",\"\'echo \>\>/proc/$$/fd/1 hello world\;sleep 10\'\"

IMHO this used to work in former versions (print out hello world on the 
calling shell). Strangely

bash -c "echo >/proc/$$/fd/1 hello world"

works. So my initial guess is that is has to do with the decoupling of 
Cygwin PIDs from Windows PIDs, but there were also changes in the proc 
file system...

Thanks a lot in advance for any help/thoughts!

BR

Till


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

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

* Re: Are there any changes to the access control to /proc/<PID>/fd/1 in cygwin 3?
  2019-06-15 18:28 Are there any changes to the access control to /proc/<PID>/fd/1 in cygwin 3? Till Riedel
@ 2019-06-16 15:42 ` Brian Inglis
  2019-06-20 19:49   ` Till Riedel [TM]
  0 siblings, 1 reply; 4+ messages in thread
From: Brian Inglis @ 2019-06-16 15:42 UTC (permalink / raw)
  To: cygwin

On 2019-06-15 12:27, Till Riedel wrote:
> I have been using a very handy sudo hack, that broke lately (I think) when
> updating cygwin: https://github.com/imachug/win-sudo
> The trick is to spawn an elevated process using powershell and hook up the
> calling file descripters. I now get "write error: Bad file descriptor"
> To reproduce call:
> powershell.exe Start-Process bash  \"-c\",\"\'echo \>\>/proc/$$/fd/1 hello
> world\;sleep 10\'\"
> IMHO this used to work in former versions (print out hello world on the calling
> shell). Strangely
> bash -c "echo >/proc/$$/fd/1 hello world"
> works. So my initial guess is that is has to do with the decoupling of Cygwin
> PIDs from Windows PIDs, but there were also changes in the proc file system...
> Thanks a lot in advance for any help/thoughts!

Given:
$ bash -c 'ls -dglo /dev/std* /proc/self /proc/$$ /proc/self/fd/[012]'
lrwxrwxrwx 1 15 May 14  2013 /dev/stderr -> /proc/self/fd/2
lrwxrwxrwx 1 15 May 14  2013 /dev/stdin -> /proc/self/fd/0
lrwxrwxrwx 1 15 May 14  2013 /dev/stdout -> /proc/self/fd/1
dr-xr-xr-x 3  0 Jun 16 01:37 /proc/23846
lrwxrwxrwx 1  0 Jun 16 01:37 /proc/self -> 23846
lrwxrwxrwx 1  0 Jun 16 01:37 /proc/self/fd/0 -> /dev/pty0
lrwxrwxrwx 1  0 Jun 16 01:37 /proc/self/fd/1 -> /dev/pty0
lrwxrwxrwx 1  0 Jun 16 01:37 /proc/self/fd/2 -> /dev/pty0

the following seems to work as expected:
$ powershell Start-Process bash  \"-c\",\"\'echo \>\>/dev/stdout hello
world\;sleep 10\'\"

-- 
Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada

This email may be disturbing to some readers as it contains
too much technical detail. Reader discretion is advised.

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

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

* Re: Re: Are there any changes to the access control to /proc/<PID>/fd/1 in cygwin 3?
  2019-06-16 15:42 ` Brian Inglis
@ 2019-06-20 19:49   ` Till Riedel [TM]
  2019-06-20 20:09     ` Till Riedel [TM]
  0 siblings, 1 reply; 4+ messages in thread
From: Till Riedel [TM] @ 2019-06-20 19:49 UTC (permalink / raw)
  To: cygwin

Hi Brian,

thanks for the reply.

But proc/$$/fd/1 references the callers  stdout and not the callees as 
/dev/stdout or /proc/self/fd/2 if called from eg. from bash, because it 
is expanded before the call.

What I was able to do is to inject messages into the callers stdout and 
read from the callers stdin, which is when executing under elevated 
priviledges (the behaviour you would want for a sudo).

As said echo >/proc/$$/fd/1 hello world is not the problem and works 
fine as you said as well. (I probably should not have said strangely in 
the first place, because it is a whole different deal...)

BR

Till



Brian Inglis @ 16.06.2019 (17:42) :
> On 2019-06-15 12:27, Till Riedel wrote:
>> I have been using a very handy sudo hack, that broke lately (I think) when
>> updating cygwin: https://github.com/imachug/win-sudo
>> The trick is to spawn an elevated process using powershell and hook up the
>> calling file descripters. I now get "write error: Bad file descriptor"
>> To reproduce call:
>> powershell.exe Start-Process bash  \"-c\",\"\'echo \>\>/proc/$$/fd/1 hello
>> world\;sleep 10\'\"
>> IMHO this used to work in former versions (print out hello world on the calling
>> shell). Strangely
>> bash -c "echo >/proc/$$/fd/1 hello world"
>> works. So my initial guess is that is has to do with the decoupling of Cygwin
>> PIDs from Windows PIDs, but there were also changes in the proc file system...
>> Thanks a lot in advance for any help/thoughts!
> Given:
> $ bash -c 'ls -dglo /dev/std* /proc/self /proc/$$ /proc/self/fd/[012]'
> lrwxrwxrwx 1 15 May 14  2013 /dev/stderr -> /proc/self/fd/2
> lrwxrwxrwx 1 15 May 14  2013 /dev/stdin -> /proc/self/fd/0
> lrwxrwxrwx 1 15 May 14  2013 /dev/stdout -> /proc/self/fd/1
> dr-xr-xr-x 3  0 Jun 16 01:37 /proc/23846
> lrwxrwxrwx 1  0 Jun 16 01:37 /proc/self -> 23846
> lrwxrwxrwx 1  0 Jun 16 01:37 /proc/self/fd/0 -> /dev/pty0
> lrwxrwxrwx 1  0 Jun 16 01:37 /proc/self/fd/1 -> /dev/pty0
> lrwxrwxrwx 1  0 Jun 16 01:37 /proc/self/fd/2 -> /dev/pty0
>
> the following seems to work as expected:
> $ powershell Start-Process bash  \"-c\",\"\'echo \>\>/dev/stdout hello
> world\;sleep 10\'\"
>
-- 
KIT- Research University in the Helmholtz Association

Dr.-Ing. Till Riedel
Lab Leader TECO, SDSC-BW/SDIL (AR)

Karlsruhe Institute of Technology (KIT)
Institute of Telematics (TM)
Pervasive Computing Systems - Prof. Beigl


Bldg. 07.07., Room 211
Vincenz Prießnitz Str. 1, 76131 Karlsruhe

+49 (0)721 608 41706
www.teco.kit.edu/~riedel


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

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

* Re: Are there any changes to the access control to /proc/<PID>/fd/1 in cygwin 3?
  2019-06-20 19:49   ` Till Riedel [TM]
@ 2019-06-20 20:09     ` Till Riedel [TM]
  0 siblings, 0 replies; 4+ messages in thread
From: Till Riedel [TM] @ 2019-06-20 20:09 UTC (permalink / raw)
  To: cygwin

Hi Brian,

you actually hinted me at sth. : powershell.exe Start-Process bash  
\"-c\",\"\'echo hello world  \>`readlink /proc/$$/fd/1`\;sleep 10\'\" 
works as well.

I verified this:

 >echo hello >/proc/3235/fd/0
-bash: echo: write error: Bad file descriptor

 >echo hello >`readlink /proc/3235/fd/0`
works!?

Am I missing sth about symlinks?

BR

Till

Till Riedel [TM] @ 20.06.2019 (21:49) :
> Hi Brian,
>
> thanks for the reply.
>
> But proc/$$/fd/1 references the callers  stdout and not the callees as 
> /dev/stdout or /proc/self/fd/2 if called from eg. from bash, because 
> it is expanded before the call.
>
> What I was able to do is to inject messages into the callers stdout 
> and read from the callers stdin, which is when executing under 
> elevated priviledges (the behaviour you would want for a sudo).
>
> As said echo >/proc/$$/fd/1 hello world is not the problem and works 
> fine as you said as well. (I probably should not have said strangely 
> in the first place, because it is a whole different deal...)
>
> BR
>
> Till
>
>
>
> Brian Inglis @ 16.06.2019 (17:42) :
>> On 2019-06-15 12:27, Till Riedel wrote:
>>> I have been using a very handy sudo hack, that broke lately (I 
>>> think) when
>>> updating cygwin: https://github.com/imachug/win-sudo
>>> The trick is to spawn an elevated process using powershell and hook 
>>> up the
>>> calling file descripters. I now get "write error: Bad file descriptor"
>>> To reproduce call:
>>> powershell.exe Start-Process bash  \"-c\",\"\'echo \>\>/proc/$$/fd/1 
>>> hello
>>> world\;sleep 10\'\"
>>> IMHO this used to work in former versions (print out hello world on 
>>> the calling
>>> shell). Strangely
>>> bash -c "echo >/proc/$$/fd/1 hello world"
>>> works. So my initial guess is that is has to do with the decoupling 
>>> of Cygwin
>>> PIDs from Windows PIDs, but there were also changes in the proc file 
>>> system...
>>> Thanks a lot in advance for any help/thoughts!
>> Given:
>> $ bash -c 'ls -dglo /dev/std* /proc/self /proc/$$ /proc/self/fd/[012]'
>> lrwxrwxrwx 1 15 May 14  2013 /dev/stderr -> /proc/self/fd/2
>> lrwxrwxrwx 1 15 May 14  2013 /dev/stdin -> /proc/self/fd/0
>> lrwxrwxrwx 1 15 May 14  2013 /dev/stdout -> /proc/self/fd/1
>> dr-xr-xr-x 3  0 Jun 16 01:37 /proc/23846
>> lrwxrwxrwx 1  0 Jun 16 01:37 /proc/self -> 23846
>> lrwxrwxrwx 1  0 Jun 16 01:37 /proc/self/fd/0 -> /dev/pty0
>> lrwxrwxrwx 1  0 Jun 16 01:37 /proc/self/fd/1 -> /dev/pty0
>> lrwxrwxrwx 1  0 Jun 16 01:37 /proc/self/fd/2 -> /dev/pty0
>>
>> the following seems to work as expected:
>> $ powershell Start-Process bash  \"-c\",\"\'echo \>\>/dev/stdout hello
>> world\;sleep 10\'\"
>>
-- 
KIT- Research University in the Helmholtz Association

Dr.-Ing. Till Riedel
Lab Leader TECO, SDSC-BW/SDIL (AR)

Karlsruhe Institute of Technology (KIT)
Institute of Telematics (TM)
Pervasive Computing Systems - Prof. Beigl


Bldg. 07.07., Room 211
Vincenz Prießnitz Str. 1, 76131 Karlsruhe

+49 (0)721 608 41706
www.teco.kit.edu/~riedel


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

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

end of thread, other threads:[~2019-06-20 20:09 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-15 18:28 Are there any changes to the access control to /proc/<PID>/fd/1 in cygwin 3? Till Riedel
2019-06-16 15:42 ` Brian Inglis
2019-06-20 19:49   ` Till Riedel [TM]
2019-06-20 20:09     ` Till Riedel [TM]

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 read-only IMAP folder(s) and NNTP newsgroup(s).