ovl: skip copy up of empty security.capability
PATCH 2/3 ovl: skip copy up of empty security.capability
commit 50912a1715b8a7c614b654011a0db750e372b43e upstream.
ovl_copy_xattr() gives up if it can't read an attribute that listxattr() has named. An empty security.capability, which anybody has been able to store on any file for a long time, is such a case: it is listed, and getxattr() has nothing to return for it. A file in a lower layer that carries one can't be copied up: it can't be written to, renamed or have its mode changed.
There is nothing to copy if there are no data. Go on with the next one.
[amir: treat -EINVAL as no capability too, and do the same in
ovl_copy_up_meta_inode_data()]
---
[ backport: context: no blank line before the ovl_getxattr_value() call;
depends on e6b9117076fb ("ovl: fortify ovl_copy_xattr() against underlying layer modifications") ]
fs/overlayfs/copy_up.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)
fs/overlayfs/copy_up.c +15 -2
@@ -47,6 +47,15 @@ static bool ovl_must_copy_xattr(const char *name)static ssize_t ovl_getxattr_value (const struct path *path,char *name,char **value,ssize_t *value_size); +/* +* Any user can store an empty security.capability, which fails to read with +* -EINVAL. It grants no capability, so treat it as none, like no xattr. +*/ +static bool ovl_no_fscap (ssize_t err) +{ +return err == -ENODATA || err == -EOPNOTSUPP || err == -EINVAL ; +} +int ovl_copy_xattr (struct super_block *sb,const struct path *oldpath,struct dentry *new) {struct dentry *old = oldpath->dentry;
@@ -98,6 +107,10 @@ int ovl_copy_xattr(struct super_block *sb, const struct path *oldpath, struct de } size =ovl_getxattr_value (oldpath, name, &value, &value_size);if (size <0 ) { +if (!strcmp (name,XATTR_NAME_CAPS ) &&ovl_no_fscap (size)) { + error =0 ; +continue ; + } error = size;break ; }
@@ -947,9 +960,9 @@ static int ovl_copy_up_meta_inode_data(struct ovl_copy_up_ctx *c)if (c->stat.size) { err = cap_size =ovl_getxattr_value (&upperpath,XATTR_NAME_CAPS , &capability, &cap_size); -if (cap_size == -ENODATA || cap_size == -EOPNOTSUPP ) +if (ovl_no_fscap (cap_size)) cap_size =0 ; -if (cap_size <0 ) +else if (cap_size <0 ) goto out; }
Signature · 1 line
backport
PATCH 3/3 ovl: set the revalidate flags after d_instantiate()
From: Chris Mason <[email protected]>
commit 75e89c0055c1d7f7eeb462995f11253ca5864f79 upstream.
stat() of a file on an overlayfs mount triggers a kernel warning and fails with ECHILD if another task is creating that file at the same time. This happens on an overlay with a FUSE upper layer, which is the layer where overlayfs creates new files. Write access to a directory on such an overlay is all a user needs to run the two tasks.
The revalidate flags are DCACHE_OP_REVALIDATE and DCACHE_OP_WEAK_REVALIDATE. They tell path walk to call ->d_revalidate() or ->d_weak_revalidate() on a dentry, so that the filesystem can check that the cached dentry is still valid. An overlay dentry only has one of these flags if a dentry in one of its layers has it. FUSE dentries have the first one.
When a flag is set on an overlay dentry, path walk calls ovl_dentry_revalidate_common(). That function only expects a dentry without an inode in RCU walk, while the dentry is being destroyed. For such a dentry outside of RCU walk, it hits a WARN_ON() and returns -ECHILD. So a negative overlay dentry must never have the flags set.
ovl_instantiate() breaks this rule. When a task creates a file, the overlay dentry for the new name is hashed but still negative. ovl_instantiate() then works in this order:
- It copies the flags from the new upper dentry to the overlay dentry.
- It calls ovl_get_inode(), which can sleep in a getxattr request to the FUSE server.
- Only then does it call d_instantiate().
A second task that looks up the name between the first step and the last finds a negative dentry with the flags set and revalidates it.
Reproduced with a FUSE server that delays its getxattr reply: stat() of a name that was being created hit the WARN_ON() and failed with ECHILD.
Fix this by setting the flags after d_instantiate().
[backport: no tmpfile case and a 2-arg ovl_dentry_init_reval(); no WARN_ON,
but a negative dentry still fails with -ECHILD]
--- fs/overlayfs/dir.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
fs/overlayfs/dir.c +6 -1
@@ -269,7 +269,6 @@ static int ovl_instantiate(struct dentry *dentry, struct inode *inode,ovl_dir_modified (dentry->d_parent, false);ovl_dentry_set_upper_alias (dentry); -ovl_dentry_init_reval (dentry, newdentry);if (!hardlink) {/*
@@ -296,6 +295,12 @@ static int ovl_instantiate(struct dentry *dentry, struct inode *inode, }d_instantiate (dentry, inode); +/* +* The dentry is hashed and a path walk can find it at any time. Set +* the revalidate flags only now, because ovl_dentry_revalidate_common() +* does not expect them on a negative dentry. +*/ +ovl_dentry_init_reval (dentry,ovl_dentry_upper (dentry));if (inode != oip.newinode) {pr_warn_ratelimited ("newly created inode found in cache (%pd2)\n" , dentry);
Signature · 1 line
backport
Quoted 16 lines · Amir Goldstein
commit
50912a1715b8a7c614b654011a0db750e372b43eupstream.
ovl_copy_xattr()gives up if it can't read an attribute thatlistxattr()has named. An empty security.capability, which anybody has been able to store on any file for a long time, is such a case: it is listed, andgetxattr()has nothing to return for it. A file in a lower layer that carries one can't be copied up: it can't be written to, renamed or have its mode changed.There is nothing to copy if there are no data. Go on with the next one.
Fixes 8db6c34f1dbc ("Introduce v3 namespaced file capabilities")Signed-off-by Josef Bacik <[email protected]>
Quoted 7 lines
[amir: treat
-EINVALas no capability too, and do the same in
ovl_copy_up_meta_inode_data()]Signed-off-by Amir Goldstein <[email protected]>---
[ backport: context: no blank line before theovl_getxattr_value()call;
depends one6b9117076fb("ovl: fortifyovl_copy_xattr()against underlying layer modifications") ]
Greg,
Sorry for messing up the send of this series.
This one depends on patch 1/3 from Message-ID
<[email protected]>
Thanks,
Amir.
Quoted 48 lines
fs/overlayfs/copy_up.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)fs/overlayfs/copy_up.c +15
-3@@ -47,6 +47,15 @@ static bool ovl_must_copy_xattr(const char *name)static ssize_t ovl_getxattr_value (const struct path *path,char *name,char **value,ssize_t *value_size); +/* +* Any user can store an empty security.capability, which fails to read with +* -EINVAL. It grants no capability, so treat it as none, like no xattr. +*/ +static bool ovl_no_fscap (ssize_t err) +{ +return err == -ENODATA || err == -EOPNOTSUPP || err == -EINVAL ; +} +int ovl_copy_xattr (struct super_block *sb,const struct path *oldpath,struct dentry *new) {struct dentry *old = oldpath->dentry;@@ -98,6 +107,10 @@ int ovl_copy_xattr(struct super_block *sb, const struct path *oldpath, struct de } size =ovl_getxattr_value (oldpath, name, &value, &value_size);if (size <0 ) { +if (!strcmp (name,XATTR_NAME_CAPS ) &&ovl_no_fscap (size)) { + error =0 ; +continue ; + } error = size;break ; }@@ -947,9 +960,9 @@ static int ovl_copy_up_meta_inode_data(struct ovl_copy_up_ctx *c)if (c->stat.size) { err = cap_size =ovl_getxattr_value (&upperpath,XATTR_NAME_CAPS , &capability, &cap_size); -if (cap_size == -ENODATA || cap_size == -EOPNOTSUPP ) +if (ovl_no_fscap (cap_size)) cap_size =0 ; -if (cap_size <0 ) +else if (cap_size <0 ) goto out; } --backport
Greg Kroah-Hartman
maintainerQuoted 25 lines · Amir Goldstein
Quoted 16 lines · Amir Goldstein
commit
50912a1715b8a7c614b654011a0db750e372b43eupstream.
ovl_copy_xattr()gives up if it can't read an attribute thatlistxattr()has named. An empty security.capability, which anybody has been able to store on any file for a long time, is such a case: it is listed, andgetxattr()has nothing to return for it. A file in a lower layer that carries one can't be copied up: it can't be written to, renamed or have its mode changed.There is nothing to copy if there are no data. Go on with the next one.
Fixes 8db6c34f1dbc ("Introduce v3 namespaced file capabilities")Signed-off-by Josef Bacik <[email protected]>Quoted 7 lines
[amir: treat
-EINVALas no capability too, and do the same in
ovl_copy_up_meta_inode_data()]Signed-off-by Amir Goldstein <[email protected]>---
[ backport: context: no blank line before theovl_getxattr_value()call;
depends one6b9117076fb("ovl: fortifyovl_copy_xattr()against underlying layer modifications") ]
Quoted 6 lines
Greg,
Sorry for messing up the send of this series.
This one depends on patch 1/3 from Message-ID
<[email protected]>
Not a problem, thanks for all of these, now queued up.
greg k-h