Skip to content

Commit

Permalink
ovl: return required buffer size for file handles
Browse files Browse the repository at this point in the history
Overlayfs doesn't work well with the fanotify mechanism.

Fanotify first probes for the required buffer size for the file handle,
but overlayfs currently bails out without passing the size back.

That results in errors in the kernel log, such as:

[527944.485384] overlayfs: failed to encode file handle (/, err=-75, buflen=0, len=29, type=1)
[527944.485386] fanotify: failed to encode fid (fsid=ae521e68.a434d95f, type=255, bytes=0, err=-2)

Signed-off-by: Lubos Dolezel <lubos@dolezel.info>
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
  • Loading branch information
Lubos Dolezel authored and Miklos Szeredi committed May 13, 2020
1 parent 399c109 commit 144da23
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions fs/overlayfs/export.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,30 +231,26 @@ static int ovl_dentry_to_fid(struct dentry *dentry, u32 *fid, int buflen)
if (IS_ERR(fh))
return PTR_ERR(fh);

err = -EOVERFLOW;
len = OVL_FH_LEN(fh);
if (len > buflen)
goto fail;

memcpy(fid, fh, len);
if (len <= buflen)
memcpy(fid, fh, len);
err = len;

out:
kfree(fh);
return err;

fail:
pr_warn_ratelimited("failed to encode file handle (%pd2, err=%i, buflen=%d, len=%d, type=%d)\n",
dentry, err, buflen, fh ? (int)fh->fb.len : 0,
fh ? fh->fb.type : 0);
pr_warn_ratelimited("failed to encode file handle (%pd2, err=%i)\n",
dentry, err);
goto out;
}

static int ovl_encode_fh(struct inode *inode, u32 *fid, int *max_len,
struct inode *parent)
{
struct dentry *dentry;
int bytes = *max_len << 2;
int bytes, buflen = *max_len << 2;

/* TODO: encode connectable file handles */
if (parent)
Expand All @@ -264,12 +260,14 @@ static int ovl_encode_fh(struct inode *inode, u32 *fid, int *max_len,
if (WARN_ON(!dentry))
return FILEID_INVALID;

bytes = ovl_dentry_to_fid(dentry, fid, bytes);
bytes = ovl_dentry_to_fid(dentry, fid, buflen);
dput(dentry);
if (bytes <= 0)
return FILEID_INVALID;

*max_len = bytes >> 2;
if (bytes > buflen)
return FILEID_INVALID;

return OVL_FILEID_V1;
}
Expand Down

0 comments on commit 144da23

Please sign in to comment.