From 6b2d5fe46fa8f4fc1c5262c73930b9a2a94db2e3 Mon Sep 17 00:00:00 2001 From: Miklos Szeredi Date: Fri, 16 Dec 2016 11:02:56 +0100 Subject: ovl: check namelen We already calculate f_namelen in statfs as the maximum of the name lengths provided by the filesystems taking part in the overlay. Signed-off-by: Miklos Szeredi --- fs/overlayfs/namei.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'fs/overlayfs/namei.c') diff --git a/fs/overlayfs/namei.c b/fs/overlayfs/namei.c index f4057fcb0246..2e0b84c68ef6 100644 --- a/fs/overlayfs/namei.c +++ b/fs/overlayfs/namei.c @@ -20,7 +20,8 @@ static struct dentry *ovl_lookup_real(struct dentry *dir, dentry = lookup_one_len_unlocked(name->name, dir, name->len); if (IS_ERR(dentry)) { - if (PTR_ERR(dentry) == -ENOENT) + if (PTR_ERR(dentry) == -ENOENT || + PTR_ERR(dentry) == -ENAMETOOLONG) dentry = NULL; } else if (!dentry->d_inode) { dput(dentry); @@ -74,6 +75,7 @@ struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry, { struct ovl_entry *oe; const struct cred *old_cred; + struct ovl_fs *ofs = dentry->d_sb->s_fs_info; struct ovl_entry *poe = dentry->d_parent->d_fsdata; struct path *stack = NULL; struct dentry *upperdir, *upperdentry = NULL; @@ -86,6 +88,9 @@ struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry, unsigned int i; int err; + if (dentry->d_name.len > ofs->namelen) + return ERR_PTR(-ENAMETOOLONG); + old_cred = ovl_override_creds(dentry->d_sb); upperdir = ovl_upperdentry_dereference(poe); if (upperdir) { @@ -127,14 +132,9 @@ struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry, this = ovl_lookup_real(lowerpath.dentry, &dentry->d_name); err = PTR_ERR(this); - if (IS_ERR(this)) { - /* - * If it's positive, then treat ENAMETOOLONG as ENOENT. - */ - if (err == -ENAMETOOLONG && (upperdentry || ctr)) - continue; + if (IS_ERR(this)) goto out_put; - } + if (!this) continue; if (ovl_is_whiteout(this)) { -- cgit v1.2.3-55-g7522