]> git.proxmox.com Git - qemu.git/commitdiff
hw/9pfs: Preserve S_ISGID
authorM. Mohan Kumar <mohan@in.ibm.com>
Thu, 19 Jan 2012 06:51:12 +0000 (12:21 +0530)
committerAneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Mon, 30 Jan 2012 05:24:16 +0000 (10:54 +0530)
In passthrough security model in local fs driver, after a file creation
chown and chmod are done to set the file credentials and mode as requested
by 9p client. But if there was a request to create a file with S_ISGID
bit, doing chown on that file resets the S_ISGID bit. So first call
chown and then invoking chmod with proper mode bit retains the S_ISGID
(if present/requested)

This resulted in LTP mknod02, mknod03, mknod05, open10 test case
failures. This patch fixes this issue.

man 2 chown
When the owner or group of an executable file are changed by an unprivileged
user the S_ISUID  and  S_ISGID mode  bits are cleared.  POSIX does not specify
whether this also should happen when root does the chown(); the Linux behavior
depends on the kernel version.

Signed-off-by: M. Mohan Kumar <mohan@in.ibm.com>
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
hw/9pfs/virtio-9p-handle.c
hw/9pfs/virtio-9p-local.c

index cb012c0510ace40de7153d7feb87f0e981a0c200..f96d17a9749a6f672741ff4dcb98da81d1dcc3ce 100644 (file)
@@ -63,11 +63,11 @@ static int handle_update_file_cred(int dirfd, const char *name, FsCred *credp)
     if (fd < 0) {
         return fd;
     }
-    ret = fchmod(fd, credp->fc_mode & 07777);
+    ret = fchownat(fd, "", credp->fc_uid, credp->fc_gid, AT_EMPTY_PATH);
     if (ret < 0) {
         goto err_out;
     }
-    ret = fchownat(fd, "", credp->fc_uid, credp->fc_gid, AT_EMPTY_PATH);
+    ret = fchmod(fd, credp->fc_mode & 07777);
 err_out:
     close(fd);
     return ret;
index 6e3f9d1d97d6fd4c26d65bb4073c2a4a26f23438..33a41d2e18b60aab8c87cab8834c03a442fc5ca7 100644 (file)
@@ -257,9 +257,6 @@ static int local_post_create_passthrough(FsContext *fs_ctx, const char *path,
 {
     char buffer[PATH_MAX];
 
-    if (chmod(rpath(fs_ctx, path, buffer), credp->fc_mode & 07777) < 0) {
-        return -1;
-    }
     if (lchown(rpath(fs_ctx, path, buffer), credp->fc_uid,
                 credp->fc_gid) < 0) {
         /*
@@ -270,6 +267,10 @@ static int local_post_create_passthrough(FsContext *fs_ctx, const char *path,
             return -1;
         }
     }
+
+    if (chmod(rpath(fs_ctx, path, buffer), credp->fc_mode & 07777) < 0) {
+        return -1;
+    }
     return 0;
 }