Skip to contentSkip to conversation

linux-next: Fixes tag needs some work in the overlayfs tree

PATCH New Stephen Rothwell 2 participants 2 messages May 13, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

Hi all,

In commit

8d628847a2f8 ("ovl: potential crash in ovl_fid_to_fh()")

Fixes tag

Fixes cbe7fba8edfc: ("ovl: make sure that real fid is 32bit aligned in memory")

has these problem(s):

- unexpected colon after SHA1

Signature · 2 lines
Cheers,
Stephen Rothwell
#1 lore raw

PATCH v3 1/1 ovl: potential crash in ovl_fid_to_fh()

The "buflen" value comes from the user and there is a potential that it could be zero. In do_handle_to_path() we know that "handle->handle_bytes" is non-zero and we do:

	handle_dwords = handle->handle_bytes >> 2;

So values 1-3 become zero. Then in ovl_fh_to_dentry() we do:

	int len = fh_len << 2;

So now len is in the "0,4-128" range and a multiple of 4. But if "buflen" is zero it will try to copy negative bytes when we do the memcpy in ovl_fid_to_fh().

	memcpy(&fh->fb, fid, buflen - OVL_FH_WIRE_OFFSET);

And that will lead to a crash. Thanks to Amir Goldstein for his help with this patch.

Fixes cbe7fba8edfc ("ovl: make sure that real fid is 32bit aligned in memory")

---
v2: Move the check after the other checks
v3: Fix Fixes tag

 fs/overlayfs/export.c | 3 +++
 1 file changed, 3 insertions(+)
fs/overlayfs/export.c +3 -0
index 475c61f53f0fe..ed5c1078919cc 100644
@@ -783,6 +783,9 @@ static struct ovl_fh *ovl_fid_to_fh(struct fid *fid, int buflen, int fh_type)
 	if (fh_type != OVL_FILEID_V0)
 		return ERR_PTR(-EINVAL);
 
+	if (buflen <= OVL_FH_WIRE_OFFSET)
+		return ERR_PTR(-EINVAL);
+
 	fh = kzalloc(buflen, GFP_KERNEL);
 	if (!fh)
 		return ERR_PTR(-ENOMEM);
Signature · 1 line
2.26.2