From: Alexey Abramov via Guix-patches via <guix-patches@gnu.org>
To: "Ludovic Courtès" <ludo@gnu.org>
Cc: 55034@debbugs.gnu.org
Subject: [bug#55034] [PATCH 0/1] Let openssh trust /gnu/store
Date: Fri, 22 Apr 2022 09:02:49 +0200 [thread overview]
Message-ID: <87tualiorq.fsf@delta.lan> (raw)
In-Reply-To: <8735i8oyxn.fsf_-_@gnu.org> ("Ludovic Courtès"'s message of "Wed, 20 Apr 2022 12:02:12 +0200")
Ludovic Courtès <ludo@gnu.org> writes:
> Alexey Abramov <levenson@mmer.org> skribis:
>
>> + safe_path(const char *name, struct stat *stp, const char *pw_dir,
>> + uid_t uid, char *err, size_t errlen)
>> + {
>> ++ static const char gnu_store[] = "/gnu/store";
>> + char buf[PATH_MAX], homedir[PATH_MAX];
>> + char *cp;
>> + int comparehome = 0;
>> +@@ -2178,6 +2179,10 @@ safe_path(const char *name, struct stat *stp, const char *pw_dir,
>> + }
>> + strlcpy(buf, cp, sizeof(buf));
>> +
>> ++ /* If are past the Guix /gnu/store then we can stop */
>> ++ if (strcmp(gnu_store, buf) == 0)
>> ++ break;
>
> We should not hard-code “/gnu/store” because it can be something else.
>
> I think you can do like what ‘gcc-dl-cache.patch’ does: replace the
> literal "/gnu/store" by @STORE_DIRECTORY@, and substitute it in a phase.
This is great! That is what I was looking for.
> Also note that the strcmp above is incorrect: it would accept
> /gnu/storesomethinglese. You probably need to add a trailing slash to
> be sure.
Let me correct myself. In the previous email I wrote that the safe_path
goes from top to bottom, but actually it walking upwards. This is an
actual loop
--8<---------------cut here---------------start------------->8---
/* for each component of the canonical path, walking upwards */
for (;;) {
if ((cp = dirname(buf)) == NULL) {
snprintf(err, errlen, "dirname() failed");
return -1;
}
strlcpy(buf, cp, sizeof(buf));
/* If are past the Guix /gnu/store then we can stop */
if (strcmp(gnu_store, buf) == 0)
break;
if (stat(buf, &st) == -1 ||
(!platform_sys_dir_uid(st.st_uid) && st.st_uid != uid) ||
(st.st_mode & 022) != 0) {
snprintf(err, errlen,
"bad ownership or modes for directory %s", buf);
return -1;
}
/* If are past the homedir then we can stop */
if (comparehome && strcmp(homedir, buf) == 0)
break;
/*
* dirname should always complete with a "/" path,
* but we can be paranoid and check for "." too
*/
if ((strcmp("/", buf) == 0) || (strcmp(".", buf) == 0))
break;
}
return 0;
--8<---------------cut here---------------end--------------->8---
As you can see, buffer is holding the result of dirname already, hence
I used "/gnu/store".
--
Alexey
next prev parent reply other threads:[~2022-04-22 7:04 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-20 8:47 [bug#55034] [PATCH 0/1] Let openssh trust /gnu/store Alexey Abramov via Guix-patches via
2022-04-20 8:49 ` [bug#55034] [PATCH 1/1] gnu: openssh: Trust /gnu/store directory Alexey Abramov via Guix-patches via
2022-04-20 10:02 ` [bug#55034] [PATCH 0/1] Let openssh trust /gnu/store Ludovic Courtès
2022-04-22 7:02 ` Alexey Abramov via Guix-patches via [this message]
2022-04-20 9:56 ` Ludovic Courtès
2022-04-22 6:44 ` Alexey Abramov via Guix-patches via
2022-04-27 21:54 ` Ludovic Courtès
2022-04-20 10:17 ` Tobias Geerinckx-Rice via Guix-patches via
2022-04-20 10:20 ` Tobias Geerinckx-Rice via Guix-patches via
2022-04-22 7:33 ` Alexey Abramov via Guix-patches via
2022-04-26 7:25 ` [bug#55034] [PATCH v2] gnu: openssh: Trust Guix store directory Alexey Abramov via Guix-patches via
2022-04-28 22:07 ` bug#55034: [PATCH 0/1] Let openssh trust /gnu/store Ludovic Courtès
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=87tualiorq.fsf@delta.lan \
--to=guix-patches@gnu.org \
--cc=55034@debbugs.gnu.org \
--cc=levenson@mmer.org \
--cc=ludo@gnu.org \
/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.