From nobody Wed May 15 09:57:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1603473425; cv=none; d=zohomail.com; s=zohoarc; b=moSg2GsH0LaahipzzCNy9eu5R79Dio18E802q1DO6JZDlNtt2e62KuK7WOKUpYBLjJ3ZenKIDGxNP7pdQVIuxjCVGUcOsxUQssFTuYhD/uuCWNiQz5JToQV8rysduoQwa4LOnCK3NxG8W4ZjIJsyIk+03fLqEqhLvrfilrWpvyQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603473425; h=Content-Type:Content-Transfer-Encoding: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=hpypEx6GSXG1iA90tR9+xmS+weK9zNiwaau8KlRzKu0=; b=DaeQoPfuiFB851DuqweTrkEBavGDL+ZpDYKjwRW8dMz7o7PbmEFLGL45+AELGPf/SOK6ryvvH69i4iEcT47CuERueDGB2cKqp97yh3yy/1kls+X+X+YTI3D5jaZARgtVrYAFnKLVVMcyMNQQGpoDEc2XKS7BGYNSjyv0/iueD/g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1603473425539329.09576621846895; Fri, 23 Oct 2020 10:17:05 -0700 (PDT) Received: from localhost ([::1]:36838 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kW0ga-0002a8-6V for importer@patchew.org; Fri, 23 Oct 2020 13:17:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56044) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kW0On-0001Ks-07 for qemu-devel@nongnu.org; Fri, 23 Oct 2020 12:58:41 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:32260) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kW0Oc-00059j-Pe for qemu-devel@nongnu.org; Fri, 23 Oct 2020 12:58:40 -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-549-jLideVhSMIiuW8ErOfxJ6Q-1; Fri, 23 Oct 2020 12:58:27 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id ECB4A1074642 for ; Fri, 23 Oct 2020 16:58:26 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-113-212.ams2.redhat.com [10.36.113.212]) by smtp.corp.redhat.com (Postfix) with ESMTP id 950EB10013D7; Fri, 23 Oct 2020 16:58:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603472310; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hpypEx6GSXG1iA90tR9+xmS+weK9zNiwaau8KlRzKu0=; b=VHTeRxYkG2Oz027srWjBTIGiBFAxMFsOa6fSJJrw0ivW07SwS/gTVuqc8ktJgEDb3ySEMG HSY3xzQmloYXltlVrNfmU/WYrQx/hqM44BYZcEeuEeSmO/Tk/Vm6MbKF03vBtEcOMC3oq1 vtcaNJt0zb5J8/dh1W3aAhwL8OUenhU= X-MC-Unique: jLideVhSMIiuW8ErOfxJ6Q-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, stefanha@redhat.com, vgoyal@redhat.com, dinechin@redhat.com, virtio-fs@redhat.com Subject: [PATCH v4 1/5] tools/virtiofsd: xattr name mappings: Add option Date: Fri, 23 Oct 2020 17:58:08 +0100 Message-Id: <20201023165812.36028-2-dgilbert@redhat.com> In-Reply-To: <20201023165812.36028-1-dgilbert@redhat.com> References: <20201023165812.36028-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@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=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/23 01:44:00 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_NONE=-0.0001, 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: "Dr. David Alan Gilbert" Add an option to define mappings of xattr names so that the client and server filesystems see different views. This can be used to have different SELinux mappings as seen by the guest, to run the virtiofsd with less privileges (e.g. in a case where it can't set trusted/system/security xattrs but you want the guest to be able to), or to isolate multiple users of the same name; e.g. trusted attributes used by stacking overlayfs. A mapping engine is used with 3 simple rules; the rules can be combined to allow most useful mapping scenarios. The ruleset is defined by -o xattrmap=3D'rules...'. This patch doesn't use the rule maps yet. Signed-off-by: Dr. David Alan Gilbert Reviewed-by: Stefan Hajnoczi --- docs/tools/virtiofsd.rst | 92 ++++++++++++++++ tools/virtiofsd/passthrough_ll.c | 173 +++++++++++++++++++++++++++++++ 2 files changed, 265 insertions(+) diff --git a/docs/tools/virtiofsd.rst b/docs/tools/virtiofsd.rst index 7ecee49834..868fa0e97b 100644 --- a/docs/tools/virtiofsd.rst +++ b/docs/tools/virtiofsd.rst @@ -109,6 +109,98 @@ Options timeout. ``always`` sets a long cache lifetime at the expense of cohere= ncy. The default is ``auto``. =20 +xattr-mapping +------------- + +By default the name of xattr's used by the client are passed through to th= e server +file system. This can be a problem where either those xattr names are used +by something on the server (e.g. selinux client/server confusion) or if the +virtiofsd is running in a container with restricted privileges where it ca= nnot +access some attributes. + +A mapping of xattr names can be made using -o xattrmap=3Dmapping where the= ``mapping`` +string consists of a series of rules. + +The first matching rule terminates the mapping. +The set of rules must include a terminating rule to match any remaining at= tributes +at the end. + +Each rule consists of a number of fields separated with a separator that i= s the +first non-white space character in the rule. This separator must then be = used +for the whole rule. +White space may be added before and after each rule. +Using ':' as the separator a rule is of the form: + +``:type:scope:key:prepend:`` + +**scope** is: + +- 'client' - match 'key' against a xattr name from the client for + setxattr/getxattr/removexattr +- 'server' - match 'prepend' against a xattr name from the server + for listxattr +- 'all' - can be used to make a single rule where both the server + and client matches are triggered. + +**type** is one of: + +- 'prefix' - is designed to prepend and strip a prefix; the modified + attributes then being passed on to the client/server. + +- 'ok' - Causes the rule set to be terminated when a match is found + while allowing matching xattr's through unchanged. + It is intended both as a way of explicitly terminating + the list of rules, and to allow some xattr's to skip following rules. + +- 'bad' - If a client tries to use a name matching 'key' it's + denied using EPERM; when the server passes an attribute + name matching 'prepend' it's hidden. In many ways it's use is very like + 'ok' as either an explict terminator or for special handling of certain + patterns. + +**key** is a string tested as a prefix on an attribute name originating +on the client. It maybe empty in which case a 'client' rule +will always match on client names. + +**prepend** is a string tested as a prefix on an attribute name originating +on the server, and used as a new prefix. It may be empty +in which case a 'server' rule will always match on all names from +the server. + +e.g.: + + ``:prefix:client:trusted.:user.virtiofs.:`` + + will match 'trusted.' attributes in client calls and prefix them before + passing them to the server. + + ``:prefix:server::user.virtiofs.:`` + + will strip 'user.virtiofs.' from all server replies. + + ``:prefix:all:trusted.:user.virtiofs.:`` + + combines the previous two cases into a single rule. + + ``:ok:client:user.::`` + + will allow get/set xattr for 'user.' xattr's and ignore + following rules. + + ``:ok:server::security.:`` + + will pass 'securty.' xattr's in listxattr from the server + and ignore following rules. + + ``:ok:all:::`` + + will terminate the rule search passing any remaining attributes + in both directions. + + ``:bad:server::security.:`` + + would hide 'security.' xattr's in listxattr from the server. + Examples -------- =20 diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough= _ll.c index ff53df4451..d47fe3db31 100644 --- a/tools/virtiofsd/passthrough_ll.c +++ b/tools/virtiofsd/passthrough_ll.c @@ -64,6 +64,7 @@ #include #include =20 +#include "qemu/cutils.h" #include "passthrough_helpers.h" #include "passthrough_seccomp.h" =20 @@ -137,6 +138,12 @@ enum { CACHE_ALWAYS, }; =20 +typedef struct xattr_map_entry { + char *key; + char *prepend; + unsigned int flags; +} XattrMapEntry; + struct lo_data { pthread_mutex_t mutex; int debug; @@ -144,6 +151,7 @@ struct lo_data { int flock; int posix_lock; int xattr; + char *xattrmap; char *source; char *modcaps; double timeout; @@ -157,6 +165,8 @@ struct lo_data { struct lo_map ino_map; /* protected by lo->mutex */ struct lo_map dirp_map; /* protected by lo->mutex */ struct lo_map fd_map; /* protected by lo->mutex */ + XattrMapEntry *xattr_map_list; + size_t xattr_map_nentries; =20 /* An O_PATH file descriptor to /proc/self/fd/ */ int proc_self_fd; @@ -172,6 +182,7 @@ static const struct fuse_opt lo_opts[] =3D { { "no_posix_lock", offsetof(struct lo_data, posix_lock), 0 }, { "xattr", offsetof(struct lo_data, xattr), 1 }, { "no_xattr", offsetof(struct lo_data, xattr), 0 }, + { "xattrmap=3D%s", offsetof(struct lo_data, xattrmap), 0 }, { "modcaps=3D%s", offsetof(struct lo_data, modcaps), 0 }, { "timeout=3D%lf", offsetof(struct lo_data, timeout), 0 }, { "timeout=3D", offsetof(struct lo_data, timeout_set), 1 }, @@ -2010,6 +2021,161 @@ static void lo_flock(fuse_req_t req, fuse_ino_t ino= , struct fuse_file_info *fi, fuse_reply_err(req, res =3D=3D -1 ? errno : 0); } =20 +/* types */ +/* + * Exit; process attribute unmodified if matched. + * An empty key applies to all. + */ +#define XATTR_MAP_FLAG_OK (1 << 0) +/* + * The attribute is unwanted; + * EPERM on write, hidden on read. + */ +#define XATTR_MAP_FLAG_BAD (1 << 1) +/* + * For attr that start with 'key' prepend 'prepend' + * 'key' may be empty to prepend for all attrs + * key is defined from set/remove point of view. + * Automatically reversed on read + */ +#define XATTR_MAP_FLAG_PREFIX (1 << 2) + +/* scopes */ +/* Apply rule to get/set/remove */ +#define XATTR_MAP_FLAG_CLIENT (1 << 16) +/* Apply rule to list */ +#define XATTR_MAP_FLAG_SERVER (1 << 17) +/* Apply rule to all */ +#define XATTR_MAP_FLAG_ALL (XATTR_MAP_FLAG_SERVER | XATTR_MAP_FLAG_CLIEN= T) + +static void add_xattrmap_entry(struct lo_data *lo, + const XattrMapEntry *new_entry) +{ + XattrMapEntry *res =3D g_realloc_n(lo->xattr_map_list, + lo->xattr_map_nentries + 1, + sizeof(XattrMapEntry)); + res[lo->xattr_map_nentries++] =3D *new_entry; + + lo->xattr_map_list =3D res; +} + +static void free_xattrmap(struct lo_data *lo) +{ + XattrMapEntry *map =3D lo->xattr_map_list; + size_t i; + + if (!map) { + return; + } + + for (i =3D 0; i < lo->xattr_map_nentries; i++) { + g_free(map[i].key); + g_free(map[i].prepend); + }; + + g_free(map); + lo->xattr_map_list =3D NULL; + lo->xattr_map_nentries =3D -1; +} + +static void parse_xattrmap(struct lo_data *lo) +{ + const char *map =3D lo->xattrmap; + const char *tmp; + + lo->xattr_map_nentries =3D 0; + while (*map) { + XattrMapEntry tmp_entry; + char sep; + + if (isspace(*map)) { + map++; + continue; + } + /* The separator is the first non-space of the rule */ + sep =3D *map++; + if (!sep) { + break; + } + + tmp_entry.flags =3D 0; + /* Start of 'type' */ + if (strstart(map, "prefix", &map)) { + tmp_entry.flags |=3D XATTR_MAP_FLAG_PREFIX; + } else if (strstart(map, "ok", &map)) { + tmp_entry.flags |=3D XATTR_MAP_FLAG_OK; + } else if (strstart(map, "bad", &map)) { + tmp_entry.flags |=3D XATTR_MAP_FLAG_BAD; + } else { + fuse_log(FUSE_LOG_ERR, + "%s: Unexpected type;" + "Expecting 'prefix', 'ok', or 'bad' in rule %zu\n", + __func__, lo->xattr_map_nentries); + exit(1); + } + + if (*map++ !=3D sep) { + fuse_log(FUSE_LOG_ERR, + "%s: Missing '%c' at end of type field of rule %zu\n", + __func__, sep, lo->xattr_map_nentries); + exit(1); + } + + /* Start of 'scope' */ + if (strstart(map, "client", &map)) { + tmp_entry.flags |=3D XATTR_MAP_FLAG_CLIENT; + } else if (strstart(map, "server", &map)) { + tmp_entry.flags |=3D XATTR_MAP_FLAG_SERVER; + } else if (strstart(map, "all", &map)) { + tmp_entry.flags |=3D XATTR_MAP_FLAG_ALL; + } else { + fuse_log(FUSE_LOG_ERR, + "%s: Unexpected scope;" + " Expecting 'client', 'server', or 'all', in rule %zu= \n", + __func__, lo->xattr_map_nentries); + exit(1); + } + + if (*map++ !=3D sep) { + fuse_log(FUSE_LOG_ERR, + "%s: Expecting '%c' found '%c'" + " after scope in rule %zu\n", + __func__, sep, *map, lo->xattr_map_nentries); + exit(1); + } + + /* At start of 'key' field */ + tmp =3D strchr(map, sep); + if (!tmp) { + fuse_log(FUSE_LOG_ERR, + "%s: Missing '%c' at end of key field of rule %zu", + __func__, sep, lo->xattr_map_nentries); + exit(1); + } + tmp_entry.key =3D g_strndup(map, tmp - map); + map =3D tmp + 1; + + /* At start of 'prepend' field */ + tmp =3D strchr(map, sep); + if (!tmp) { + fuse_log(FUSE_LOG_ERR, + "%s: Missing '%c' at end of prepend field of rule %zu= ", + __func__, sep, lo->xattr_map_nentries); + exit(1); + } + tmp_entry.prepend =3D g_strndup(map, tmp - map); + map =3D tmp + 1; + + add_xattrmap_entry(lo, &tmp_entry); + /* End of rule - go around again for another rule */ + } + + if (!lo->xattr_map_nentries) { + fuse_log(FUSE_LOG_ERR, "Empty xattr map\n"); + exit(1); + } +} + static void lo_getxattr(fuse_req_t req, fuse_ino_t ino, const char *name, size_t size) { @@ -2806,6 +2972,8 @@ static void fuse_lo_data_cleanup(struct lo_data *lo) close(lo->root.fd); } =20 + free(lo->xattrmap); + free_xattrmap(lo); free(lo->source); } =20 @@ -2906,6 +3074,11 @@ int main(int argc, char *argv[]) } else { lo.source =3D strdup("/"); } + + if (lo.xattrmap) { + parse_xattrmap(&lo); + } + if (!lo.timeout_set) { switch (lo.cache) { case CACHE_NONE: --=20 2.28.0 From nobody Wed May 15 09:57:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1603472651; cv=none; d=zohomail.com; s=zohoarc; b=EGEYr/q/OsjAqJuHTMkIK9U44MaE5JogD2oSsn9waim4l2PLxhBSKTBbtS1HrjM1pqCV/cQCmeENxCc6Cg3dyeYbKOqnTYwW4+paynFHmHHK5zSlY40TLVefJmrhwg+A/xhppAYsd2f0fYFFkVUt3BOwXRzwr3MM3CojHwGt4g8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603472651; h=Content-Type:Content-Transfer-Encoding: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=TSDWjWEqs/z+Rjo4H/tYL8xvBGokWHXRX6SfnwxYerI=; b=MQHmXoavP/9YkZypBRrvxjOzy+WYW3nOmEaMaz71enCbFNc+QsNKZvY1UMInFHbun0jyZIZssx02CJC3Hw4Aj87P9wuaenU1q5rcx+ZDo/uRp8Xbob5KBt9HyddToZiwCjc7eVtjBw+SrfM4+C19ePB1SpIlb1dTXDQ1hqqFRwA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1603472651695992.8120492800177; Fri, 23 Oct 2020 10:04:11 -0700 (PDT) Received: from localhost ([::1]:60420 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kW0U6-0005Xt-4h for importer@patchew.org; Fri, 23 Oct 2020 13:04:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56090) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kW0Oo-0001NG-Ht for qemu-devel@nongnu.org; Fri, 23 Oct 2020 12:58:42 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:37819) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kW0Oi-0005A6-Ie for qemu-devel@nongnu.org; Fri, 23 Oct 2020 12:58:42 -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-575-_YQYOpO-P1y1GsNrOUzcoA-1; Fri, 23 Oct 2020 12:58:29 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 78122805EF8 for ; Fri, 23 Oct 2020 16:58:28 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-113-212.ams2.redhat.com [10.36.113.212]) by smtp.corp.redhat.com (Postfix) with ESMTP id 44DC810013D7; Fri, 23 Oct 2020 16:58:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603472311; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TSDWjWEqs/z+Rjo4H/tYL8xvBGokWHXRX6SfnwxYerI=; b=S32JTRw6iXw2SLsKCRZjLA9hz1sUHByXNWmeiULP5bHXBa7ZmfOFXcyvuLgc5se6gicI4X TV6TXSA1ChI5YhBM/W3/dMVT84AejqLNSXrTnKJ4gvZ8rwDnskPjvLuiKCbXOpYv0+ycuU smX5QMA12CfbSl+VIFbbYfPzL6VaSgQ= X-MC-Unique: _YQYOpO-P1y1GsNrOUzcoA-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, stefanha@redhat.com, vgoyal@redhat.com, dinechin@redhat.com, virtio-fs@redhat.com Subject: [PATCH v4 2/5] tools/virtiofsd: xattr name mappings: Map client xattr names Date: Fri, 23 Oct 2020 17:58:09 +0100 Message-Id: <20201023165812.36028-3-dgilbert@redhat.com> In-Reply-To: <20201023165812.36028-1-dgilbert@redhat.com> References: <20201023165812.36028-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@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=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/23 01:44:00 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_NONE=-0.0001, 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: "Dr. David Alan Gilbert" Map xattr names originating at the client; from get/set/remove xattr. Signed-off-by: Dr. David Alan Gilbert Reviewed-by: Stefan Hajnoczi --- tools/virtiofsd/passthrough_ll.c | 101 ++++++++++++++++++++++++++++++- 1 file changed, 98 insertions(+), 3 deletions(-) diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough= _ll.c index d47fe3db31..ec3ef7b50d 100644 --- a/tools/virtiofsd/passthrough_ll.c +++ b/tools/virtiofsd/passthrough_ll.c @@ -2176,20 +2176,80 @@ static void parse_xattrmap(struct lo_data *lo) } } =20 -static void lo_getxattr(fuse_req_t req, fuse_ino_t ino, const char *name, +/* + * For use with getxattr/setxattr/removexattr, where the client + * gives us a name and we may need to choose a different one. + * Allocates a buffer for the result placing it in *out_name. + * If there's no change then *out_name is not set. + * Returns 0 on success + * Can return -EPERM to indicate we block a given attribute + * (in which case out_name is not allocated) + * Can return -ENOMEM to indicate out_name couldn't be allocated. + */ +static int xattr_map_client(const struct lo_data *lo, const char *client_n= ame, + char **out_name) +{ + size_t i; + for (i =3D 0; i < lo->xattr_map_nentries; i++) { + const XattrMapEntry *cur_entry =3D lo->xattr_map_list + i; + + if ((cur_entry->flags & XATTR_MAP_FLAG_CLIENT) && + (strstart(client_name, cur_entry->key, NULL))) { + if (cur_entry->flags & XATTR_MAP_FLAG_BAD) { + return -EPERM; + } + if (cur_entry->flags & XATTR_MAP_FLAG_OK) { + /* Unmodified name */ + return 0; + } + if (cur_entry->flags & XATTR_MAP_FLAG_PREFIX) { + *out_name =3D g_try_malloc(strlen(client_name) + + strlen(cur_entry->prepend) + 1); + if (!*out_name) { + return -ENOMEM; + } + sprintf(*out_name, "%s%s", cur_entry->prepend, client_name= ); + return 0; + } + } + } + + return -EPERM; +} + +static void lo_getxattr(fuse_req_t req, fuse_ino_t ino, const char *in_nam= e, size_t size) { struct lo_data *lo =3D lo_data(req); char *value =3D NULL; char procname[64]; + const char *name; + char *mapped_name; struct lo_inode *inode; ssize_t ret; int saverr; int fd =3D -1; =20 + mapped_name =3D NULL; + name =3D in_name; + if (lo->xattrmap) { + ret =3D xattr_map_client(lo, in_name, &mapped_name); + if (ret < 0) { + if (ret =3D=3D -EPERM) { + ret =3D -ENODATA; + } + fuse_reply_err(req, -ret); + return; + } + if (mapped_name) { + name =3D mapped_name; + } + } + inode =3D lo_inode(req, ino); if (!inode) { fuse_reply_err(req, EBADF); + g_free(mapped_name); return; } =20 @@ -2254,6 +2314,7 @@ out_err: saverr =3D errno; out: fuse_reply_err(req, saverr); + g_free(mapped_name); goto out_free; } =20 @@ -2331,19 +2392,35 @@ out: goto out_free; } =20 -static void lo_setxattr(fuse_req_t req, fuse_ino_t ino, const char *name, +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) { char procname[64]; + const char *name; + char *mapped_name; struct lo_data *lo =3D lo_data(req); struct lo_inode *inode; ssize_t ret; int saverr; int fd =3D -1; =20 + mapped_name =3D NULL; + name =3D in_name; + if (lo->xattrmap) { + ret =3D xattr_map_client(lo, in_name, &mapped_name); + if (ret < 0) { + fuse_reply_err(req, -ret); + return; + } + if (mapped_name) { + name =3D mapped_name; + } + } + inode =3D lo_inode(req, ino); if (!inode) { fuse_reply_err(req, EBADF); + g_free(mapped_name); return; } =20 @@ -2378,21 +2455,38 @@ out: } =20 lo_inode_put(lo, &inode); + g_free(mapped_name); fuse_reply_err(req, saverr); } =20 -static void lo_removexattr(fuse_req_t req, fuse_ino_t ino, const char *nam= e) +static void lo_removexattr(fuse_req_t req, fuse_ino_t ino, const char *in_= name) { char procname[64]; + const char *name; + char *mapped_name; struct lo_data *lo =3D lo_data(req); struct lo_inode *inode; ssize_t ret; int saverr; int fd =3D -1; =20 + mapped_name =3D NULL; + name =3D in_name; + if (lo->xattrmap) { + ret =3D xattr_map_client(lo, in_name, &mapped_name); + if (ret < 0) { + fuse_reply_err(req, -ret); + return; + } + if (mapped_name) { + name =3D mapped_name; + } + } + inode =3D lo_inode(req, ino); if (!inode) { fuse_reply_err(req, EBADF); + g_free(mapped_name); return; } =20 @@ -2427,6 +2521,7 @@ out: } =20 lo_inode_put(lo, &inode); + g_free(mapped_name); fuse_reply_err(req, saverr); } =20 --=20 2.28.0 From nobody Wed May 15 09:57:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1603473495; cv=none; d=zohomail.com; s=zohoarc; b=JioTN98RK+vI9PoQgPcf9CdcM1q5TI7ViyMGol4MPSh6S6Wsk6svKNkkpzNu7OOKRqBzwqLx7U5n3mm+f+DsxF6yta9ciT6k8MYzZGQY0/4nnyaQ4UW59ecBiJeD+zmJ59aCmfKzMqJoU05350stCcDa6XE2jV6ASNmFtCzn21U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603473495; h=Content-Type:Content-Transfer-Encoding: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=gDwvzkFNIweZmShw1wlRU7uHBoUQJTTBSzbW+CLl6CM=; b=aYem7kjilRlJmgSj6WbO8cB720ZAY5Wys6Y80q/tAgkTkg1MW68wCKe/LC2fC2tmBQ2z/fZbJytdEFitGCtd160lidANBIqw+b3Zgdzm9wZqK7ldNHRcb92+9njnGyEQFu9mUt/ak4pFfZ068BeqO5XpPJiVpgkM1VodYEJVTng= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1603473495053402.3328248146564; Fri, 23 Oct 2020 10:18:15 -0700 (PDT) Received: from localhost ([::1]:38952 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kW0hh-0003Tc-SG for importer@patchew.org; Fri, 23 Oct 2020 13:18:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56056) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kW0On-0001Le-Fm for qemu-devel@nongnu.org; Fri, 23 Oct 2020 12:58:41 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:28812) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kW0Oi-0005AE-Ie for qemu-devel@nongnu.org; Fri, 23 Oct 2020 12:58:41 -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-593-jfg-zVE4PgSounPqtOUYmw-1; Fri, 23 Oct 2020 12:58:31 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 07D45804B7A for ; Fri, 23 Oct 2020 16:58:30 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-113-212.ams2.redhat.com [10.36.113.212]) by smtp.corp.redhat.com (Postfix) with ESMTP id C628E10013D7; Fri, 23 Oct 2020 16:58:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603472312; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gDwvzkFNIweZmShw1wlRU7uHBoUQJTTBSzbW+CLl6CM=; b=TV/xjn/v1APmMflUlLk8f2FaIBkoZX4C+GloCF0ZvPx9u+tty/DBqdNIkCKtPU0hAjpbDT VdsfU0qev/3Dy6eOAfQ2McLKscHDesvbyRFsh7Oo+aB9Ax4GwXtmbXocUMOhC8cVR82lb+ Q1QviIpDrPJnFL5mbGZV4Mo6TqlfR2c= X-MC-Unique: jfg-zVE4PgSounPqtOUYmw-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, stefanha@redhat.com, vgoyal@redhat.com, dinechin@redhat.com, virtio-fs@redhat.com Subject: [PATCH v4 3/5] tools/virtiofsd: xattr name mappings: Map server xattr names Date: Fri, 23 Oct 2020 17:58:10 +0100 Message-Id: <20201023165812.36028-4-dgilbert@redhat.com> In-Reply-To: <20201023165812.36028-1-dgilbert@redhat.com> References: <20201023165812.36028-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@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=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/23 01:44:00 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_NONE=-0.0001, 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: "Dr. David Alan Gilbert" Map xattr names coming from the server, i.e. the host filesystem; currently this is only from listxattr. Signed-off-by: Dr. David Alan Gilbert Reviewed-by: Stefan Hajnoczi --- tools/virtiofsd/passthrough_ll.c | 90 ++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough= _ll.c index ec3ef7b50d..57f584ee49 100644 --- a/tools/virtiofsd/passthrough_ll.c +++ b/tools/virtiofsd/passthrough_ll.c @@ -2217,6 +2217,44 @@ static int xattr_map_client(const struct lo_data *lo= , const char *client_name, return -EPERM; } =20 +/* + * For use with listxattr where the server fs gives us a name and we may n= eed + * to sanitize this for the client. + * Returns a pointer to the result in *out_name + * This is always the original string or the current string with some pr= efix + * removed; no reallocation is done. + * Returns 0 on success + * Can return -ENODATA to indicate the name should be dropped from the lis= t. + */ +static int xattr_map_server(const struct lo_data *lo, const char *server_n= ame, + const char **out_name) +{ + size_t i; + const char *end; + + for (i =3D 0; i < lo->xattr_map_nentries; i++) { + const XattrMapEntry *cur_entry =3D lo->xattr_map_list + i; + + if ((cur_entry->flags & XATTR_MAP_FLAG_SERVER) && + (strstart(server_name, cur_entry->prepend, &end))) { + if (cur_entry->flags & XATTR_MAP_FLAG_BAD) { + return -ENODATA; + } + if (cur_entry->flags & XATTR_MAP_FLAG_OK) { + *out_name =3D server_name; + return 0; + } + if (cur_entry->flags & XATTR_MAP_FLAG_PREFIX) { + /* Remove prefix */ + *out_name =3D end; + return 0; + } + } + } + + return -ENODATA; +} + static void lo_getxattr(fuse_req_t req, fuse_ino_t ino, const char *in_nam= e, size_t size) { @@ -2371,8 +2409,60 @@ static void lo_listxattr(fuse_req_t req, fuse_ino_t = ino, size_t size) if (ret =3D=3D 0) { goto out; } + + if (lo->xattr_map_list) { + /* + * Map the names back, some attributes might be dropped, + * some shortened, but not increased, so we shouldn't + * run out of room. + */ + size_t out_index, in_index; + out_index =3D 0; + in_index =3D 0; + while (in_index < ret) { + const char *map_out; + char *in_ptr =3D value + in_index; + /* Length of current attribute name */ + size_t in_len =3D strlen(value + in_index) + 1; + + int mapret =3D xattr_map_server(lo, in_ptr, &map_out); + if (mapret !=3D -ENODATA && mapret !=3D 0) { + /* Shouldn't happen */ + saverr =3D -mapret; + goto out; + } + if (mapret =3D=3D 0) { + /* Either unchanged, or truncated */ + size_t out_len; + if (map_out !=3D in_ptr) { + /* +1 copies the NIL */ + out_len =3D strlen(map_out) + 1; + } else { + /* No change */ + out_len =3D in_len; + } + /* + * Move result along, may still be needed for an uncha= nged + * entry if a previous entry was changed. + */ + memmove(value + out_index, map_out, out_len); + + out_index +=3D out_len; + } + in_index +=3D in_len; + } + ret =3D out_index; + if (ret =3D=3D 0) { + goto out; + } + } fuse_reply_buf(req, value, ret); } else { + /* + * xattrmap only ever shortens the result, + * so we don't need to do anything clever with the + * allocation length here. + */ fuse_reply_xattr(req, ret); } out_free: --=20 2.28.0 From nobody Wed May 15 09:57:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1603473672; cv=none; d=zohomail.com; s=zohoarc; b=iXDotr3HlLhMBb+ia80fuYrGFZLRyCixiGwIT5k+lojSRj21VteztXQphzSrtQ4pR9yofNSQp5naVtkYU2nnaHwpVwkZh4unn706jmJ9o3NjG9JJ7sW/MbxLSjEL7sVBiXCi7+VwXprwuwyGaPAZ82kGgXDeHGplLK/6FqTpX/8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603473672; h=Content-Type:Content-Transfer-Encoding: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=Kmj8Qu9zk6u8styP1oVh44uMPcepAPf0nIT1VcNsAjw=; b=etl3yzINRaEYrl/w+0hYVoh1DTE2e0SIs0w8MfuQ26GY1SrIObKfj8jkqZkMattRyppSd8jmfky27rbijlAoA8jP1kVDILOWT6b5ZU6/IJgScsiMHdjfkEii9JxvuTvh0cNQvxez/23hG8BMrIYdvx2JPjYzG7A4ZaYgY72uD8k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1603473672063369.09610408126116; Fri, 23 Oct 2020 10:21:12 -0700 (PDT) Received: from localhost ([::1]:44580 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kW0kZ-0005wX-1Z for importer@patchew.org; Fri, 23 Oct 2020 13:21:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56108) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kW0Op-0001P4-9S for qemu-devel@nongnu.org; Fri, 23 Oct 2020 12:58:43 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:47830) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kW0Oi-0005AM-Ki for qemu-devel@nongnu.org; Fri, 23 Oct 2020 12:58:42 -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-35-yMyevcvJPyKXAjlgBScccQ-1; Fri, 23 Oct 2020 12:58:32 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 885091007466 for ; Fri, 23 Oct 2020 16:58:31 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-113-212.ams2.redhat.com [10.36.113.212]) by smtp.corp.redhat.com (Postfix) with ESMTP id 52D4A10013D7; Fri, 23 Oct 2020 16:58:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603472314; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Kmj8Qu9zk6u8styP1oVh44uMPcepAPf0nIT1VcNsAjw=; b=dqOIudcUTWnIbGXxEwQkUrzsAM08dfaam2mftWSt/+yt0EqTJRruP84RJTT6P8sApZI+K2 3ZCELzalfOWPeuLub0/Z/c1rjQgMDQ1bUEI6S5LtKflSWIMWl0JOeZRQIT9mduh6bf/7Hj ya6RIacldXexFs6AY5KktZ3u64H22C0= X-MC-Unique: yMyevcvJPyKXAjlgBScccQ-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, stefanha@redhat.com, vgoyal@redhat.com, dinechin@redhat.com, virtio-fs@redhat.com Subject: [PATCH v4 4/5] tools/virtiofsd: xattr name mapping examples Date: Fri, 23 Oct 2020 17:58:11 +0100 Message-Id: <20201023165812.36028-5-dgilbert@redhat.com> In-Reply-To: <20201023165812.36028-1-dgilbert@redhat.com> References: <20201023165812.36028-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@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=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/23 01:44:00 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_NONE=-0.0001, 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: "Dr. David Alan Gilbert" Add a few examples of xattrmaps to the documentation. Signed-off-by: Dr. David Alan Gilbert Reviewed-by: Stefan Hajnoczi --- docs/tools/virtiofsd.rst | 50 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/docs/tools/virtiofsd.rst b/docs/tools/virtiofsd.rst index 868fa0e97b..4e74690eca 100644 --- a/docs/tools/virtiofsd.rst +++ b/docs/tools/virtiofsd.rst @@ -201,6 +201,56 @@ e.g.: =20 would hide 'security.' xattr's in listxattr from the server. =20 +xattr-mapping Examples +---------------------- + +1) Prefix all attributes with 'user.virtiofs.' + +:: + +-o xattrmap=3D":prefix:all::user.virtiofs.::bad:all:::" + + +This uses two rules, using : as the field separator; +the first rule prefixes and strips 'user.virtiofs.', +the second rule hides any non-prefixed attributes that +the host set. + +2) Prefix 'trusted.' attributes, allow others through + +:: + + "/prefix/all/trusted./user.virtiofs./ + /bad/server//trusted./ + /bad/client/user.virtiofs.// + /ok/all///" + + +Here there are four rules, using / as the field +separator, and also demonstrating that new lines can +be included between rules. +The first rule is the prefixing of 'trusted.' and +stripping of 'user.virtiofs.'. +The second rule hides unprefixed 'trusted.' attributes +on the host. +The third rule stops a guest from explicitly setting +the 'user.viritofs.' path directly. +Finally, the fourth rule lets all remaining attributes +through. + +3) Hide 'security.' attributes, and allow everything else + +:: + + "/bad/all/security./security./ + /ok/all///' + +The first rule combines what could be separate client and server +rules into a single 'all' rule, matching 'security.' in either +client arguments or lists returned from the host. This stops +the client seeing any 'security.' attributes on the server and +stops it setting any. + Examples -------- =20 --=20 2.28.0 From nobody Wed May 15 09:57:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1603473558; cv=none; d=zohomail.com; s=zohoarc; b=SW6fE7I12Q7qhETG7lwUj4M43qkFU5jS44rL+Pehc4K+FQmtpgqxpByOyxE2+B6K1MmZKGJ+NlXKjfAtXCxqN9X5J5zKPC19RAyjgaZehEV7Ui3XJWtZSMG8ytBmeR2kysUnhrgp9A7452h0oQE1bFTWLSYBDdkw7SxMAhdvYus= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603473558; h=Content-Type:Content-Transfer-Encoding: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=9+wyqoxRoHamLhKSdNFz5fBLOjHkBSk5R3XheaiQ8mE=; b=MtC1l5qv3cXzg7nuvh2jZBBLS/GxqNnRv5ZrIcrVKiaB4aVZtDZdaJVXcZ3NYo064NidBswWDctA+4uKvZaYdNkQI1uTB0IpZ7ygduNmT7R1S22HZoJo0ZVLYOAjcKHBQ0BiBoyd5mUDjNMzudm/zKb05CojtIJ+aLenzQoyHUI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1603473558118401.5569571990603; Fri, 23 Oct 2020 10:19:18 -0700 (PDT) Received: from localhost ([::1]:41054 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kW0ij-0004M4-4H for importer@patchew.org; Fri, 23 Oct 2020 13:19:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56096) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kW0Oo-0001NY-Nj for qemu-devel@nongnu.org; Fri, 23 Oct 2020 12:58:42 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:45563) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kW0Oi-0005AZ-K9 for qemu-devel@nongnu.org; Fri, 23 Oct 2020 12:58:42 -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-273-Z76WtehkPXehvlWWVGpBeQ-1; Fri, 23 Oct 2020 12:58:34 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 136C81007463 for ; Fri, 23 Oct 2020 16:58:33 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-113-212.ams2.redhat.com [10.36.113.212]) by smtp.corp.redhat.com (Postfix) with ESMTP id D7F241002388; Fri, 23 Oct 2020 16:58:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603472315; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9+wyqoxRoHamLhKSdNFz5fBLOjHkBSk5R3XheaiQ8mE=; b=DDhLBLAvhM/WdXtssoQ9+7YqM4iLHokhLCelQpgnntU1SHHVscoskuFlrCnZjb3NffhXZ7 ZAgXz7A6b8FMnzT2JR3b7nnE38AJlcjfDQkdvxHqzcnqqSpx60406Zc09WvuB8wQLTdGU0 O0xK35BMf499uBoeb6fIWsJlRBz74AA= X-MC-Unique: Z76WtehkPXehvlWWVGpBeQ-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, stefanha@redhat.com, vgoyal@redhat.com, dinechin@redhat.com, virtio-fs@redhat.com Subject: [PATCH v4 5/5] tools/virtiofsd: xattr name mappings: Simple 'map' Date: Fri, 23 Oct 2020 17:58:12 +0100 Message-Id: <20201023165812.36028-6-dgilbert@redhat.com> In-Reply-To: <20201023165812.36028-1-dgilbert@redhat.com> References: <20201023165812.36028-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@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=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/23 01:44:00 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_NONE=-0.0001, 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: "Dr. David Alan Gilbert" The mapping rule system implemented in the last few patches is extremely flexible, but not easy to use. Add a simple 'map' type as a sprinkling of sugar to make it easy. e.g. -o xattrmap=3D":map::user.virtiofs.:" would be sufficient to prefix all xattr's or -o xattrmap=3D":map:trusted.:user.virtiofs.:" would just prefix 'trusted.' xattr's and leave everything else alone. Signed-off-by: Dr. David Alan Gilbert Reviewed-by: Stefan Hajnoczi --- docs/tools/virtiofsd.rst | 19 ++++++ tools/virtiofsd/passthrough_ll.c | 112 ++++++++++++++++++++++++++++++- 2 files changed, 130 insertions(+), 1 deletion(-) diff --git a/docs/tools/virtiofsd.rst b/docs/tools/virtiofsd.rst index 4e74690eca..24268fd67e 100644 --- a/docs/tools/virtiofsd.rst +++ b/docs/tools/virtiofsd.rst @@ -129,6 +129,7 @@ Each rule consists of a number of fields separated with= a separator that is the first non-white space character in the rule. This separator must then be = used for the whole rule. White space may be added before and after each rule. + Using ':' as the separator a rule is of the form: =20 ``:type:scope:key:prepend:`` @@ -201,6 +202,14 @@ e.g.: =20 would hide 'security.' xattr's in listxattr from the server. =20 +A simpler 'map' type provides a shorter syntax for the common case: + +``:map:key:prepend:`` + +The 'map' type adds a number of separate rules to add **prepend** as a pre= fix +to the matched **key** (or all attributes if **key** is empty). +There may be at most one 'map' rule and it must be the last rule in the se= t. + xattr-mapping Examples ---------------------- =20 @@ -216,6 +225,11 @@ the first rule prefixes and strips 'user.virtiofs.', the second rule hides any non-prefixed attributes that the host set. =20 +This is equivalent to the 'map' rule: + +:: +-o xattrmap=3D":map::user.virtiofs.:" + 2) Prefix 'trusted.' attributes, allow others through =20 :: @@ -238,6 +252,11 @@ the 'user.viritofs.' path directly. Finally, the fourth rule lets all remaining attributes through. =20 +This is equivalent to the 'map' rule: + +:: +-o xattrmap=3D"/map/trusted./user.virtiofs./" + 3) Hide 'security.' attributes, and allow everything else =20 :: diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough= _ll.c index 57f584ee49..9f1ad9698d 100644 --- a/tools/virtiofsd/passthrough_ll.c +++ b/tools/virtiofsd/passthrough_ll.c @@ -2078,6 +2078,109 @@ static void free_xattrmap(struct lo_data *lo) lo->xattr_map_nentries =3D -1; } =20 +/* + * Handle the 'map' type, which is sugar for a set of commands + * for the common case of prefixing a subset or everything, + * and allowing anything not prefixed through. + * It must be the last entry in the stream, although there + * can be other entries before it. + * The form is: + * :map:key:prefix: + * + * key maybe empty in which case all entries are prefixed. + */ +static void parse_xattrmap_map(struct lo_data *lo, + const char *rule, char sep) +{ + const char *tmp; + char *key; + char *prefix; + XattrMapEntry tmp_entry; + + if (*rule !=3D sep) { + fuse_log(FUSE_LOG_ERR, + "%s: Expecting '%c' after 'map' keyword, found '%c'\n", + __func__, sep, *rule); + exit(1); + } + + rule++; + + /* At start of 'key' field */ + tmp =3D strchr(rule, sep); + if (!tmp) { + fuse_log(FUSE_LOG_ERR, + "%s: Missing '%c' at end of key field in map rule\n", + __func__, sep); + exit(1); + } + + key =3D g_strndup(rule, tmp - rule); + rule =3D tmp + 1; + + /* At start of prefix field */ + tmp =3D strchr(rule, sep); + if (!tmp) { + fuse_log(FUSE_LOG_ERR, + "%s: Missing '%c' at end of prefix field in map rule\n", + __func__, sep); + exit(1); + } + + prefix =3D g_strndup(rule, tmp - rule); + rule =3D tmp + 1; + + /* + * This should be the end of the string, we don't allow + * any more commands after 'map'. + */ + if (*rule) { + fuse_log(FUSE_LOG_ERR, + "%s: Expecting end of command after map, found '%c'\n", + __func__, *rule); + exit(1); + } + + /* 1st: Prefix matches/everything */ + tmp_entry.flags =3D XATTR_MAP_FLAG_PREFIX | XATTR_MAP_FLAG_ALL; + tmp_entry.key =3D g_strdup(key); + tmp_entry.prepend =3D g_strdup(prefix); + add_xattrmap_entry(lo, &tmp_entry); + + if (!*key) { + /* Prefix all case */ + + /* 2nd: Hide any non-prefixed entries on the host */ + tmp_entry.flags =3D XATTR_MAP_FLAG_BAD | XATTR_MAP_FLAG_ALL; + tmp_entry.key =3D g_strdup(""); + tmp_entry.prepend =3D g_strdup(""); + add_xattrmap_entry(lo, &tmp_entry); + } else { + /* Prefix matching case */ + + /* 2nd: Hide non-prefixed but matching entries on the host */ + tmp_entry.flags =3D XATTR_MAP_FLAG_BAD | XATTR_MAP_FLAG_SERVER; + tmp_entry.key =3D g_strdup(""); /* Not used */ + tmp_entry.prepend =3D g_strdup(key); + add_xattrmap_entry(lo, &tmp_entry); + + /* 3rd: Stop the client accessing prefixed attributes directly */ + tmp_entry.flags =3D XATTR_MAP_FLAG_BAD | XATTR_MAP_FLAG_CLIENT; + tmp_entry.key =3D g_strdup(prefix); + tmp_entry.prepend =3D g_strdup(""); /* Not used */ + add_xattrmap_entry(lo, &tmp_entry); + + /* 4th: Everything else is OK */ + tmp_entry.flags =3D XATTR_MAP_FLAG_OK | XATTR_MAP_FLAG_ALL; + tmp_entry.key =3D g_strdup(""); + tmp_entry.prepend =3D g_strdup(""); + add_xattrmap_entry(lo, &tmp_entry); + } + + g_free(key); + g_free(prefix); +} + static void parse_xattrmap(struct lo_data *lo) { const char *map =3D lo->xattrmap; @@ -2106,10 +2209,17 @@ static void parse_xattrmap(struct lo_data *lo) tmp_entry.flags |=3D XATTR_MAP_FLAG_OK; } else if (strstart(map, "bad", &map)) { tmp_entry.flags |=3D XATTR_MAP_FLAG_BAD; + } else if (strstart(map, "map", &map)) { + /* + * map is sugar that adds a number of rules, and must be + * the last entry. + */ + parse_xattrmap_map(lo, map, sep); + return; } else { fuse_log(FUSE_LOG_ERR, "%s: Unexpected type;" - "Expecting 'prefix', 'ok', or 'bad' in rule %zu\n", + "Expecting 'prefix', 'ok', 'bad' or 'map' in rule %zu= \n", __func__, lo->xattr_map_nentries); exit(1); } --=20 2.28.0