git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jonathan Tan <jonathantanmy@google.com>
To: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Cc: Jonathan Tan <jonathantanmy@google.com>,
	git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>,
	Bagas Sanjaya <bagasdotme@gmail.com>,
	Emily Shaffer <emilyshaffer@google.com>
Subject: Re: [PATCH v2 2/2] hooks: fix an obscure TOCTOU "did we just run a hook?" race
Date: Mon, 21 Mar 2022 13:30:18 -0700	[thread overview]
Message-ID: <20220321203019.2614799-1-jonathantanmy@google.com> (raw)
In-Reply-To: <patch-v2-2.2-9d16984898c-20220307T123244Z-avarab@gmail.com>

Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:
> diff --git a/builtin/commit.c b/builtin/commit.c
> index 8b8bdad3959..009a1de0a3d 100644
> --- a/builtin/commit.c
> +++ b/builtin/commit.c
> @@ -726,11 +726,13 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
>  	int clean_message_contents = (cleanup_mode != COMMIT_MSG_CLEANUP_NONE);
>  	int old_display_comment_prefix;
>  	int merge_contains_scissors = 0;
> +	int invoked_hook;
>  
>  	/* This checks and barfs if author is badly specified */
>  	determine_author_info(author_ident);
>  
> -	if (!no_verify && run_commit_hook(use_editor, index_file, "pre-commit", NULL))
> +	if (!no_verify && run_commit_hook(use_editor, index_file, &invoked_hook,
> +					  "pre-commit", NULL))
>  		return 0;
>  
>  	if (squash_message) {
> @@ -1053,10 +1055,10 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
>  		return 0;
>  	}
>  
> -	if (!no_verify && hook_exists("pre-commit")) {
> +	if (!no_verify && invoked_hook) {

This commit causes Git to fail Valgrind (tested using "cd t && sh
t5537*.sh -i -v --valgrind-only=10"). You can see here that a caller of
run_commit_hook() expects invoked_hook to be set, but...

> diff --git a/commit.c b/commit.c
> index d400f5dfa2b..396e14d7b32 100644
> --- a/commit.c
> +++ b/commit.c
> @@ -1713,7 +1713,7 @@ size_t ignore_non_trailer(const char *buf, size_t len)
>  }
>  
>  int run_commit_hook(int editor_is_used, const char *index_file,
> -		    const char *name, ...)
> +		    int *invoked_hook, const char *name, ...)
>  {
>  	struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT;
>  	va_list args;
> diff --git a/commit.h b/commit.h

The quoted part is the entire diff of commit.c. You can see that we have
a new argument "int *invoked_hook", but don't actually do anything with
it. Could you (Ævar) take a look?

      reply	other threads:[~2022-03-21 20:30 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-18 20:43 [PATCH 0/2] hooks: fix a race in hook execution Ævar Arnfjörð Bjarmason
2022-02-18 20:43 ` [PATCH 1/2] merge: don't run post-hook logic on --no-verify Ævar Arnfjörð Bjarmason
2022-02-18 23:57   ` Junio C Hamano
2022-02-18 20:43 ` [PATCH 2/2] hooks: fix a TOCTOU in "did we run a hook?" heuristic Ævar Arnfjörð Bjarmason
2022-02-19  0:11   ` Junio C Hamano
2022-02-19  4:48     ` Ævar Arnfjörð Bjarmason
2022-02-19  4:08   ` Taylor Blau
2022-02-19 10:46     ` Ævar Arnfjörð Bjarmason
2022-03-07 12:33 ` [PATCH v2 0/2] hooks: fix a race in hook execution Ævar Arnfjörð Bjarmason
2022-03-07 12:33   ` [PATCH v2 1/2] merge: don't run post-hook logic on --no-verify Ævar Arnfjörð Bjarmason
2022-03-07 12:33   ` [PATCH v2 2/2] hooks: fix an obscure TOCTOU "did we just run a hook?" race Ævar Arnfjörð Bjarmason
2022-03-21 20:30     ` Jonathan Tan [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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=20220321203019.2614799-1-jonathantanmy@google.com \
    --to=jonathantanmy@google.com \
    --cc=avarab@gmail.com \
    --cc=bagasdotme@gmail.com \
    --cc=emilyshaffer@google.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /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://80x24.org/mirrors/git.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).