#594498 sshfs: Incorrect umask handling?

Package:
sshfs
Source:
sshfs-fuse
Description:
filesystem client based on SSH File Transfer Protocol
Submitter:
Petter Reinholdtsen
Date:
2011-12-05 08:57:20 UTC
Severity:
normal
#594498#5
Date:
2010-08-26 13:12:28 UTC
From:
To:
Package: sshfs
Version: 2.2-1

I ran into this problem when testing if sshfs could be used to mount
the home directory of users.

The problem is simply that the client umask is not used as is, but
seem to be combined with the ssh server umask.  This give unexpected
results.

Here is a program demonstrating the problem.


#define _GNU_SOURCE
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>

mode_t touch_get_mode(const char *name, mode_t mode) {
  mode_t retval = 0;
  int fd = open(name, O_RDWR|O_CREAT|O_LARGEFILE, mode);
  if (-1 != fd) {
    unlink(name);
    struct stat statbuf;
    if (-1 != fstat(fd, &statbuf)) {
      retval = statbuf.st_mode & 0x1ff;
    }
    close(fd);
  }
  return retval;
}

/* Try to detect problem discovered using sshfs */
int test_umask(void) {
  printf("info: testing umask effect on file creation\n");

  mode_t orig_umask = umask(000);
  mode_t newmode;
  if (0666 != (newmode = touch_get_mode("foobar", 0666))) {
    printf("  error: Wrong file mode %o when creating using mode 666 and umask 000\n",
           newmode);
  }
  umask(007);
  if (0660 != (newmode = touch_get_mode("foobar", 0666))) {
    printf("  error: Wrong file mode %o when creating using mode 666 and umask 007\n",
           newmode);
  }

  umask (orig_umask);
  return 0;
}

int main(int argc, char **argv) {
  test_umask();
  return 0;
}


On a system where everything is OK, this is printed:

  info: testing umask effect on file creation

When working on a sshfs file system, this is printed:

  info: testing umask effect on file creation
    error: Wrong file mode 644 when creating using mode 666 and umask 000
    error: Wrong file mode 640 when creating using mode 666 and umask 007

I suspect this can be solved by using umask(0) on the server before
handling any file system requests.

Happy hacking,

#594498#12
Date:
2011-12-03 13:19:33 UTC
From:
To:
tag 594498 +patch
thanks

Hi,

Reviewing this bug I found, in the sshfs mailing list, a year old patch [1]
for this issue.

I'm not exactly sure that the permissions should be handled this way, in fact I
would prefer a way to enforce permissions from the server side. But, if you
are interested in this feature it might be worth applying the patch or trying
to convince upstream (the authors) to accept it.

[1]: http://sourceforge.net/mailarchive/forum.php?forum_name=fuse-sshfs&max_rows=25&style=nested&viewmonth=201012&viewday=6

#594498#15
Date:
2011-12-03 13:19:33 UTC
From:
To:
tag 594498 +patch
thanks

Hi,

Reviewing this bug I found, in the sshfs mailing list, a year old patch [1]
for this issue.

I'm not exactly sure that the permissions should be handled this way, in fact I
would prefer a way to enforce permissions from the server side. But, if you
are interested in this feature it might be worth applying the patch or trying
to convince upstream (the authors) to accept it.

[1]: http://sourceforge.net/mailarchive/forum.php?forum_name=fuse-sshfs&max_rows=25&style=nested&viewmonth=201012&viewday=6

#594498#20
Date:
2011-12-05 08:56:25 UTC
From:
To:
See this more recent discussion about the same issue:

http://thread.gmane.org/gmane.comp.file-systems.fuse.sshfs/1207

So part of the problem can be solved on the server side.   The other
part (more fine grained control of permission bits on client side) is
still up for debate.

Thanks,
Miklos