From nobody Sun May 5 11:32:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1617114454; cv=none; d=zohomail.com; s=zohoarc; b=deIimkatpyqbJRBvHQsBAwniO41OOPueYDwKmH5ORvneKSwxMzCiZE/juVdjI4CI7y8cm4T46qHSO5EqUeL4YwE1zfeRN8jxiXstM4J8CNW6rxyUwGwlB+3OZOYQvRnQV+URE9ogClOgzCMBA/SiFaaadjlxWfnkcmDfejr3SY4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1617114454; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Fz2lty2f82fOCXnvCMnt30KfeGYKl86ayn41eviG2iA=; b=ji72WrMqWoTf88bm9g0kgOS0SL972OmdwxLtr82B7uTfTQZqSA2ScDRurlDc9o8H9hdH2VXAgE1fhrTeDNa8pStnf9coYZ472mIqbzdXGIBFkq9On/7skGL2hKwS5+5OMM1gg97idwwLAa6ptGNQjMSBf0rVICXyOyfsvsyXmmM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1617114454605226.93789835143718; Tue, 30 Mar 2021 07:27:34 -0700 (PDT) Received: from localhost ([::1]:42994 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lRFBN-0003wM-Bd for importer@patchew.org; Tue, 30 Mar 2021 10:17:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53946) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lRF4A-0002yT-Kt for qemu-devel@nongnu.org; Tue, 30 Mar 2021 10:09:58 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:40386) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lRF42-00058W-O7 for qemu-devel@nongnu.org; Tue, 30 Mar 2021 10:09:58 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-417-I9i8mo09OsWhxZQSD_2Z3Q-1; Tue, 30 Mar 2021 10:09:45 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 84ECD612AE; Tue, 30 Mar 2021 14:09:44 +0000 (UTC) Received: from horse.redhat.com (ovpn-116-118.rdu2.redhat.com [10.10.116.118]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7FD0A62A22; Tue, 30 Mar 2021 14:09:35 +0000 (UTC) Received: by horse.redhat.com (Postfix, from userid 10451) id 22E9C223D98; Tue, 30 Mar 2021 10:09:34 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617113389; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Fz2lty2f82fOCXnvCMnt30KfeGYKl86ayn41eviG2iA=; b=KtJ9q9JiPIyQXulL79H+eRfdkApjiHQAA105TzovhOpt2iy0PMz8cF9pnEK314s77/pbd3 2M868/7dfDifuP6dTvj2f0VlnzBBImWkzoaoAI/8yY353N7z9aGhOwI/x/NR0n2Kg1nwfh OwZM0cq+YLjDSFKybIW6g9idupW51/o= X-MC-Unique: I9i8mo09OsWhxZQSD_2Z3Q-1 From: Vivek Goyal To: qemu-devel@nongnu.org, virtio-fs@redhat.com Subject: [PATCH v6 1/5] virtiofsd: Add umask to seccom allow list Date: Tue, 30 Mar 2021 10:09:21 -0400 Message-Id: <20210330140925.730449-2-vgoyal@redhat.com> In-Reply-To: <20210330140925.730449-1-vgoyal@redhat.com> References: <20210330140925.730449-1-vgoyal@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=vgoyal@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=vgoyal@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lhenriques@suse.de, Stefan Hajnoczi , dgilbert@redhat.com, vgoyal@redhat.com, miklos@szeredi.hu Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Patches in this series are going to make use of "umask" syscall. So allow it. Signed-off-by: Vivek Goyal Reviewed-by: Stefan Hajnoczi --- tools/virtiofsd/passthrough_seccomp.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/virtiofsd/passthrough_seccomp.c b/tools/virtiofsd/passth= rough_seccomp.c index 62441cfcdb..f49ed94b5e 100644 --- a/tools/virtiofsd/passthrough_seccomp.c +++ b/tools/virtiofsd/passthrough_seccomp.c @@ -114,6 +114,7 @@ static const int syscall_allowlist[] =3D { SCMP_SYS(utimensat), SCMP_SYS(write), SCMP_SYS(writev), + SCMP_SYS(umask), }; =20 /* Syscalls used when --syslog is enabled */ --=20 2.25.4 From nobody Sun May 5 11:32:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1617113536; cv=none; d=zohomail.com; s=zohoarc; b=WMTTPvYl3zkIW6cex5OfnhYvvbbJ3GFR1TQT9L2fPy+Up+XzdlpI0ft8zIhpryB9b/wQSL+l/8esz31BsJ+EDyPIxIYOIWsfx1w9F7MLF6RSkzdTSDzE4i33fg1cju8YE+PWFaaWWtk7AYoAiRqKO00XYuj65x2+IaEjTm0GNGs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1617113536; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=VD9imHUYCrYXbqORd8UehuR2aJYG8zcPhvQ2cCVRuE4=; b=aI+jSjbg+FTPBYN7LtN+/ExXyaQP9Md+g/eOO95jKsuQEE2iffWKGd8uz+w05hMa7y7S2CuBRHBZXQdlYfjnT/TFzYxnZsaTGJdaD/GwhLtPjSMasV+jVdzUBCal5+5fYXKn9X1OBjJJto0ARsf/mqETnPjaz9A63Bkjtad1m1E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 161711353671166.56907455438943; Tue, 30 Mar 2021 07:12:16 -0700 (PDT) Received: from localhost ([::1]:54874 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lRF6N-0005be-EV for importer@patchew.org; Tue, 30 Mar 2021 10:12:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53902) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lRF44-0002vM-SP for qemu-devel@nongnu.org; Tue, 30 Mar 2021 10:09:54 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:26116) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lRF3v-00055i-AW for qemu-devel@nongnu.org; Tue, 30 Mar 2021 10:09:50 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-187-AuhV_j25PCe-9ep4qZyIKg-1; Tue, 30 Mar 2021 10:09:37 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E226410055D0; Tue, 30 Mar 2021 14:09:35 +0000 (UTC) Received: from horse.redhat.com (ovpn-116-118.rdu2.redhat.com [10.10.116.118]) by smtp.corp.redhat.com (Postfix) with ESMTP id 802B360613; Tue, 30 Mar 2021 14:09:35 +0000 (UTC) Received: by horse.redhat.com (Postfix, from userid 10451) id 28DE6223D99; Tue, 30 Mar 2021 10:09:34 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617113380; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VD9imHUYCrYXbqORd8UehuR2aJYG8zcPhvQ2cCVRuE4=; b=gKa2f7muNjS3r/3/jBIe+eCw47wly4H480gDSgwIf3lQUTSJJKPuy/pbM7MyNVK6EsBl2D aUW7cUQdIT4OVnLTXK8K08uk9ylPlpyf9PGJfUerWt5iwEmx+ASsrr0NTLrtLqWp0722Gf HXRVjNQvgQgRieyCJWxAeJfVM7UfO6c= X-MC-Unique: AuhV_j25PCe-9ep4qZyIKg-1 From: Vivek Goyal To: qemu-devel@nongnu.org, virtio-fs@redhat.com Subject: [PATCH v6 2/5] virtiofsd: Add capability to change/restore umask Date: Tue, 30 Mar 2021 10:09:22 -0400 Message-Id: <20210330140925.730449-3-vgoyal@redhat.com> In-Reply-To: <20210330140925.730449-1-vgoyal@redhat.com> References: <20210330140925.730449-1-vgoyal@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=vgoyal@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=vgoyal@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lhenriques@suse.de, Stefan Hajnoczi , dgilbert@redhat.com, vgoyal@redhat.com, miklos@szeredi.hu Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" When parent directory has default acl and a file is created in that directory, then umask is ignored and final file permissions are determined using default acl instead. (man 2 umask). Currently, fuse applies the umask and sends modified mode in create request accordingly. fuse server can set FUSE_DONT_MASK and tell fuse client to not apply umask and fuse server will take care of it as needed. With posix acls enabled, requirement will be that we want umask to determine final file mode if parent directory does not have default acl. So if posix acls are enabled, opt in for FUSE_DONT_MASK. virtiofsd will set umask of the thread doing file creation. And host kernel should use that umask if parent directory does not have default acls, otherwise umask does not take affect. Miklos mentioned that we already call unshare(CLONE_FS) for every thread. That means umask has now become property of per thread and it should be ok to manipulate it in file creation path. This patch only adds capability to change umask and restore it. It does not enable it yet. Next patch will add capability to enable it based on if user enabled posix_acl or not. This should fix fstest generic/099. Reported-by: Luis Henriques Signed-off-by: Vivek Goyal Reviewed-by: Stefan Hajnoczi --- tools/virtiofsd/passthrough_ll.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough= _ll.c index b144320e48..e6ae3d38d7 100644 --- a/tools/virtiofsd/passthrough_ll.c +++ b/tools/virtiofsd/passthrough_ll.c @@ -122,6 +122,7 @@ struct lo_inode { struct lo_cred { uid_t euid; gid_t egid; + mode_t umask; }; =20 enum { @@ -172,6 +173,8 @@ struct lo_data { /* An O_PATH file descriptor to /proc/self/fd/ */ int proc_self_fd; int user_killpriv_v2, killpriv_v2; + /* If set, virtiofsd is responsible for setting umask during creation = */ + bool change_umask; }; =20 static const struct fuse_opt lo_opts[] =3D { @@ -1134,7 +1137,8 @@ static void lo_lookup(fuse_req_t req, fuse_ino_t pare= nt, const char *name) * ownership of caller. * TODO: What about selinux context? */ -static int lo_change_cred(fuse_req_t req, struct lo_cred *old) +static int lo_change_cred(fuse_req_t req, struct lo_cred *old, + bool change_umask) { int res; =20 @@ -1154,11 +1158,14 @@ static int lo_change_cred(fuse_req_t req, struct lo= _cred *old) return errno_save; } =20 + if (change_umask) { + old->umask =3D umask(req->ctx.umask); + } return 0; } =20 /* Regain Privileges */ -static void lo_restore_cred(struct lo_cred *old) +static void lo_restore_cred(struct lo_cred *old, bool restore_umask) { int res; =20 @@ -1173,6 +1180,9 @@ static void lo_restore_cred(struct lo_cred *old) fuse_log(FUSE_LOG_ERR, "setegid(%u): %m\n", old->egid); exit(1); } + + if (restore_umask) + umask(old->umask); } =20 static void lo_mknod_symlink(fuse_req_t req, fuse_ino_t parent, @@ -1202,7 +1212,7 @@ static void lo_mknod_symlink(fuse_req_t req, fuse_ino= _t parent, return; } =20 - saverr =3D lo_change_cred(req, &old); + saverr =3D lo_change_cred(req, &old, lo->change_umask && !S_ISLNK(mode= )); if (saverr) { goto out; } @@ -1211,7 +1221,7 @@ static void lo_mknod_symlink(fuse_req_t req, fuse_ino= _t parent, =20 saverr =3D errno; =20 - lo_restore_cred(&old); + lo_restore_cred(&old, lo->change_umask && !S_ISLNK(mode)); =20 if (res =3D=3D -1) { goto out; @@ -1918,7 +1928,7 @@ static void lo_create(fuse_req_t req, fuse_ino_t pare= nt, const char *name, return; } =20 - err =3D lo_change_cred(req, &old); + err =3D lo_change_cred(req, &old, lo->change_umask); if (err) { goto out; } @@ -1929,7 +1939,7 @@ static void lo_create(fuse_req_t req, fuse_ino_t pare= nt, const char *name, fd =3D openat(parent_inode->fd, name, fi->flags | O_CREAT | O_EXCL, mo= de); err =3D fd =3D=3D -1 ? errno : 0; =20 - lo_restore_cred(&old); + lo_restore_cred(&old, lo->change_umask); =20 /* Ignore the error if file exists and O_EXCL was not given */ if (err && (err !=3D EEXIST || (fi->flags & O_EXCL))) { --=20 2.25.4 From nobody Sun May 5 11:32:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1617117349; cv=none; d=zohomail.com; s=zohoarc; b=QdVXPLJpGXv9b0kvgZcY9ZArwV+70EZ+s3RrmxxSGgTihdOQdzoEBMOju+HI8rucUji7r1nusp/Rmq2GbPYucnZx3btnU/8De7OA9UdIkrX5dXvm9RejPvLD2fk1EczLaexLcQ4JIYZdMD6MCS2SSuH5YjYrgwkHLGXVfChIcMA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1617117349; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=PbzFkdzHdpZD4jkX9pDFL09Q9lBem9TQmaJWoeDpQMQ=; b=h9AhchRShWqGjZXDBaaHVIBE4YeX4yUuS8lQEqKwV/Evc9z8+r9w1iY9YyDQLyDPibq4FKivXhYzeDDdQqGZpg3IU5kICYTTzDteYMA62brQVonxRu8X6q7/dnMOxnH0YPQWOctOuDHpEJsykypk0jDLCAGTdCXNrN/X/mzaJYY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1617117349742613.5175656209242; Tue, 30 Mar 2021 08:15:49 -0700 (PDT) Received: from localhost ([::1]:35032 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lRF8I-0000YW-SH for importer@patchew.org; Tue, 30 Mar 2021 10:14:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53944) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lRF4A-0002yH-K2 for qemu-devel@nongnu.org; Tue, 30 Mar 2021 10:09:58 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:31805) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lRF3v-000568-BX for qemu-devel@nongnu.org; Tue, 30 Mar 2021 10:09:56 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-277-hiytHt3qNIKNSpZgVHullg-1; Tue, 30 Mar 2021 10:09:37 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DB052802B5B; Tue, 30 Mar 2021 14:09:35 +0000 (UTC) Received: from horse.redhat.com (ovpn-116-118.rdu2.redhat.com [10.10.116.118]) by smtp.corp.redhat.com (Postfix) with ESMTP id 77B6360861; Tue, 30 Mar 2021 14:09:35 +0000 (UTC) Received: by horse.redhat.com (Postfix, from userid 10451) id 2DA95225FCD; Tue, 30 Mar 2021 10:09:34 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617113381; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PbzFkdzHdpZD4jkX9pDFL09Q9lBem9TQmaJWoeDpQMQ=; b=TQ9jOqobS2HVlqX8rLyjb4BO4i9RdbIB1+MvDCRLyjP6aHZdiQFHCibSHRvJSh5X+gNOZn 6vm9dMVIUjOogzCuSbhGKHRtm3PvED+ZxMPjA3HvD3WjuXMzvobk3lWiV9Q04jswhYRfxf pSEok6i583ZVjeKPM0aRb/OIQKJsGlA= X-MC-Unique: hiytHt3qNIKNSpZgVHullg-1 From: Vivek Goyal To: qemu-devel@nongnu.org, virtio-fs@redhat.com Subject: [PATCH v6 3/5] virtiofsd: Add an option to enable/disable posix acls Date: Tue, 30 Mar 2021 10:09:23 -0400 Message-Id: <20210330140925.730449-4-vgoyal@redhat.com> In-Reply-To: <20210330140925.730449-1-vgoyal@redhat.com> References: <20210330140925.730449-1-vgoyal@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=vgoyal@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=vgoyal@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_FILL_THIS_FORM_SHORT=0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lhenriques@suse.de, dgilbert@redhat.com, vgoyal@redhat.com, miklos@szeredi.hu Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" fuse has an option FUSE_POSIX_ACL which needs to be opted in by fuse server to enable posix acls. As of now we are not opting in for this, so posix acls are disabled on virtiofs by default. Add virtiofsd option "-o posix_acl/no_posix_acl" to let users enable/disable posix acl support. By default it is disabled as of now due to performance concerns with cache=3Dnone. Currently even if file server has not opted in for FUSE_POSIX_ACL, user can still query acl and set acl, and system.posix_acl_access and system.posix_acl_default xattrs show up listxattr response. Miklos said this is confusing. So he said lets block and filter system.posix_acl_access and system.posix_acl_default xattrs in getxattr/setxattr/listxattr if user has explicitly disabled posix acls using -o no_posix_acl. As of now continuing to keeping the existing behavior if user did not specify any option to disable acl support due to concerns about backward compatibility. Signed-off-by: Vivek Goyal --- docs/tools/virtiofsd.rst | 3 + tools/virtiofsd/helper.c | 1 + tools/virtiofsd/passthrough_ll.c | 112 ++++++++++++++++++++++++++++++- 3 files changed, 115 insertions(+), 1 deletion(-) diff --git a/docs/tools/virtiofsd.rst b/docs/tools/virtiofsd.rst index 00554c75bd..a41f934999 100644 --- a/docs/tools/virtiofsd.rst +++ b/docs/tools/virtiofsd.rst @@ -101,6 +101,9 @@ Options Enable/disable extended attributes (xattr) on files and directories. = The default is ``no_xattr``. =20 + * posix_acl|no_posix_acl - + Enable/disable posix acl support. Posix ACLs are disabled by default`. + .. option:: --socket-path=3DPATH =20 Listen on vhost-user UNIX domain socket at PATH. diff --git a/tools/virtiofsd/helper.c b/tools/virtiofsd/helper.c index 28243b51b2..800a1a6801 100644 --- a/tools/virtiofsd/helper.c +++ b/tools/virtiofsd/helper.c @@ -183,6 +183,7 @@ void fuse_cmdline_help(void) " to virtiofsd from guest applica= tions.\n" " default: no_allow_direct_io\n" " -o announce_submounts Announce sub-mount points to th= e guest\n" + " -o posix_acl/no_posix_acl Enable/Disable posix_acl. (defa= ult: disabled)\n" ); } =20 diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough= _ll.c index e6ae3d38d7..fda6b90fb3 100644 --- a/tools/virtiofsd/passthrough_ll.c +++ b/tools/virtiofsd/passthrough_ll.c @@ -175,6 +175,7 @@ struct lo_data { int user_killpriv_v2, killpriv_v2; /* If set, virtiofsd is responsible for setting umask during creation = */ bool change_umask; + int user_posix_acl; }; =20 static const struct fuse_opt lo_opts[] =3D { @@ -207,6 +208,8 @@ static const struct fuse_opt lo_opts[] =3D { { "announce_submounts", offsetof(struct lo_data, announce_submounts), = 1 }, { "killpriv_v2", offsetof(struct lo_data, user_killpriv_v2), 1 }, { "no_killpriv_v2", offsetof(struct lo_data, user_killpriv_v2), 0 }, + { "posix_acl", offsetof(struct lo_data, user_posix_acl), 1 }, + { "no_posix_acl", offsetof(struct lo_data, user_posix_acl), 0 }, FUSE_OPT_END }; static bool use_syslog =3D false; @@ -705,6 +708,29 @@ static void lo_init(void *userdata, struct fuse_conn_i= nfo *conn) conn->want &=3D ~FUSE_CAP_HANDLE_KILLPRIV_V2; lo->killpriv_v2 =3D 0; } + + if (lo->user_posix_acl =3D=3D 1) { + /* + * User explicitly asked for this option. Enable it unconditionall= y. + * If connection does not have this capability, print error message + * now. It will fail later in fuse_lowlevel.c + */ + if (!(conn->capable & FUSE_CAP_POSIX_ACL) || + !(conn->capable & FUSE_CAP_DONT_MASK)) { + fuse_log(FUSE_LOG_ERR, "lo_init: Can not enable posix acl." + " kernel does not support FUSE_POSIX_ACL or FUSE_DONT= _MASK" + " capability.\n"); + } else { + fuse_log(FUSE_LOG_DEBUG, "lo_init: enabling posix acl\n"); + } + + conn->want |=3D FUSE_CAP_POSIX_ACL | FUSE_CAP_DONT_MASK; + lo->change_umask =3D true; + } else { + /* User either did not specify anything or wants it disabled */ + fuse_log(FUSE_LOG_DEBUG, "lo_init: disabling posix_acl\n"); + conn->want &=3D ~FUSE_CAP_POSIX_ACL; + } } =20 static void lo_getattr(fuse_req_t req, fuse_ino_t ino, @@ -2732,6 +2758,63 @@ static int xattr_map_server(const struct lo_data *lo= , const char *server_name, return -ENODATA; } =20 +static bool block_xattr(struct lo_data *lo, const char *name) +{ + /* + * If user explicitly enabled posix_acl or did not provide any option, + * do not block acl. Otherwise block system.posix_acl_access and + * system.posix_acl_default xattrs. + */ + if (lo->user_posix_acl) { + return false; + } + if (!strcmp(name, "system.posix_acl_access") || + !strcmp(name, "system.posix_acl_default")) + return true; + + return false; +} + +/* + * Returns number of bytes in xattr_list after filtering on success. This + * could be zero as well if nothing is left after filtering. + * + * Returns negative error code on failure. + * xattr_list is modified in place. + */ +static int remove_blocked_xattrs(struct lo_data *lo, char *xattr_list, + unsigned in_size) +{ + size_t out_index, in_index; + + /* + * As of now we only filter out acl xattrs. If acls are enabled or + * they have not been explicitly disabled, there is nothing to + * filter. + */ + if (lo->user_posix_acl) { + return in_size; + } + + out_index =3D 0; + in_index =3D 0; + while (in_index < in_size) { + char *in_ptr =3D xattr_list + in_index; + + /* Length of current attribute name */ + size_t in_len =3D strlen(xattr_list + in_index) + 1; + + if (!block_xattr(lo, in_ptr)) { + if (in_index !=3D out_index) { + memmove(xattr_list + out_index, xattr_list + in_index, in_= len); + } + out_index +=3D in_len; + } + in_index +=3D in_len; + } + return out_index; +} + static void lo_getxattr(fuse_req_t req, fuse_ino_t ino, const char *in_nam= e, size_t size) { @@ -2745,6 +2828,11 @@ static void lo_getxattr(fuse_req_t req, fuse_ino_t i= no, const char *in_name, int saverr; int fd =3D -1; =20 + if (block_xattr(lo, in_name)) { + fuse_reply_err(req, EOPNOTSUPP); + return; + } + mapped_name =3D NULL; name =3D in_name; if (lo->xattrmap) { @@ -2886,7 +2974,6 @@ static void lo_listxattr(fuse_req_t req, fuse_ino_t i= no, size_t size) if (ret =3D=3D 0) { goto out; } - if (lo->xattr_map_list) { /* * Map the names back, some attributes might be dropped, @@ -2933,6 +3020,12 @@ static void lo_listxattr(fuse_req_t req, fuse_ino_t = ino, size_t size) goto out; } } + + ret =3D remove_blocked_xattrs(lo, value, ret); + if (ret <=3D 0) { + saverr =3D -ret; + goto out; + } fuse_reply_buf(req, value, ret); } else { /* @@ -2971,6 +3064,11 @@ static void lo_setxattr(fuse_req_t req, fuse_ino_t i= no, const char *in_name, int saverr; int fd =3D -1; =20 + if (block_xattr(lo, in_name)) { + fuse_reply_err(req, EOPNOTSUPP); + return; + } + mapped_name =3D NULL; name =3D in_name; if (lo->xattrmap) { @@ -3037,6 +3135,11 @@ static void lo_removexattr(fuse_req_t req, fuse_ino_= t ino, const char *in_name) int saverr; int fd =3D -1; =20 + if (block_xattr(lo, in_name)) { + fuse_reply_err(req, EOPNOTSUPP); + return; + } + mapped_name =3D NULL; name =3D in_name; if (lo->xattrmap) { @@ -3730,6 +3833,7 @@ int main(int argc, char *argv[]) .allow_direct_io =3D 0, .proc_self_fd =3D -1, .user_killpriv_v2 =3D -1, + .user_posix_acl =3D -1, }; struct lo_map_elem *root_elem; struct lo_map_elem *reserve_elem; @@ -3857,6 +3961,12 @@ int main(int argc, char *argv[]) exit(1); } =20 + if (lo.user_posix_acl =3D=3D 1 && !lo.xattr) { + fuse_log(FUSE_LOG_ERR, "Can't enable posix ACLs. xattrs are disabl= ed." + "\n"); + exit(1); + } + lo.use_statx =3D true; =20 se =3D fuse_session_new(&args, &lo_oper, sizeof(lo_oper), &lo); --=20 2.25.4 From nobody Sun May 5 11:32:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1617117114; cv=none; d=zohomail.com; s=zohoarc; b=GxeW0b6ddJBgfJ+LkgNy6eVwM5jZ4dqK78jXGPCYoxfa6+cY+H5KOtpAqZO2ecMSQYKMHZw2vX0favsXbFmEYRRH5vFVPPEr2lsyYv5U3ApwqlALfpeIYn0EkwEeGK7/RS0QNpIrLkSTzKccuN1PLS0VVfUJNfwFYnr23/gRbT8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1617117114; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=5gJP52Zqh3kpE6TcUNZWjRxSQ69ELdgT6ZQo2ROocsg=; b=JodRQddmgCOWoZwJXduKwi6SnfQSU9Jp2Nv67nWbPHwdNvapXd581Eb3zYL26K/o1RnPcpWZxItxvKs0gD12ZD3PpEXl/QCUhGdk26rSGEOACk7PjUdbHNvT87EDdkEFnwl7bewNpOkDlTkTmvqTOHNqwvqWXQVuYLwWHI3MdS4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1617117114579182.1235331152426; Tue, 30 Mar 2021 08:11:54 -0700 (PDT) Received: from localhost ([::1]:49856 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lRFDn-0006n7-LR for importer@patchew.org; Tue, 30 Mar 2021 10:19:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53828) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lRF3z-0002tW-7M for qemu-devel@nongnu.org; Tue, 30 Mar 2021 10:09:47 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:36338) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lRF3v-00054U-4O for qemu-devel@nongnu.org; Tue, 30 Mar 2021 10:09:46 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-530-348H6Ia4P3KvkoaML_k4wA-1; Tue, 30 Mar 2021 10:09:36 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E830F83DBE2; Tue, 30 Mar 2021 14:09:35 +0000 (UTC) Received: from horse.redhat.com (ovpn-116-118.rdu2.redhat.com [10.10.116.118]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7FFBB60938; Tue, 30 Mar 2021 14:09:35 +0000 (UTC) Received: by horse.redhat.com (Postfix, from userid 10451) id 328E9225FCE; Tue, 30 Mar 2021 10:09:34 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617113380; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5gJP52Zqh3kpE6TcUNZWjRxSQ69ELdgT6ZQo2ROocsg=; b=ZzZd7c/OLTMMwdN3/u22Yi/v67w23Vwxla7xpsdCZuS8kXl5shPvypy4pUMNp8HMvWyIWY qAOR4kETjVYJFEC/GL0InQBYNre56OW6pOQhjFc5P9sjshjggOFCe1Oeh6BR6lXf7ge5kG VsGcStcOIedEZNwhFWg6xIfD5870lHM= X-MC-Unique: 348H6Ia4P3KvkoaML_k4wA-1 From: Vivek Goyal To: qemu-devel@nongnu.org, virtio-fs@redhat.com Subject: [PATCH v6 4/5] virtiofsd: Add support for setxattr_v2 Date: Tue, 30 Mar 2021 10:09:24 -0400 Message-Id: <20210330140925.730449-5-vgoyal@redhat.com> In-Reply-To: <20210330140925.730449-1-vgoyal@redhat.com> References: <20210330140925.730449-1-vgoyal@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=vgoyal@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=vgoyal@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lhenriques@suse.de, dgilbert@redhat.com, vgoyal@redhat.com, miklos@szeredi.hu Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Add the bits to enable support for setxattr_v2 if fuse offers it. Signed-off-by: Vivek Goyal --- include/standard-headers/linux/fuse.h | 12 +++++++- tools/virtiofsd/fuse_common.h | 6 ++++ tools/virtiofsd/fuse_lowlevel.c | 42 ++++++++++++++++++++++++++- tools/virtiofsd/fuse_lowlevel.h | 3 +- tools/virtiofsd/passthrough_ll.c | 3 +- 5 files changed, 62 insertions(+), 4 deletions(-) diff --git a/include/standard-headers/linux/fuse.h b/include/standard-heade= rs/linux/fuse.h index 950d7edb7e..cc87ff27d0 100644 --- a/include/standard-headers/linux/fuse.h +++ b/include/standard-headers/linux/fuse.h @@ -179,6 +179,7 @@ * 7.33 * - add FUSE_HANDLE_KILLPRIV_V2, FUSE_WRITE_KILL_SUIDGID, FATTR_KILL_SUI= DGID * - add FUSE_OPEN_KILL_SUIDGID + * - add FUSE_SETXATTR_V2 */ =20 #ifndef _LINUX_FUSE_H @@ -210,7 +211,7 @@ #define FUSE_KERNEL_VERSION 7 =20 /** Minor version number of this interface */ -#define FUSE_KERNEL_MINOR_VERSION 33 +#define FUSE_KERNEL_MINOR_VERSION 34 =20 /** The node ID of the root inode */ #define FUSE_ROOT_ID 1 @@ -326,6 +327,7 @@ struct fuse_file_lock { * does not have CAP_FSETID. Additionally upon * write/truncate sgid is killed only if file has group * execute permission. (Same as Linux VFS behavior). + * FUSE_SETXATTR_V2: Does file server support V2 of struct fuse_setxattr_in */ #define FUSE_ASYNC_READ (1 << 0) #define FUSE_POSIX_LOCKS (1 << 1) @@ -356,6 +358,7 @@ struct fuse_file_lock { #define FUSE_MAP_ALIGNMENT (1 << 26) #define FUSE_SUBMOUNTS (1 << 27) #define FUSE_HANDLE_KILLPRIV_V2 (1 << 28) +#define FUSE_SETXATTR_V2 (1 << 29) =20 /** * CUSE INIT request/reply flags @@ -682,6 +685,13 @@ struct fuse_setxattr_in { uint32_t flags; }; =20 +struct fuse_setxattr_in_v2 { + uint32_t size; + uint32_t flags; + uint32_t setxattr_flags; + uint32_t padding; +}; + struct fuse_getxattr_in { uint32_t size; uint32_t padding; diff --git a/tools/virtiofsd/fuse_common.h b/tools/virtiofsd/fuse_common.h index fa9671872e..84e78c2a56 100644 --- a/tools/virtiofsd/fuse_common.h +++ b/tools/virtiofsd/fuse_common.h @@ -372,6 +372,12 @@ struct fuse_file_info { */ #define FUSE_CAP_HANDLE_KILLPRIV_V2 (1 << 28) =20 +/** + * Indicates that file server will expect "struct fuse_setxattr_in_v2" type + * of struct in setxattr requests + */ +#define FUSE_CAP_SETXATTR_V2 (1 << 29) + /** * Ioctl flags * diff --git a/tools/virtiofsd/fuse_lowlevel.c b/tools/virtiofsd/fuse_lowleve= l.c index 58e32fc963..72f8252af8 100644 --- a/tools/virtiofsd/fuse_lowlevel.c +++ b/tools/virtiofsd/fuse_lowlevel.c @@ -1420,6 +1420,34 @@ static void do_statfs(fuse_req_t req, fuse_ino_t nod= eid, } } =20 +static void do_setxattr_v2(fuse_req_t req, fuse_ino_t nodeid, + struct fuse_mbuf_iter *iter) +{ + struct fuse_setxattr_in_v2 *arg; + const char *name; + const char *value; + + arg =3D fuse_mbuf_iter_advance(iter, sizeof(*arg)); + name =3D fuse_mbuf_iter_advance_str(iter); + if (!arg || !name) { + fuse_reply_err(req, EINVAL); + return; + } + + value =3D fuse_mbuf_iter_advance(iter, arg->size); + if (!value) { + fuse_reply_err(req, EINVAL); + return; + } + + if (req->se->op.setxattr) { + req->se->op.setxattr(req, nodeid, name, value, arg->size, arg->fla= gs, + arg->setxattr_flags); + } else { + fuse_reply_err(req, ENOSYS); + } +} + static void do_setxattr(fuse_req_t req, fuse_ino_t nodeid, struct fuse_mbuf_iter *iter) { @@ -1427,6 +1455,9 @@ static void do_setxattr(fuse_req_t req, fuse_ino_t no= deid, const char *name; const char *value; =20 + if (req->se->conn.want & FUSE_CAP_SETXATTR_V2) { + return do_setxattr_v2(req, nodeid, iter); + } arg =3D fuse_mbuf_iter_advance(iter, sizeof(*arg)); name =3D fuse_mbuf_iter_advance_str(iter); if (!arg || !name) { @@ -1441,7 +1472,8 @@ static void do_setxattr(fuse_req_t req, fuse_ino_t no= deid, } =20 if (req->se->op.setxattr) { - req->se->op.setxattr(req, nodeid, name, value, arg->size, arg->fla= gs); + req->se->op.setxattr(req, nodeid, name, value, arg->size, arg->fla= gs, + 0); } else { fuse_reply_err(req, ENOSYS); } @@ -1988,6 +2020,9 @@ static void do_init(fuse_req_t req, fuse_ino_t nodeid, if (arg->flags & FUSE_HANDLE_KILLPRIV_V2) { se->conn.capable |=3D FUSE_CAP_HANDLE_KILLPRIV_V2; } + if (arg->flags & FUSE_SETXATTR_V2) { + se->conn.capable |=3D FUSE_CAP_SETXATTR_V2; + } #ifdef HAVE_SPLICE #ifdef HAVE_VMSPLICE se->conn.capable |=3D FUSE_CAP_SPLICE_WRITE | FUSE_CAP_SPLICE_MOVE; @@ -2020,6 +2055,7 @@ static void do_init(fuse_req_t req, fuse_ino_t nodeid, LL_SET_DEFAULT(se->op.readdirplus, FUSE_CAP_READDIRPLUS); LL_SET_DEFAULT(se->op.readdirplus && se->op.readdir, FUSE_CAP_READDIRPLUS_AUTO); + LL_SET_DEFAULT(1, FUSE_CAP_SETXATTR_V2); se->conn.time_gran =3D 1; =20 if (bufsize < FUSE_MIN_READ_BUFFER) { @@ -2123,6 +2159,10 @@ static void do_init(fuse_req_t req, fuse_ino_t nodei= d, outarg.flags |=3D FUSE_HANDLE_KILLPRIV_V2; } =20 + if (se->conn.want & FUSE_CAP_SETXATTR_V2) { + outarg.flags |=3D FUSE_SETXATTR_V2; + } + fuse_log(FUSE_LOG_DEBUG, " INIT: %u.%u\n", outarg.major, outarg.mino= r); fuse_log(FUSE_LOG_DEBUG, " flags=3D0x%08x\n", outarg.flags); fuse_log(FUSE_LOG_DEBUG, " max_readahead=3D0x%08x\n", outarg.max_rea= dahead); diff --git a/tools/virtiofsd/fuse_lowlevel.h b/tools/virtiofsd/fuse_lowleve= l.h index 3bf786b034..4b4e8c9724 100644 --- a/tools/virtiofsd/fuse_lowlevel.h +++ b/tools/virtiofsd/fuse_lowlevel.h @@ -798,7 +798,8 @@ struct fuse_lowlevel_ops { * fuse_reply_err */ void (*setxattr)(fuse_req_t req, fuse_ino_t ino, const char *name, - const char *value, size_t size, int flags); + const char *value, size_t size, int flags, + uint32_t setxattr_flags); =20 /** * Get an extended attribute diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough= _ll.c index fda6b90fb3..c5a589441d 100644 --- a/tools/virtiofsd/passthrough_ll.c +++ b/tools/virtiofsd/passthrough_ll.c @@ -3053,7 +3053,8 @@ out: } =20 static void lo_setxattr(fuse_req_t req, fuse_ino_t ino, const char *in_nam= e, - const char *value, size_t size, int flags) + const char *value, size_t size, int flags, + uint32_t extra_flags) { char procname[64]; const char *name; --=20 2.25.4 From nobody Sun May 5 11:32:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1617117332; cv=none; d=zohomail.com; s=zohoarc; b=h3qQpo01mkOFNmL695D6ziHN0NF7o1jfHvZ4lakLrNbeE4wlIfOuYlq8eKllXT9V6GiqfgMYie/oh9pAxyNDHVxfMDa9cftY1vdV4Y6AOSzoCohoA7g6RhOrcCVvBsm20ARXJFhISns1/8VWQczj8FXEzjPALOOthA7fRNqp6VI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1617117332; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=rtS/g0OGOClDMjnADvuymU2io8u8AE6nWPE506Ug4tA=; b=mswQyx60eSn21e3mfJLQvv4fgxvwbNtuYUqNRcB8fkHw7/y7ZdtV2pQpbhxMK6XbC+HXZxzRO/Irrrmdm+EZ8SGJfdskpdmeUGgtPt5ahGYZAqs7SNfZNuPEdyS+kFx0Iz+sE8gpuiWIanGgRhG1zzchp11iYlkngoo85vPL/ME= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1617117332116881.0718416736136; Tue, 30 Mar 2021 08:15:32 -0700 (PDT) Received: from localhost ([::1]:55344 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lRFGF-0000kQ-Fa for importer@patchew.org; Tue, 30 Mar 2021 10:22:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53960) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lRF4D-00034a-1w for qemu-devel@nongnu.org; Tue, 30 Mar 2021 10:10:01 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:32622) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lRF3x-00056T-2k for qemu-devel@nongnu.org; Tue, 30 Mar 2021 10:10:00 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-342-3E4893LePjCqhMioXZXDOw-1; Tue, 30 Mar 2021 10:09:42 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E9E011B18BC3; Tue, 30 Mar 2021 14:09:39 +0000 (UTC) Received: from horse.redhat.com (ovpn-116-118.rdu2.redhat.com [10.10.116.118]) by smtp.corp.redhat.com (Postfix) with ESMTP id 79D645D9CC; Tue, 30 Mar 2021 14:09:36 +0000 (UTC) Received: by horse.redhat.com (Postfix, from userid 10451) id 371FC225FCF; Tue, 30 Mar 2021 10:09:34 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617113384; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rtS/g0OGOClDMjnADvuymU2io8u8AE6nWPE506Ug4tA=; b=XjBYjFFK2LLDDBgKi0PjK7ZfQNH6zVxd7F0t7KBUVhQHcwx+NeKl/1RNXLmcyvv1p1IdkP sPRX6KFSneMVZjGe/mAZvY9f8MLiWV7jor9YIEwMPN5CD5wge+NlfeifL+YxLC/h8LimLk CTiqwv6GpUjM9hLTpaYEDenbvxaqxk0= X-MC-Unique: 3E4893LePjCqhMioXZXDOw-1 From: Vivek Goyal To: qemu-devel@nongnu.org, virtio-fs@redhat.com Subject: [PATCH v6 5/5] virtiofsd: Switch creds, drop FSETID for system.posix_acl_access xattr Date: Tue, 30 Mar 2021 10:09:25 -0400 Message-Id: <20210330140925.730449-6-vgoyal@redhat.com> In-Reply-To: <20210330140925.730449-1-vgoyal@redhat.com> References: <20210330140925.730449-1-vgoyal@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=vgoyal@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=vgoyal@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lhenriques@suse.de, dgilbert@redhat.com, vgoyal@redhat.com, miklos@szeredi.hu Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" When posix access acls are set on a file, it can lead to adjusting file permissions (mode) as well. If caller does not have CAP_FSETID and it also does not have membership of owner group, this will lead to clearing SGID bit in mode. Current fuse code is written in such a way that it expects file server to take care of chaning file mode (permission), if there is a need. Right now, host kernel does not clear SGID bit because virtiofsd is running as root and has CAP_FSETID. For host kernel to clear SGID, virtiofsd need to switch to gid of caller in guest and also drop CAP_FSETID (if caller did not have it to begin with). If SGID needs to be cleared, client will set the flag FUSE_SETXATTR_ACL_KILL_SGID in setxattr request. In that case server should kill sgid. Currently just switch to uid/gid of the caller and drop CAP_FSETID and that should do it. This should fix the xfstest generic/375 test case. We don't have to switch uid for this to work. That could be one optimization that pass a parameter to lo_change_cred() to only switch gid and not uid. Also this will not work whenever (if ever) we support idmapped mounts. In that case it is possible that uid/gid in request are 0/0 but still we need to clear SGID. So we will have to pick a non-root sgid and switch to that instead. That's an TODO item for future when idmapped mount support is introduced. Reported-by: Luis Henriques Signed-off-by: Vivek Goyal --- include/standard-headers/linux/fuse.h | 7 ++++ tools/virtiofsd/passthrough_ll.c | 50 ++++++++++++++++++++++++--- 2 files changed, 52 insertions(+), 5 deletions(-) diff --git a/include/standard-headers/linux/fuse.h b/include/standard-heade= rs/linux/fuse.h index cc87ff27d0..4eb79399d4 100644 --- a/include/standard-headers/linux/fuse.h +++ b/include/standard-headers/linux/fuse.h @@ -180,6 +180,7 @@ * - add FUSE_HANDLE_KILLPRIV_V2, FUSE_WRITE_KILL_SUIDGID, FATTR_KILL_SUI= DGID * - add FUSE_OPEN_KILL_SUIDGID * - add FUSE_SETXATTR_V2 + * - add FUSE_SETXATTR_ACL_KILL_SGID */ =20 #ifndef _LINUX_FUSE_H @@ -450,6 +451,12 @@ struct fuse_file_lock { */ #define FUSE_OPEN_KILL_SUIDGID (1 << 0) =20 +/** + * setxattr flags + * FUSE_SETXATTR_ACL_KILL_SGID: Clear SGID when system.posix_acl_access is= set + */ +#define FUSE_SETXATTR_ACL_KILL_SGID (1 << 0) + enum fuse_opcode { FUSE_LOOKUP =3D 1, FUSE_FORGET =3D 2, /* no reply */ diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough= _ll.c index c5a589441d..a968dc4e61 100644 --- a/tools/virtiofsd/passthrough_ll.c +++ b/tools/virtiofsd/passthrough_ll.c @@ -175,7 +175,7 @@ struct lo_data { int user_killpriv_v2, killpriv_v2; /* If set, virtiofsd is responsible for setting umask during creation = */ bool change_umask; - int user_posix_acl; + int user_posix_acl, posix_acl; }; =20 static const struct fuse_opt lo_opts[] =3D { @@ -716,16 +716,19 @@ static void lo_init(void *userdata, struct fuse_conn_= info *conn) * now. It will fail later in fuse_lowlevel.c */ if (!(conn->capable & FUSE_CAP_POSIX_ACL) || - !(conn->capable & FUSE_CAP_DONT_MASK)) { + !(conn->capable & FUSE_CAP_DONT_MASK) || + !(conn->capable & FUSE_CAP_SETXATTR_V2)) { fuse_log(FUSE_LOG_ERR, "lo_init: Can not enable posix acl." - " kernel does not support FUSE_POSIX_ACL or FUSE_DONT= _MASK" - " capability.\n"); + " kernel does not support FUSE_POSIX_ACL, FUSE_DONT_M= ASK" + " or FUSE_SETXATTR_V2 capability.\n"); } else { fuse_log(FUSE_LOG_DEBUG, "lo_init: enabling posix acl\n"); } =20 - conn->want |=3D FUSE_CAP_POSIX_ACL | FUSE_CAP_DONT_MASK; + conn->want |=3D FUSE_CAP_POSIX_ACL | FUSE_CAP_DONT_MASK | + FUSE_CAP_SETXATTR_V2; lo->change_umask =3D true; + lo->posix_acl =3D true; } else { /* User either did not specify anything or wants it disabled */ fuse_log(FUSE_LOG_DEBUG, "lo_init: disabling posix_acl\n"); @@ -3100,12 +3103,49 @@ static void lo_setxattr(fuse_req_t req, fuse_ino_t = ino, const char *in_name, =20 sprintf(procname, "%i", inode->fd); if (S_ISREG(inode->filetype) || S_ISDIR(inode->filetype)) { + bool switched_creds =3D false; + struct lo_cred old =3D {}; + fd =3D openat(lo->proc_self_fd, procname, O_RDONLY); if (fd < 0) { saverr =3D errno; goto out; } + + /* + * If we are setting posix access acl and if SGID needs to be + * cleared, then switch to caller's gid and drop CAP_FSETID + * and that should make sure host kernel clears SGID. + * + * This probably will not work when we support idmapped mounts. + * In that case we will need to find a non-root gid and switch + * to it. (Instead of gid in request). Fix it when we support + * idmapped mounts. + */ + if (lo->posix_acl && !strcmp(name, "system.posix_acl_access") + && (extra_flags & FUSE_SETXATTR_ACL_KILL_SGID)) { + ret =3D lo_change_cred(req, &old, false); + if (ret) { + saverr =3D ret; + goto out; + } + ret =3D drop_effective_cap("FSETID", NULL); + if (ret !=3D 0) { + lo_restore_cred(&old, false); + saverr =3D ret; + goto out; + } + switched_creds =3D true; + } + ret =3D fsetxattr(fd, name, value, size, flags); + + if (switched_creds) { + if (gain_effective_cap("FSETID")) { + fuse_log(FUSE_LOG_ERR, "Failed to gain CAP_FSETID\n"); + } + lo_restore_cred(&old, false); + } } else { /* fchdir should not fail here */ assert(fchdir(lo->proc_self_fd) =3D=3D 0); --=20 2.25.4