All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] overlay: return required buffer size for file handles
@ 2020-05-04 19:35 Lubos Dolezel
  2020-05-05  2:58 ` Amir Goldstein
  0 siblings, 1 reply; 3+ messages in thread
From: Lubos Dolezel @ 2020-05-04 19:35 UTC (permalink / raw)
  To: linux-unionfs; +Cc: Miklos Szeredi, Lubos Dolezel

Hello,

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)

Lubos

Signed-off-by: Lubos Dolezel <lubos@dolezel.info>
---
 fs/overlayfs/export.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/fs/overlayfs/export.c b/fs/overlayfs/export.c
index 475c61f53..0068bf3a0 100644
--- a/fs/overlayfs/export.c
+++ b/fs/overlayfs/export.c
@@ -231,12 +231,9 @@ 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 (buflen >= len)
+		memcpy(fid, fh, len);
 	err = len;
 
 out:
@@ -255,6 +252,7 @@ static int ovl_encode_fh(struct inode *inode, u32 *fid, int *max_len,
 {
 	struct dentry *dentry;
 	int bytes = *max_len << 2;
+	int bytes_used;
 
 	/* TODO: encode connectable file handles */
 	if (parent)
@@ -264,12 +262,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_used = ovl_dentry_to_fid(dentry, fid, bytes);
 	dput(dentry);
-	if (bytes <= 0)
+	if (bytes_used <= 0)
 		return FILEID_INVALID;
 
-	*max_len = bytes >> 2;
+	*max_len = bytes_used >> 2;
+	if (bytes_used > bytes)
+		return FILEID_INVALID;
 
 	return OVL_FILEID_V1;
 }
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-05-06 10:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-04 19:35 [PATCH] overlay: return required buffer size for file handles Lubos Dolezel
2020-05-05  2:58 ` Amir Goldstein
2020-05-06 10:22   ` Amir Goldstein

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.