From: Xinglu Chen <public@yoctocell.xyz>
To: Maxime Devos <maximedevos@telenet.be>, 48872@debbugs.gnu.org
Subject: bug#48872: Guix services: ‘chmod’ leaves opportunity to leak secrets
Date: Tue, 08 Jun 2021 16:42:43 +0200 [thread overview]
Message-ID: <874ke8s9i4.fsf@yoctocell.xyz> (raw)
In-Reply-To: <74f0e45af9ab426a5105452f191cffad337ca7ce.camel@telenet.be>
[-- 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 --]
prev parent reply other threads:[~2021-06-08 14:44 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=874ke8s9i4.fsf@yoctocell.xyz \
--to=public@yoctocell.xyz \
--cc=48872@debbugs.gnu.org \
--cc=maximedevos@telenet.be \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.