From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:39761) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rfb89-00035x-Qw for qemu-devel@nongnu.org; Tue, 27 Dec 2011 12:48:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Rfb88-0007Kg-ST for qemu-devel@nongnu.org; Tue, 27 Dec 2011 12:48:05 -0500 Received: from e28smtp07.in.ibm.com ([122.248.162.7]:35373) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rfb88-0007Ka-7o for qemu-devel@nongnu.org; Tue, 27 Dec 2011 12:48:04 -0500 Received: from /spool/local by e28smtp07.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 27 Dec 2011 23:17:57 +0530 Received: from d28av03.in.ibm.com (d28av03.in.ibm.com [9.184.220.65]) by d28relay05.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id pBRHlqdA3985594 for ; Tue, 27 Dec 2011 23:17:53 +0530 Received: from d28av03.in.ibm.com (loopback [127.0.0.1]) by d28av03.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id pBRHlpRY031372 for ; Wed, 28 Dec 2011 04:47:52 +1100 From: "M. Mohan Kumar" Date: Tue, 27 Dec 2011 23:17:46 +0530 Message-Id: <1325008066-12094-1-git-send-email-mohan@in.ibm.com> Subject: [Qemu-devel] [PATCH] Preserve S_ISGID List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org, "Aneesh Kumar K.V" Cc: "M. Mohan Kumar" From: "M. Mohan Kumar" 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 --- hw/9pfs/virtio-9p-local.c | 7 ++++--- 1 files changed, 4 insertions(+), 3 deletions(-) diff --git a/hw/9pfs/virtio-9p-local.c b/hw/9pfs/virtio-9p-local.c index 3ae6ef2..3eb481d 100644 --- a/hw/9pfs/virtio-9p-local.c +++ b/hw/9pfs/virtio-9p-local.c @@ -115,9 +115,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) { /* @@ -128,6 +125,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; } -- 1.7.6