{"thread":{"id":"35655","subject":"hooks scripts and noexec partition","startedAt":"2014-01-14T15:41:03Z","lastAt":"2014-12-17T03:03:29Z","messageCount":4,"participants":["krzf83@gmail.com","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"233091","messageId":"CAJ1PRS=96aSp3GE+wj=zHX=JGfZbjUeiUuiDDvfJNuRhrbK_Yg@mail.gmail.com","threadId":"35655","inReplyTo":null,"subject":"hooks scripts and noexec partition","fromName":"krzf83@gmail.com","fromEmail":"krzf83@gmail.com","sentAt":"2014-01-14T15:41:03Z","receivedAt":"2014-01-14T15:41:03Z","isPatch":false,"sender":{"key":"krzf83@gmail.com","avatar":null},"body":"git can't execute hooks no partitions mounted with noexec - even if\nthose are just scripts with shebang line and they actualy work by\nhooks/./post-comit (because I use small patch on kernel that allows\nrunning scripts that way on noexec partition)\n\nfs/exec.c\n\n//        error = -EACCES;\n//        if (file->f_path.mnt->mnt_flags & MNT_NOEXEC)\n//                goto exit;\n...\n//        if (file->f_path.mnt->mnt_flags & MNT_NOEXEC)\n//                goto exit;\n"},{"id":"233137","messageId":"20140115091609.GC14335@sigill.intra.peff.net","threadId":"35655","inReplyTo":"CAJ1PRS=96aSp3GE+wj=zHX=JGfZbjUeiUuiDDvfJNuRhrbK_Yg@mail.gmail.com","subject":"Re: hooks scripts and noexec partition","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2014-01-15T09:16:09Z","receivedAt":"2014-01-15T09:16:09Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, Jan 14, 2014 at 04:41:03PM +0100, krzf83@gmail.com  wrote:\n\n> git can't execute hooks no partitions mounted with noexec - even if\n> those are just scripts with shebang line\n\nRight. Git does not know that they are shell (or other) scripts; they\ncould be anything, and the advertised interface is that git will run\nexec on them (and it is explicitly OK for them to exist but not be\nexecutable, and git takes this as a sign that they are inactive).\n\n> and they actualy work by\n> hooks/./post-comit (because I use small patch on kernel that allows\n> running scripts that way on noexec partition)\n\nIf you are suggesting that git always execute them as \"hooks/./$hook\",\nthat might make sense if such behavior is widespread. But it sounds like\nyou are running a custom kernel patch to get around the noexec setting.\nHere is the custom git patch to match it. :)\n\ndiff --git a/run-command.c b/run-command.c\nindex 3914d9c..ae84e87 100644\n--- a/run-command.c\n+++ b/run-command.c\n@@ -753,7 +753,7 @@ int finish_async(struct async *async)\n \n char *find_hook(const char *name)\n {\n-\tchar *path = git_path(\"hooks/%s\", name);\n+\tchar *path = git_path(\"hooks/./%s\", name);\n \tif (access(path, X_OK) < 0)\n \t\tpath = NULL;\n \n\n-Peff\n"},{"id":"253681","messageId":"CAJ1PRS=KmiQJG91nxG5pQXPHX2XruoyL9c4yzzPeYayw+UAjPw@mail.gmail.com","threadId":"35655","inReplyTo":"20140115091609.GC14335@sigill.intra.peff.net","subject":"Re: hooks scripts and noexec partition","fromName":"krzf83@gmail.com","fromEmail":"krzf83@gmail.com","sentAt":"2014-12-14T01:44:35Z","receivedAt":"2014-12-14T01:44:35Z","isPatch":false,"sender":{"key":"krzf83@gmail.com","avatar":null},"body":"Thanks for the patch, however it is not working (no change, hooks\nstill dont work on noexec partition). Since I see that you are fluent\nin git code and C can you by any chance tell me how to modify\nrun-command.c to make git run hooks as: /bin/sh <hook_path> ?\n\n2014-01-15 10:16 GMT+01:00 Jeff King <peff@peff.net>:\n> On Tue, Jan 14, 2014 at 04:41:03PM +0100, krzf83@gmail.com  wrote:\n>\n>> git can't execute hooks no partitions mounted with noexec - even if\n>> those are just scripts with shebang line\n>\n> Right. Git does not know that they are shell (or other) scripts; they\n> could be anything, and the advertised interface is that git will run\n> exec on them (and it is explicitly OK for them to exist but not be\n> executable, and git takes this as a sign that they are inactive).\n>\n>> and they actualy work by\n>> hooks/./post-comit (because I use small patch on kernel that allows\n>> running scripts that way on noexec partition)\n>\n> If you are suggesting that git always execute them as \"hooks/./$hook\",\n> that might make sense if such behavior is widespread. But it sounds like\n> you are running a custom kernel patch to get around the noexec setting.\n> Here is the custom git patch to match it. :)\n>\n> diff --git a/run-command.c b/run-command.c\n> index 3914d9c..ae84e87 100644\n> --- a/run-command.c\n> +++ b/run-command.c\n> @@ -753,7 +753,7 @@ int finish_async(struct async *async)\n>\n>  char *find_hook(const char *name)\n>  {\n> -       char *path = git_path(\"hooks/%s\", name);\n> +       char *path = git_path(\"hooks/./%s\", name);\n>         if (access(path, X_OK) < 0)\n>                 path = NULL;\n>\n>\n> -Peff\n"},{"id":"253756","messageId":"20141217030328.GB4033@peff.net","threadId":"35655","inReplyTo":"CAJ1PRS=KmiQJG91nxG5pQXPHX2XruoyL9c4yzzPeYayw+UAjPw@mail.gmail.com","subject":"Re: hooks scripts and noexec partition","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2014-12-17T03:03:29Z","receivedAt":"2014-12-17T03:03:29Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sun, Dec 14, 2014 at 02:44:35AM +0100, krzf83@gmail.com  wrote:\n\n> Thanks for the patch, however it is not working (no change, hooks\n> still dont work on noexec partition). Since I see that you are fluent\n> in git code and C can you by any chance tell me how to modify\n> run-command.c to make git run hooks as: /bin/sh <hook_path> ?\n\nI do not think that is a smart thing to do in general, as there is no\nguarantee that the hook is in fact a shell script (and not a binary, or\nsome other scripting language). But if you want do a one-off patch for\nyourself, knowing that you will only use shell scripts, it is probably\nsomething like:\n\ndiff --git a/run-command.c b/run-command.c\nindex a476999..ccfccf0 100644\n--- a/run-command.c\n+++ b/run-command.c\n@@ -812,6 +812,7 @@ int run_hook_ve(const char *const *env, const char *name, va_list args)\n \tif (!p)\n \t\treturn 0;\n \n+\targv_array_push(&hook.args, \"/bin/sh\");\n \targv_array_push(&hook.args, p);\n \twhile ((p = va_arg(args, const char *)))\n \t\targv_array_push(&hook.args, p);\n\n-Peff\n"}]}