From: Junio C Hamano <gitster@pobox.com>
To: Chris Torek <chris.torek@gmail.com>
Cc: "LTPCGO | George" <george@ltpcgo.com>, Git List <git@vger.kernel.org>
Subject: Re: Issue with insufficient permission for adding an object to repository database .git/objects
Date: Fri, 17 Jul 2020 12:53:20 -0700 [thread overview]
Message-ID: <xmqq365pex5b.fsf@gitster.c.googlers.com> (raw)
In-Reply-To: <CAPx1GvfKxu8gwbp0Gn2dBf9th874skKjD-echeAFr7_77o8FYw@mail.gmail.com> (Chris Torek's message of "Thu, 16 Jul 2020 08:41:40 -0700")
Chris Torek <chris.torek@gmail.com> writes:
> What Git does is this:
>
> * form the name of a file that we expect not to exist
> * use an open() system call in this way:
>
> fd = open(path, O_CREAT | O_EXCL | O_RDWR, 0444)
>
> Note that this is a single, atomic system call that asks
> the OS to:
>
> 1. make sure the path does not exist currently -- if it
> does, return an error;
> 2. create that path and open the resulting file for
> reading and writing, but make sure that no one else
> may write to that path.
>
> On a local file system, this really is a single atomic
> operation: either the path does not exist *and* you are
> allowed to create it *and* the creation succeeds *and*
> you now have a writable file-handle for a read-only file;
> or, any one of the "and"s above has failed (file already
> existed, you aren't allowed to create here, etc).
That's a very nice and clealy written analysis. What you outlined
above is exactly why we use these flags and create the file
read-only from the get go.
Having said that, most of these "create atomically" that are coming
via the tempfile API could use a looser 0644, as the primary reason
why we are careful is not to protect against bad actors but to
protect against ourselves (another process or another thread) racing
to create the same object---in other words, we are happy as long as
O_CREAT|O_EXCL is honored, and "link into the final place and then
unlink the tempfile" or "rename into the final place" patterns that
are used to conclude the temporary file obtained via the tempfile
API are reliable on the target filesystem.
The resulting file being read-only with 0444 (limited further by
umask) is not all that important. It is certainly possible to
destroy an owner-writable file by redirecting into it, and making
the files read-only may prevent such an accident from happening, but
immediate parent directories of these files have to be at least
owner-writable, so it is just as easy to destroy such a read-only
file by unlinking it from its parent directory.
I may be forgetting important reasons why we insist read-only files
in $GIT_DIR for objects, packs and commit-graph files (there may be
others), but otherwise I do not have a strong objection to a patch
with a well written log message that loosens these 0444 modes that
are (eventually) given to git_mkstemp_mode() to 0644.
Thanks.
prev parent reply other threads:[~2020-07-17 19:53 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-16 14:25 Issue with insufficient permission for adding an object to repository database .git/objects LTPCGO | George
2020-07-16 15:41 ` Chris Torek
2020-07-17 19:53 ` Junio C Hamano [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=xmqq365pex5b.fsf@gitster.c.googlers.com \
--to=gitster@pobox.com \
--cc=chris.torek@gmail.com \
--cc=george@ltpcgo.com \
--cc=git@vger.kernel.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.
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 NNTP newsgroup(s).