unofficial mirror of bug-guix@gnu.org 
 help / color / mirror / code / Atom feed
From: Maxime Devos <maximedevos@telenet.be>
To: Xinglu Chen <public@yoctocell.xyz>, 48872@debbugs.gnu.org
Subject: bug#48872: Guix services: ‘chmod’ leaves opportunity to leak secrets
Date: Tue, 08 Jun 2021 10:55:57 +0200	[thread overview]
Message-ID: <74f0e45af9ab426a5105452f191cffad337ca7ce.camel@telenet.be> (raw)
In-Reply-To: <87y2bn5f6v.fsf@yoctocell.xyz>

[-- 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 --]

  reply	other threads:[~2021-06-08  8:57 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 [this message]
2021-06-08 14:42   ` Xinglu Chen

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

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=74f0e45af9ab426a5105452f191cffad337ca7ce.camel@telenet.be \
    --to=maximedevos@telenet.be \
    --cc=48872@debbugs.gnu.org \
    --cc=public@yoctocell.xyz \
    /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 public inbox

	https://git.savannah.gnu.org/cgit/guix.git

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).