Skip to contentSkip to conversation

autofs4: check dev ioctl size before allocating

PATCH New Ian Kent 1 participant 1 message Apr 7, 2014 Kernel automounter

lore
Share & tools
lore

Ian Kent

author maintainer
#0 lore raw

PATCH 1/1 autofs4: check dev ioctl size before allocating

From: Sasha Levin <[email protected]>

There wasn't any check of the size passed from userspace before trying to allocate the memory required.

This meant that userspace might request more space than allowed, triggering an OOM.

---
 fs/autofs4/dev-ioctl.c |    3 +++
 1 file changed, 3 insertions(+)
fs/autofs4/dev-ioctl.c +3 -0
index 3182c0e..232e03d 100644
@@ -103,6 +103,9 @@ static struct autofs_dev_ioctl *copy_dev_ioctl(struct autofs_dev_ioctl __user *i
 	if (tmp.size < sizeof(tmp))
 		return ERR_PTR(-EINVAL);
 
+	if (tmp.size > (PATH_MAX + sizeof(tmp)))
+		return ERR_PTR(-ENAMETOOLONG);
+
 	return memdup_user(in, tmp.size);
 }