From nobody Sat May 18 16:18:08 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=1612466346; cv=none; d=zohomail.com; s=zohoarc; b=Y8d9POmEno98b/r11Kmb+p968gSbcXnqDE/29S6o7HD2Uv1M8PY9Vjc9/5UY7guD5aSkNfxX9j4ZcDrmC6V+iif/d22QxwytALDXe5mkRLALyvQVqxJiAk7zJ9heF2hEi0TGCO4RUK6FkXm2awPt5xg5ZI4xC/hyiaRvdO5mbc4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612466346; 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=34bn4iYROhYf74704WZ1pi7p7y8NX/XWdva2PxfrYeo=; b=X/Wnoy/Qy/fS9Y8kbmED3tfrnpkgQtdxwn+6p9IpkusgFWArevtOKMbly8c3DRlWJX6SkhblNg1tNCWJkEEoHH1d5rizqw+ywYUTMKQVBeLxQTEUlYN52IvaDae5BGuxLCGuzu/NJ5ecD60pq7OPQkDMPw4ZWC8LY9YuYQag/gI= 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 1612466346334761.0891223143415; Thu, 4 Feb 2021 11:19:06 -0800 (PST) Received: from localhost ([::1]:51006 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l7k9h-0002qH-Ac for importer@patchew.org; Thu, 04 Feb 2021 14:19:05 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39696) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l7jTb-0002UD-T1 for qemu-devel@nongnu.org; Thu, 04 Feb 2021 13:35:40 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:46228) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l7jTO-0004T9-C1 for qemu-devel@nongnu.org; Thu, 04 Feb 2021 13:35:34 -0500 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-510-5e8DL4jWPHW_SArQ2uFebw-1; Thu, 04 Feb 2021 13:35:16 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 42A5B8799EC; Thu, 4 Feb 2021 18:35:15 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-114-21.ams2.redhat.com [10.36.114.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1581870483; Thu, 4 Feb 2021 18:35:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612463720; 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=34bn4iYROhYf74704WZ1pi7p7y8NX/XWdva2PxfrYeo=; b=hjkL5IjuhPfum8Dm2Z+85+Cpv10+SqPab00rQv9iqyWrwyMv74526oJplOS50Aum7rUmqh gfb/WEd8wFgIc/JhZiW6aHPnEHMcz4s5ZKqNlsbqQmjexPvEkhXQgeL237l3wEaI7zg3ky k+PjZknMXm47jVc+b0U2T9GBsO+ZU30= X-MC-Unique: 5e8DL4jWPHW_SArQ2uFebw-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, virtio-fs@redhat.com, stefanha@redhat.com, groug@kaod.org, qemu-stable@nongnu.org Subject: [PULL 1/5] virtiofsd: extract lo_do_open() from lo_open() Date: Thu, 4 Feb 2021 18:34:35 +0000 Message-Id: <20210204183439.546918-2-dgilbert@redhat.com> In-Reply-To: <20210204183439.546918-1-dgilbert@redhat.com> References: <20210204183439.546918-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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=63.128.21.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.351, 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=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: , 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: Stefan Hajnoczi Both lo_open() and lo_create() have similar code to open a file. Extract a common lo_do_open() function from lo_open() that will be used by lo_create() in a later commit. Since lo_do_open() does not otherwise need fuse_req_t req, convert lo_add_fd_mapping() to use struct lo_data *lo instead. Signed-off-by: Stefan Hajnoczi Message-Id: <20210204150208.367837-2-stefanha@redhat.com> Reviewed-by: Greg Kurz Signed-off-by: Dr. David Alan Gilbert --- tools/virtiofsd/passthrough_ll.c | 73 ++++++++++++++++++++------------ 1 file changed, 46 insertions(+), 27 deletions(-) diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough= _ll.c index 5fb36d9407..f14fa5124d 100644 --- a/tools/virtiofsd/passthrough_ll.c +++ b/tools/virtiofsd/passthrough_ll.c @@ -459,17 +459,17 @@ static void lo_map_remove(struct lo_map *map, size_t = key) } =20 /* Assumes lo->mutex is held */ -static ssize_t lo_add_fd_mapping(fuse_req_t req, int fd) +static ssize_t lo_add_fd_mapping(struct lo_data *lo, int fd) { struct lo_map_elem *elem; =20 - elem =3D lo_map_alloc_elem(&lo_data(req)->fd_map); + elem =3D lo_map_alloc_elem(&lo->fd_map); if (!elem) { return -1; } =20 elem->fd =3D fd; - return elem - lo_data(req)->fd_map.elems; + return elem - lo->fd_map.elems; } =20 /* Assumes lo->mutex is held */ @@ -1651,6 +1651,38 @@ static void update_open_flags(int writeback, int all= ow_direct_io, } } =20 +static int lo_do_open(struct lo_data *lo, struct lo_inode *inode, + struct fuse_file_info *fi) +{ + char buf[64]; + ssize_t fh; + int fd; + + update_open_flags(lo->writeback, lo->allow_direct_io, fi); + + sprintf(buf, "%i", inode->fd); + fd =3D openat(lo->proc_self_fd, buf, fi->flags & ~O_NOFOLLOW); + if (fd =3D=3D -1) { + return errno; + } + + pthread_mutex_lock(&lo->mutex); + fh =3D lo_add_fd_mapping(lo, fd); + pthread_mutex_unlock(&lo->mutex); + if (fh =3D=3D -1) { + close(fd); + return ENOMEM; + } + + fi->fh =3D fh; + if (lo->cache =3D=3D CACHE_NONE) { + fi->direct_io =3D 1; + } else if (lo->cache =3D=3D CACHE_ALWAYS) { + fi->keep_cache =3D 1; + } + return 0; +} + static void lo_create(fuse_req_t req, fuse_ino_t parent, const char *name, mode_t mode, struct fuse_file_info *fi) { @@ -1691,7 +1723,7 @@ static void lo_create(fuse_req_t req, fuse_ino_t pare= nt, const char *name, ssize_t fh; =20 pthread_mutex_lock(&lo->mutex); - fh =3D lo_add_fd_mapping(req, fd); + fh =3D lo_add_fd_mapping(lo, fd); pthread_mutex_unlock(&lo->mutex); if (fh =3D=3D -1) { close(fd); @@ -1892,38 +1924,25 @@ static void lo_fsyncdir(fuse_req_t req, fuse_ino_t = ino, int datasync, =20 static void lo_open(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info = *fi) { - int fd; - ssize_t fh; - char buf[64]; struct lo_data *lo =3D lo_data(req); + struct lo_inode *inode =3D lo_inode(req, ino); + int err; =20 fuse_log(FUSE_LOG_DEBUG, "lo_open(ino=3D%" PRIu64 ", flags=3D%d)\n", i= no, fi->flags); =20 - update_open_flags(lo->writeback, lo->allow_direct_io, fi); - - sprintf(buf, "%i", lo_fd(req, ino)); - fd =3D openat(lo->proc_self_fd, buf, fi->flags & ~O_NOFOLLOW); - if (fd =3D=3D -1) { - return (void)fuse_reply_err(req, errno); - } - - pthread_mutex_lock(&lo->mutex); - fh =3D lo_add_fd_mapping(req, fd); - pthread_mutex_unlock(&lo->mutex); - if (fh =3D=3D -1) { - close(fd); - fuse_reply_err(req, ENOMEM); + if (!inode) { + fuse_reply_err(req, EBADF); return; } =20 - fi->fh =3D fh; - if (lo->cache =3D=3D CACHE_NONE) { - fi->direct_io =3D 1; - } else if (lo->cache =3D=3D CACHE_ALWAYS) { - fi->keep_cache =3D 1; + err =3D lo_do_open(lo, inode, fi); + lo_inode_put(lo, &inode); + if (err) { + fuse_reply_err(req, err); + } else { + fuse_reply_open(req, fi); } - fuse_reply_open(req, fi); } =20 static void lo_release(fuse_req_t req, fuse_ino_t ino, --=20 2.29.2 From nobody Sat May 18 16:18:08 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=1612465901; cv=none; d=zohomail.com; s=zohoarc; b=lQaKCK7fRdXpmqiuUdL5jzEIE5cfNu21mCZFHDN1m8aGFz7zLPKdsBuFXBax5g9kxPJqPniwhGrJA5jlAiCFxTIsMqPsZ7XvO+onJsUUI7VGeBkk53COdmb7xnuTd3yDaalTJoqgZL6Ths0OWBwUvUKWe3c8Z9k64Dx8aay/aFs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612465901; 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=iyZSoVD/PK1v2AgTUerEGLiNIWbX3CD0IF78yPdqESg=; b=UP1lpAweOobV8qByZE3tkfCtwfsl0y2IDWjq9l7/jrJiTdr+aD4LNkfbTiUXWlAmCu3XG1yyacwlC3KrAOJkW8R623+S+MODI588brVfbwuU1nkKqK5oq3jXOUvzcepQm6B/K+mToj6iBwJ+uVixRS6iYzq5Y340i7aAJ9R+7hk= 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 161246590128490.30906434602025; Thu, 4 Feb 2021 11:11:41 -0800 (PST) Received: from localhost ([::1]:37604 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l7k2U-0005Et-W0 for importer@patchew.org; Thu, 04 Feb 2021 14:11:39 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39770) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l7jTm-0002br-G3 for qemu-devel@nongnu.org; Thu, 04 Feb 2021 13:35:46 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:47736) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l7jTZ-0004Vi-Bx for qemu-devel@nongnu.org; Thu, 04 Feb 2021 13:35:46 -0500 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-567-FNaItIcrPuKQF9WWIv7x4Q-1; Thu, 04 Feb 2021 13:35:25 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A58A68799E0; Thu, 4 Feb 2021 18:35:24 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-114-21.ams2.redhat.com [10.36.114.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8D49E5B4B5; Thu, 4 Feb 2021 18:35:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612463729; 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=iyZSoVD/PK1v2AgTUerEGLiNIWbX3CD0IF78yPdqESg=; b=ZOiHEuCx93PBswgWc928ct0D1vS7e+FlVoo9aM0tB+nbpvnHRw/ubZGNLPRy1Po9SZxdf8 76iv/Gk61bEzyHGgP3j4Q1I6y02nVwhZJNfih48k7cmbS4UcNeaj2Vrf3Cdej1sqqXqoIK K3WOBI8w92hJ/JMDEo/FYJh/gCQYcQE= X-MC-Unique: FNaItIcrPuKQF9WWIv7x4Q-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, virtio-fs@redhat.com, stefanha@redhat.com, groug@kaod.org, qemu-stable@nongnu.org Subject: [PULL 2/5] virtiofsd: optionally return inode pointer from lo_do_lookup() Date: Thu, 4 Feb 2021 18:34:36 +0000 Message-Id: <20210204183439.546918-3-dgilbert@redhat.com> In-Reply-To: <20210204183439.546918-1-dgilbert@redhat.com> References: <20210204183439.546918-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.351, 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_H3=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: Stefan Hajnoczi lo_do_lookup() finds an existing inode or allocates a new one. It increments nlookup so that the inode stays alive until the client releases it. Existing callers don't need the struct lo_inode so the function doesn't return it. Extend the function to optionally return the inode. The next commit will need it. Signed-off-by: Stefan Hajnoczi Reviewed-by: Greg Kurz Message-Id: <20210204150208.367837-3-stefanha@redhat.com> Signed-off-by: Dr. David Alan Gilbert --- tools/virtiofsd/passthrough_ll.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough= _ll.c index f14fa5124d..aa35fc6ba5 100644 --- a/tools/virtiofsd/passthrough_ll.c +++ b/tools/virtiofsd/passthrough_ll.c @@ -831,11 +831,13 @@ static int do_statx(struct lo_data *lo, int dirfd, co= nst char *pathname, } =20 /* - * Increments nlookup and caller must release refcount using - * lo_inode_put(&parent). + * Increments nlookup on the inode on success. unref_inode_lolocked() must= be + * called eventually to decrement nlookup again. If inodep is non-NULL, the + * inode pointer is stored and the caller must call lo_inode_put(). */ static int lo_do_lookup(fuse_req_t req, fuse_ino_t parent, const char *nam= e, - struct fuse_entry_param *e) + struct fuse_entry_param *e, + struct lo_inode **inodep) { int newfd; int res; @@ -845,6 +847,10 @@ static int lo_do_lookup(fuse_req_t req, fuse_ino_t par= ent, const char *name, struct lo_inode *inode =3D NULL; struct lo_inode *dir =3D lo_inode(req, parent); =20 + if (inodep) { + *inodep =3D NULL; + } + /* * name_to_handle_at() and open_by_handle_at() can reach here with fuse * mount point in guest, but we don't have its inode info in the @@ -913,7 +919,14 @@ static int lo_do_lookup(fuse_req_t req, fuse_ino_t par= ent, const char *name, pthread_mutex_unlock(&lo->mutex); } e->ino =3D inode->fuse_ino; - lo_inode_put(lo, &inode); + + /* Transfer ownership of inode pointer to caller or drop it */ + if (inodep) { + *inodep =3D inode; + } else { + lo_inode_put(lo, &inode); + } + lo_inode_put(lo, &dir); =20 fuse_log(FUSE_LOG_DEBUG, " %lli/%s -> %lli\n", (unsigned long long)pa= rent, @@ -948,7 +961,7 @@ static void lo_lookup(fuse_req_t req, fuse_ino_t parent= , const char *name) return; } =20 - err =3D lo_do_lookup(req, parent, name, &e); + err =3D lo_do_lookup(req, parent, name, &e, NULL); if (err) { fuse_reply_err(req, err); } else { @@ -1056,7 +1069,7 @@ static void lo_mknod_symlink(fuse_req_t req, fuse_ino= _t parent, goto out; } =20 - saverr =3D lo_do_lookup(req, parent, name, &e); + saverr =3D lo_do_lookup(req, parent, name, &e, NULL); if (saverr) { goto out; } @@ -1534,7 +1547,7 @@ static void lo_do_readdir(fuse_req_t req, fuse_ino_t = ino, size_t size, =20 if (plus) { if (!is_dot_or_dotdot(name)) { - err =3D lo_do_lookup(req, ino, name, &e); + err =3D lo_do_lookup(req, ino, name, &e, NULL); if (err) { goto error; } @@ -1732,7 +1745,7 @@ static void lo_create(fuse_req_t req, fuse_ino_t pare= nt, const char *name, } =20 fi->fh =3D fh; - err =3D lo_do_lookup(req, parent, name, &e); + err =3D lo_do_lookup(req, parent, name, &e, NULL); } if (lo->cache =3D=3D CACHE_NONE) { fi->direct_io =3D 1; --=20 2.29.2 From nobody Sat May 18 16:18:08 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=1612466060; cv=none; d=zohomail.com; s=zohoarc; b=e4ZH8z/K+YCgk6sZuTU0uIrNOVu+eWrBd+TCsKaVYbZfrWRml5ed8lHJT/twEoYJn7OpYTRkm1ixr5Yh++WTR0Ce35s5ZMTH5mPRgA9BTiYtCAGrV+Jf8bao0Mt07u3jWcR62H2d1+RR6GgTwzTrc2sO38aGSDTpTApFxXZUuA8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612466060; 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=4xyWBz8hsV6CyasCJf2n7ihL/CITpCMqcKrKncUSwAA=; b=FVq1yl5Ic+9bJ1ypcTPW2D4HJL2zPp5FK/kGzfcGty6o1Yn0WnovpSC34KsrxyGBh9c5EWCpnz5+fZKgxjRB8PP/jt7sWCUtgyY4DiCARTagNo11i5J44m2j5F6+pWrGfyX4ctm225TM593pUXYF9efzw3TIH8g5hWdcsGb9uSU= 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 1612466060627937.2492604272059; Thu, 4 Feb 2021 11:14:20 -0800 (PST) Received: from localhost ([::1]:43266 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l7k55-0007sn-FN for importer@patchew.org; Thu, 04 Feb 2021 14:14:19 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39824) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l7jTo-0002gC-8q for qemu-devel@nongnu.org; Thu, 04 Feb 2021 13:35:48 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:22878) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l7jTk-0004bA-LA for qemu-devel@nongnu.org; Thu, 04 Feb 2021 13:35:47 -0500 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-104-bsc1v3leO_edffnYKDVoWg-1; Thu, 04 Feb 2021 13:35:39 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 99BE5189DF4E; Thu, 4 Feb 2021 18:35:38 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-114-21.ams2.redhat.com [10.36.114.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id AE3C5722D9; Thu, 4 Feb 2021 18:35:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612463742; 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=4xyWBz8hsV6CyasCJf2n7ihL/CITpCMqcKrKncUSwAA=; b=T3jNDWklIkk4zUczoFuqnn4fChLOX4qWrPyFVOp7wWLspecOl2K4jJDBbeXYEdIJxPSHqX 9589H48Lt/2w2RQXH5R73w+5x0uztl/bfktT5hy7RkbF4y/f6ufJrYRBBy6M14Yk7DImmT ZqHmzVPmvQm3kKEBQODZ4d53yV1mdJU= X-MC-Unique: bsc1v3leO_edffnYKDVoWg-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, virtio-fs@redhat.com, stefanha@redhat.com, groug@kaod.org, qemu-stable@nongnu.org Subject: [PULL 3/5] virtiofsd: prevent opening of special files (CVE-2020-35517) Date: Thu, 4 Feb 2021 18:34:37 +0000 Message-Id: <20210204183439.546918-4-dgilbert@redhat.com> In-Reply-To: <20210204183439.546918-1-dgilbert@redhat.com> References: <20210204183439.546918-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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=63.128.21.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.351, 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=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: , 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: Stefan Hajnoczi A well-behaved FUSE client does not attempt to open special files with FUSE_OPEN because they are handled on the client side (e.g. device nodes are handled by client-side device drivers). The check to prevent virtiofsd from opening special files is missing in a few cases, most notably FUSE_OPEN. A malicious client can cause virtiofsd to open a device node, potentially allowing the guest to escape. This can be exploited by a modified guest device driver. It is not exploitable from guest userspace since the guest kernel will handle special files inside the guest instead of sending FUSE requests. This patch fixes this issue by introducing the lo_inode_open() function to check the file type before opening it. This is a short-term solution because it does not prevent a compromised virtiofsd process from opening device nodes on the host. Restructure lo_create() to try O_CREAT | O_EXCL first. Note that O_CREAT | O_EXCL does not follow symlinks, so O_NOFOLLOW masking is not necessary here. If the file exists and the user did not specify O_EXCL, open it via lo_do_open(). Reported-by: Alex Xu Fixes: CVE-2020-35517 Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Vivek Goyal Reviewed-by: Greg Kurz Signed-off-by: Stefan Hajnoczi Message-Id: <20210204150208.367837-4-stefanha@redhat.com> Signed-off-by: Dr. David Alan Gilbert --- tools/virtiofsd/passthrough_ll.c | 144 ++++++++++++++++++++----------- 1 file changed, 92 insertions(+), 52 deletions(-) diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough= _ll.c index aa35fc6ba5..147b59338a 100644 --- a/tools/virtiofsd/passthrough_ll.c +++ b/tools/virtiofsd/passthrough_ll.c @@ -555,6 +555,38 @@ static int lo_fd(fuse_req_t req, fuse_ino_t ino) return fd; } =20 +/* + * Open a file descriptor for an inode. Returns -EBADF if the inode is not= a + * regular file or a directory. + * + * Use this helper function instead of raw openat(2) to prevent security i= ssues + * when a malicious client opens special files such as block device nodes. + * Symlink inodes are also rejected since symlinks must already have been + * traversed on the client side. + */ +static int lo_inode_open(struct lo_data *lo, struct lo_inode *inode, + int open_flags) +{ + g_autofree char *fd_str =3D g_strdup_printf("%d", inode->fd); + int fd; + + if (!S_ISREG(inode->filetype) && !S_ISDIR(inode->filetype)) { + return -EBADF; + } + + /* + * The file is a symlink so O_NOFOLLOW must be ignored. We checked ear= lier + * that the inode is not a special file but if an external process rac= es + * with us then symlinks are traversed here. It is not possible to esc= ape + * the shared directory since it is mounted as "/" though. + */ + fd =3D openat(lo->proc_self_fd, fd_str, open_flags & ~O_NOFOLLOW); + if (fd < 0) { + return -errno; + } + return fd; +} + static void lo_init(void *userdata, struct fuse_conn_info *conn) { struct lo_data *lo =3D (struct lo_data *)userdata; @@ -684,9 +716,9 @@ static void lo_setattr(fuse_req_t req, fuse_ino_t ino, = struct stat *attr, if (fi) { truncfd =3D fd; } else { - sprintf(procname, "%i", ifd); - truncfd =3D openat(lo->proc_self_fd, procname, O_RDWR); + truncfd =3D lo_inode_open(lo, inode, O_RDWR); if (truncfd < 0) { + errno =3D -truncfd; goto out_err; } } @@ -848,7 +880,7 @@ static int lo_do_lookup(fuse_req_t req, fuse_ino_t pare= nt, const char *name, struct lo_inode *dir =3D lo_inode(req, parent); =20 if (inodep) { - *inodep =3D NULL; + *inodep =3D NULL; /* in case there is an error */ } =20 /* @@ -1664,19 +1696,26 @@ static void update_open_flags(int writeback, int al= low_direct_io, } } =20 +/* + * Open a regular file, set up an fd mapping, and fill out the struct + * fuse_file_info for it. If existing_fd is not negative, use that fd inst= ead + * opening a new one. Takes ownership of existing_fd. + * + * Returns 0 on success or a positive errno. + */ static int lo_do_open(struct lo_data *lo, struct lo_inode *inode, - struct fuse_file_info *fi) + int existing_fd, struct fuse_file_info *fi) { - char buf[64]; ssize_t fh; - int fd; + int fd =3D existing_fd; =20 update_open_flags(lo->writeback, lo->allow_direct_io, fi); =20 - sprintf(buf, "%i", inode->fd); - fd =3D openat(lo->proc_self_fd, buf, fi->flags & ~O_NOFOLLOW); - if (fd =3D=3D -1) { - return errno; + if (fd < 0) { + fd =3D lo_inode_open(lo, inode, fi->flags); + if (fd < 0) { + return -fd; + } } =20 pthread_mutex_lock(&lo->mutex); @@ -1699,9 +1738,10 @@ static int lo_do_open(struct lo_data *lo, struct lo_= inode *inode, static void lo_create(fuse_req_t req, fuse_ino_t parent, const char *name, mode_t mode, struct fuse_file_info *fi) { - int fd; + int fd =3D -1; struct lo_data *lo =3D lo_data(req); struct lo_inode *parent_inode; + struct lo_inode *inode =3D NULL; struct fuse_entry_param e; int err; struct lo_cred old =3D {}; @@ -1727,36 +1767,38 @@ static void lo_create(fuse_req_t req, fuse_ino_t pa= rent, const char *name, =20 update_open_flags(lo->writeback, lo->allow_direct_io, fi); =20 - fd =3D openat(parent_inode->fd, name, (fi->flags | O_CREAT) & ~O_NOFOL= LOW, - mode); + /* Try to create a new file but don't open existing files */ + fd =3D openat(parent_inode->fd, name, fi->flags | O_CREAT | O_EXCL, mo= de); err =3D fd =3D=3D -1 ? errno : 0; - lo_restore_cred(&old); =20 - if (!err) { - ssize_t fh; + lo_restore_cred(&old); =20 - pthread_mutex_lock(&lo->mutex); - fh =3D lo_add_fd_mapping(lo, fd); - pthread_mutex_unlock(&lo->mutex); - if (fh =3D=3D -1) { - close(fd); - err =3D ENOMEM; - goto out; - } + /* Ignore the error if file exists and O_EXCL was not given */ + if (err && (err !=3D EEXIST || (fi->flags & O_EXCL))) { + goto out; + } =20 - fi->fh =3D fh; - err =3D lo_do_lookup(req, parent, name, &e, NULL); + err =3D lo_do_lookup(req, parent, name, &e, &inode); + if (err) { + goto out; } - if (lo->cache =3D=3D CACHE_NONE) { - fi->direct_io =3D 1; - } else if (lo->cache =3D=3D CACHE_ALWAYS) { - fi->keep_cache =3D 1; + + err =3D lo_do_open(lo, inode, fd, fi); + fd =3D -1; /* lo_do_open() takes ownership of fd */ + if (err) { + /* Undo lo_do_lookup() nlookup ref */ + unref_inode_lolocked(lo, inode, 1); } =20 out: + lo_inode_put(lo, &inode); lo_inode_put(lo, &parent_inode); =20 if (err) { + if (fd >=3D 0) { + close(fd); + } + fuse_reply_err(req, err); } else { fuse_reply_create(req, &e, fi); @@ -1770,7 +1812,6 @@ static struct lo_inode_plock *lookup_create_plock_ctx= (struct lo_data *lo, pid_t pid, int *err) { struct lo_inode_plock *plock; - char procname[64]; int fd; =20 plock =3D @@ -1787,12 +1828,10 @@ static struct lo_inode_plock *lookup_create_plock_c= tx(struct lo_data *lo, } =20 /* Open another instance of file which can be used for ofd locks. */ - sprintf(procname, "%i", inode->fd); - /* TODO: What if file is not writable? */ - fd =3D openat(lo->proc_self_fd, procname, O_RDWR); - if (fd =3D=3D -1) { - *err =3D errno; + fd =3D lo_inode_open(lo, inode, O_RDWR); + if (fd < 0) { + *err =3D -fd; free(plock); return NULL; } @@ -1949,7 +1988,7 @@ static void lo_open(fuse_req_t req, fuse_ino_t ino, s= truct fuse_file_info *fi) return; } =20 - err =3D lo_do_open(lo, inode, fi); + err =3D lo_do_open(lo, inode, -1, fi); lo_inode_put(lo, &inode); if (err) { fuse_reply_err(req, err); @@ -2014,39 +2053,40 @@ static void lo_flush(fuse_req_t req, fuse_ino_t ino= , struct fuse_file_info *fi) static void lo_fsync(fuse_req_t req, fuse_ino_t ino, int datasync, struct fuse_file_info *fi) { + struct lo_inode *inode =3D lo_inode(req, ino); + struct lo_data *lo =3D lo_data(req); int res; int fd; - char *buf; =20 fuse_log(FUSE_LOG_DEBUG, "lo_fsync(ino=3D%" PRIu64 ", fi=3D0x%p)\n", i= no, (void *)fi); =20 - if (!fi) { - struct lo_data *lo =3D lo_data(req); - - res =3D asprintf(&buf, "%i", lo_fd(req, ino)); - if (res =3D=3D -1) { - return (void)fuse_reply_err(req, errno); - } + if (!inode) { + fuse_reply_err(req, EBADF); + return; + } =20 - fd =3D openat(lo->proc_self_fd, buf, O_RDWR); - free(buf); - if (fd =3D=3D -1) { - return (void)fuse_reply_err(req, errno); + if (!fi) { + fd =3D lo_inode_open(lo, inode, O_RDWR); + if (fd < 0) { + res =3D -fd; + goto out; } } else { fd =3D lo_fi_fd(req, fi); } =20 if (datasync) { - res =3D fdatasync(fd); + res =3D fdatasync(fd) =3D=3D -1 ? errno : 0; } else { - res =3D fsync(fd); + res =3D fsync(fd) =3D=3D -1 ? errno : 0; } if (!fi) { close(fd); } - fuse_reply_err(req, res =3D=3D -1 ? errno : 0); +out: + lo_inode_put(lo, &inode); + fuse_reply_err(req, res); } =20 static void lo_read(fuse_req_t req, fuse_ino_t ino, size_t size, off_t off= set, --=20 2.29.2 From nobody Sat May 18 16:18:08 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=1612466257; cv=none; d=zohomail.com; s=zohoarc; b=mRqefWHvMUcU5iI68c6Pxaw8ddjJHJoiju/UK9lRdD2Py6E9VzizEdPPl6kCBF/mbpbjHfNs9ItH43Q8n4gMuQ8+aA2C46RMYuYeI+7/ddXwQWnVdNIwUu8pz4dc5OCegVwhA2Av3K2I+Yb1Cb4aOUeC2Un11i+ZmN3dVQKZD30= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612466257; 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=77H8hOIoiJ389rWLt7+xbfiQuN7xnc/7ziqEvp6RP1w=; b=NUn04o26yntGEVnccElLvD0DlTLXMo6qeBiECR8rTCoB/rPm3xeWFR1/8ihjiJb9EgQk7djEhfhYFD48e341xwo6mexPi/CZhQxqMIXiFnSF1ZwZW1firYmeVnLPq/zRDTg70HQ8SV8oVEFGVWDW+vVVTHcFK+OeaMsXbhBTqh4= 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 1612466257854724.434400838713; Thu, 4 Feb 2021 11:17:37 -0800 (PST) Received: from localhost ([::1]:48296 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l7k8G-0001bY-MM for importer@patchew.org; Thu, 04 Feb 2021 14:17:36 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39808) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l7jTn-0002eT-Iy for qemu-devel@nongnu.org; Thu, 04 Feb 2021 13:35:47 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:35592) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l7jTk-0004bF-Kh for qemu-devel@nongnu.org; Thu, 04 Feb 2021 13:35:47 -0500 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-167-urdllxUBN5-L6VO2kP_XDg-1; Thu, 04 Feb 2021 13:35:41 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1CB8015722; Thu, 4 Feb 2021 18:35:40 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-114-21.ams2.redhat.com [10.36.114.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id E476B4D; Thu, 4 Feb 2021 18:35:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612463743; 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=77H8hOIoiJ389rWLt7+xbfiQuN7xnc/7ziqEvp6RP1w=; b=WR3cH2z1QGrzRGN2BvIF9HZDjouuhbGgV7lQQn57izfP5ejCD4WIuuj1unaN4EgHS0OHNq ioWgIZuX+/MNK0+WeKTQqJVLZhAqln9ST/BBBGzMtrWwNfg6aRiGgM4AYYrz5glZELsm9z AAQP+lrF0QwQPqo13DMA5d7+qZmFVVo= X-MC-Unique: urdllxUBN5-L6VO2kP_XDg-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, virtio-fs@redhat.com, stefanha@redhat.com, groug@kaod.org, qemu-stable@nongnu.org Subject: [PULL 4/5] virtiofsd: Add _llseek to the seccomp whitelist Date: Thu, 4 Feb 2021 18:34:38 +0000 Message-Id: <20210204183439.546918-5-dgilbert@redhat.com> In-Reply-To: <20210204183439.546918-1-dgilbert@redhat.com> References: <20210204183439.546918-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.351, 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_H3=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: Greg Kurz This is how glibc implements lseek(2) on POWER. BugLink: https://bugzilla.redhat.com/show_bug.cgi?id=3D1917692 Signed-off-by: Greg Kurz Message-Id: <20210121171540.1449777-1-groug@kaod.org> Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Dr. David Alan Gilbert --- 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 a60d7da4b4..1ecf5bf318 100644 --- a/tools/virtiofsd/passthrough_seccomp.c +++ b/tools/virtiofsd/passthrough_seccomp.c @@ -65,6 +65,7 @@ static const int syscall_whitelist[] =3D { SCMP_SYS(linkat), SCMP_SYS(listxattr), SCMP_SYS(lseek), + SCMP_SYS(_llseek), /* For POWER */ SCMP_SYS(madvise), SCMP_SYS(mkdirat), SCMP_SYS(mknodat), --=20 2.29.2 From nobody Sat May 18 16:18:08 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=1612466445; cv=none; d=zohomail.com; s=zohoarc; b=QEJMyt68RoQMCkOdAC4Ee1+XT21a+yslbbddgyw68xqK7vAk+g0mCSCaXYUSzMCglDM/XgZEBfJ2FoVa/bP//L5u/U2kFpMNWHUZRNPRNFm3eaDo9YBJbFR2EqO52b3qu+jiyEc976EJhmzcWBtXm0A5lu6GoIRHEpWy5FlOjFM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612466445; 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=2eURxzPZfAOYhVaseFeS8aD/J7t65JxsxrfDsA5hqfc=; b=RUkelmS0ccTg08gFKGlZChSC3mmpJ+Hti7lfFw63pSMiW6Qs60joQGfDM7nmHTfNps650srS4FxZ+y4eHDAco9TjNTH5JZ25zcDyQuldELepQeMV3rX9OoB8uNbNptLDlnXS8BmdPP427kbuMB3MtaXVnPmu0JuCvgqiZaeNWqE= 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 1612466445069403.2870883828899; Thu, 4 Feb 2021 11:20:45 -0800 (PST) Received: from localhost ([::1]:56960 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l7kBI-0005L8-2Q for importer@patchew.org; Thu, 04 Feb 2021 14:20:44 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39860) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l7jTp-0002iK-1y for qemu-devel@nongnu.org; Thu, 04 Feb 2021 13:35:49 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:36144) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l7jTm-0004be-1V for qemu-devel@nongnu.org; Thu, 04 Feb 2021 13:35:48 -0500 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-182-dbNGDVrGPQWATEqj51qiUQ-1; Thu, 04 Feb 2021 13:35:42 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9D2138799F0; Thu, 4 Feb 2021 18:35:41 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-114-21.ams2.redhat.com [10.36.114.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6751F6A252; Thu, 4 Feb 2021 18:35:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612463745; 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=2eURxzPZfAOYhVaseFeS8aD/J7t65JxsxrfDsA5hqfc=; b=DXsW0Nh3A4in1yZ3EyK730P0ociT/hjTJ9JwVaiN/HSlQho6pfqzJsMus13FMLyMBw+3y1 MjXW/90VSeg5mTsRDdXvYeIya5WaGxI9lrA29naHmGZ2JjyKrNZFRUJL1v/hv1vfSQunVq 4ExWfZ3iinm+s3yskalQWZdgP2tDM6Q= X-MC-Unique: dbNGDVrGPQWATEqj51qiUQ-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, virtio-fs@redhat.com, stefanha@redhat.com, groug@kaod.org, qemu-stable@nongnu.org Subject: [PULL 5/5] virtiofsd: Add restart_syscall to the seccomp whitelist Date: Thu, 4 Feb 2021 18:34:39 +0000 Message-Id: <20210204183439.546918-6-dgilbert@redhat.com> In-Reply-To: <20210204183439.546918-1-dgilbert@redhat.com> References: <20210204183439.546918-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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=63.128.21.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.351, 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: , 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: Greg Kurz This is how linux restarts some system calls after SIGSTOP/SIGCONT. This is needed to avoid virtiofsd termination when resuming execution under GDB for example. Signed-off-by: Greg Kurz Message-Id: <20210201193305.136390-1-groug@kaod.org> Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Stefan Hajnoczi Signed-off-by: Dr. David Alan Gilbert --- 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 1ecf5bf318..ea852e2e33 100644 --- a/tools/virtiofsd/passthrough_seccomp.c +++ b/tools/virtiofsd/passthrough_seccomp.c @@ -89,6 +89,7 @@ static const int syscall_whitelist[] =3D { SCMP_SYS(renameat), SCMP_SYS(renameat2), SCMP_SYS(removexattr), + SCMP_SYS(restart_syscall), SCMP_SYS(rt_sigaction), SCMP_SYS(rt_sigprocmask), SCMP_SYS(rt_sigreturn), --=20 2.29.2