git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: LTPCGO | George <george@ltpcgo.com>
To: git@vger.kernel.org
Subject: Issue with insufficient permission for adding an object to repository database .git/objects
Date: Thu, 16 Jul 2020 16:25:45 +0200	[thread overview]
Message-ID: <d6bbe71e47dcfd7ef31213537eeb3f05@ltpcgo.com> (raw)

See discussion here 
https://groups.google.com/forum/?fromgroups#!topic/git-users/35HBb76oA6c 
and https://github.com/trapexit/mergerfs/issues/626

On certain file systems, there are issues with staging a commit because 
a call to open a file stored under .git/objects fails.  It has been 
brought up in this discussion group previously.

I have attached a fix below, but it would be much better to fix in the 
code.  I am curious first, before proposing a fix in the code (although 
I can't find the specific call in the source at 
https://github.com/git/git ), what the reasoning is for the current 
permissions check on the call rather than checking the contents of the 
opened tmp file.

cc -Wall -O3 -D_GNU_SOURCE -fPIC -c -o githack.o githack.c; gcc -o 
githack.so -nostartfiles -shared githack.o -ldl;



LD_PRELOAD=./githack.so git commit -a -m "Some new commit"



The code is below:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
//#define openat ignorethisopen
#define open ignorethisopen
#define open64 ignorethisopen64
#include <fcntl.h>
//#undef openat
#undef open
#undef open64
#include <dlfcn.h>

/*
        'strace git ...' will show git fail on an openat() command
        this is probably implemented as open64() on your system
        you can confirm this by use of 'ltrace git ...'
        you may also need to adjust the oflag comparison of 194
*/

/*static int (*___openat)(int, char *, int, mode_t);*/
static int (*___open)(const char *, int, mode_t);
static int (*___open64)(const char *, int, mode_t);

static void* dlwrap(const char *fn)
{
        const char *e;
        void *p = dlsym(RTLD_NEXT, fn);
        if ((e=dlerror())!=0)  fprintf(stderr, "dlsym(RTLD_NEXT,'%s'): 
%s\r\n", fn, e);
        return p;
}

void _init(void)
{
        ___open = dlwrap("open");
        ___open64 = dlwrap("open64");
}

/*int openat(int dirfd, const char *pathname, int oflag, mode_t mode)*/
int open(const char *pathname, int oflag, mode_t mode)
{
        if (oflag && oflag == 194)
               return ___open(pathname, oflag, S_IRWXU);
        return ___open(pathname, oflag, mode);
}

int open64(const char *pathname, int oflag, mode_t mode)
{
        if (oflag && oflag == 194)
               return ___open64(pathname, oflag, S_IRWXU);
        return ___open64(pathname, oflag, mode);
}

🖳 LTPCGO 🖳
Next-level security
Dr. George O’Neill
+44 7717 318 220
george@ltpcgo.com
https://www.ltpcgo.com/

             reply	other threads:[~2020-07-16 14:26 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-16 14:25 LTPCGO | George [this message]
2020-07-16 15:41 ` Issue with insufficient permission for adding an object to repository database .git/objects Chris Torek
2020-07-17 19:53   ` Junio C Hamano

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=d6bbe71e47dcfd7ef31213537eeb3f05@ltpcgo.com \
    --to=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.
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).