* bug#48872: Guix services: ‘chmod’ leaves opportunity to leak secrets
@ 2021-06-06 12:51 Xinglu Chen
2021-06-08 8:55 ` Maxime Devos
0 siblings, 1 reply; 3+ messages in thread
From: Xinglu Chen @ 2021-06-06 12:51 UTC (permalink / raw)
To: 48872
[-- Attachment #1: Type: text/plain, Size: 669 bytes --]
[ This was reported on the Nixpkgs bug tracker a few weeks ago
<https://github.com/NixOS/nixpkgs/issues/121293> ]
When doing something like
(call-with-output-file FILE
(lambda (port)
(display SECRET port)))
(chmod FILE #o400)
an unpriviliged user could open FILE before FILE had been chmod’ed, and
then read the contents of FILE.
One solution to this problem would be to use
(mkdir (dirname FILE) #o400)
before writing SECRET to FILE.
I have identified at least two services which are vulnerable to this:
* ‘wireguard-service-type’ in (gnu services vpn)
* ‘patchwork-service-type’ in (gnu servicse web)
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 861 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* bug#48872: Guix services: ‘chmod’ leaves opportunity to leak secrets
2021-06-06 12:51 bug#48872: Guix services: ‘chmod’ leaves opportunity to leak secrets Xinglu Chen
@ 2021-06-08 8:55 ` Maxime Devos
2021-06-08 14:42 ` Xinglu Chen
0 siblings, 1 reply; 3+ messages in thread
From: Maxime Devos @ 2021-06-08 8:55 UTC (permalink / raw)
To: Xinglu Chen, 48872
[-- Attachment #1: Type: text/plain, Size: 1199 bytes --]
Xinglu Chen schreef op zo 06-06-2021 om 14:51 [+0200]:
> [ This was reported on the Nixpkgs bug tracker a few weeks ago
> <https://github.com/NixOS/nixpkgs/issues/121293> ]
>
> When doing something like
>
> (call-with-output-file FILE
> (lambda (port)
> (display SECRET port)))
> (chmod FILE #o400)
>
> an unpriviliged user could open FILE before FILE had been chmod’ed, and
> then read the contents of FILE.
>
> One solution to this problem would be to use
>
> (mkdir (dirname FILE) #o400)
>
> before writing SECRET to FILE.
Alternatively, a variant of call-with-output-file
could be defined that has a #:perms argument.
This new procedure, let's call it call-with-output-file*,
could create a file with the right permissions with
(open "/etc/...-secret" (bitwise-ior O_WRONLY O_CREAT) #o400)
or something like that.
Then the vulnerable code above would become ...
(call-with-output-file* FILE
(lambda (port)
(display SECRET port))
#:perms #o400)
This seems a bit easier in usage to me!
No need to worry if changing the permissions of the parent
directory would break anything this way.
Greetings,
Maxime.
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 260 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* bug#48872: Guix services: ‘chmod’ leaves opportunity to leak secrets
2021-06-08 8:55 ` Maxime Devos
@ 2021-06-08 14:42 ` Xinglu Chen
0 siblings, 0 replies; 3+ messages in thread
From: Xinglu Chen @ 2021-06-08 14:42 UTC (permalink / raw)
To: Maxime Devos, 48872
[-- Attachment #1: Type: text/plain, Size: 1322 bytes --]
On Tue, Jun 08 2021, Maxime Devos wrote:
> Xinglu Chen schreef op zo 06-06-2021 om 14:51 [+0200]:
>> [ This was reported on the Nixpkgs bug tracker a few weeks ago
>> <https://github.com/NixOS/nixpkgs/issues/121293> ]
>>
>> When doing something like
>>
>> (call-with-output-file FILE
>> (lambda (port)
>> (display SECRET port)))
>> (chmod FILE #o400)
>>
>> an unpriviliged user could open FILE before FILE had been chmod’ed, and
>> then read the contents of FILE.
>>
>> One solution to this problem would be to use
>>
>> (mkdir (dirname FILE) #o400)
>>
>> before writing SECRET to FILE.
>
> Alternatively, a variant of call-with-output-file
> could be defined that has a #:perms argument.
>
> This new procedure, let's call it call-with-output-file*,
> could create a file with the right permissions with
> (open "/etc/...-secret" (bitwise-ior O_WRONLY O_CREAT) #o400)
> or something like that.
>
> Then the vulnerable code above would become ...
>
> (call-with-output-file* FILE
> (lambda (port)
> (display SECRET port))
> #:perms #o400)
>
> This seems a bit easier in usage to me!
> No need to worry if changing the permissions of the parent
> directory would break anything this way.
Indeed, this sounds like a better approach!
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 861 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-06-08 14:44 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-06 12:51 bug#48872: Guix services: ‘chmod’ leaves opportunity to leak secrets Xinglu Chen
2021-06-08 8:55 ` Maxime Devos
2021-06-08 14:42 ` Xinglu Chen
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/guix.git
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.