Skip to contentSkip to conversation

autofs4: check dev ioctl size before allocating

PATCH In review Sasha Levin 2 participants 6 messages Mar 16, 2014 – Apr 7, 2014

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

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

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 files changed, 3 insertions(+), 0 deletions(-)
fs/autofs4/dev-ioctl.c +3 -0
index 3182c0e..86fa7af 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(-E2BIG);
+
 	return memdup_user(in, tmp.size);
 }
 
Signature · 1 line
1.7.2.5
#1 lore raw

Ping? Anyone wants to take this?

Quoted 26 lines · Sasha Levin

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 files changed, 3 insertions(+), 0 deletions(-)
fs/autofs4/dev-ioctl.c +3 -0
index 3182c0e..86fa7af 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(-E2BIG);
+
 	return memdup_user(in, tmp.size);
 }
 
maintainer
#2 lore raw
Quoted 1 line · Sasha Levin

Ping? Anyone wants to take this?

Is this causing a problem for users?
If it is I'll send it to Andrew straight away.

I do have this on my queue but don't have any other patches to send so it's just sitting there.

If it worries you I'll send it to Andrew now.

Quoted 29 lines · Sasha Levin
Quoted 26 lines

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 files changed, 3 insertions(+), 0 deletions(-)
fs/autofs4/dev-ioctl.c +3 -0
index 3182c0e..86fa7af 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(-E2BIG);
+
 	return memdup_user(in, tmp.size);
 }
 
#3 lore raw
Quoted 10 lines · Ian Kent
Quoted 1 line · Sasha Levin

Ping? Anyone wants to take this?

Is this causing a problem for users?
If it is I'll send it to Andrew straight away.

I do have this on my queue but don't have any other patches to send so it's just sitting there.

If it worries you I'll send it to Andrew now.

It's not really a pressing issue since /dev/autofs is accessible only to root. I also doubt that it causes problems for actual users.

If there are no issues with the patch, I think it's best if you could ack/sign off on it and if Andrew wants to take it now, he could. If he doesn't, it could wait for whenever.

I just don't want it getting lost somewhere and never making it upstream.

Thanks,
Sasha

maintainer
#4 lore raw
Quoted 12 lines · Sasha Levin
Quoted 10 lines · Ian Kent
Quoted 1 line · Sasha Levin

Ping? Anyone wants to take this?

Is this causing a problem for users?
If it is I'll send it to Andrew straight away.

I do have this on my queue but don't have any other patches to send so it's just sitting there.

If it worries you I'll send it to Andrew now.

Quoted 8 lines

It's not really a pressing issue since /dev/autofs is accessible only to root. I also doubt that it causes problems for actual users.

If there are no issues with the patch, I think it's best if you could ack/sign off on it and if Andrew wants to take it now, he could. If he doesn't, it could wait for whenever.

I just don't want it getting lost somewhere and never making it upstream.

OK, but since I'm going to send it I looked at it a bit closer. Shouldn't the E2BIG be ENAMETOOLONG since it's a file path that's being passed?

I can change that and send it if you agree with the change.

Ian

#5 lore raw
Quoted 20 lines · Ian Kent
Quoted 19 lines · Sasha Levin
Quoted 10 lines · Ian Kent
Quoted 1 line · Sasha Levin

Ping? Anyone wants to take this?

Is this causing a problem for users?
If it is I'll send it to Andrew straight away.

I do have this on my queue but don't have any other patches to send so it's just sitting there.

If it worries you I'll send it to Andrew now.

It's not really a pressing issue since /dev/autofs is accessible only to root. I also doubt that it causes problems for actual users.

If there are no issues with the patch, I think it's best if you could ack/sign off on it and if Andrew wants to take it now, he could. If he doesn't, it could wait for whenever.

Quoted 7 lines
Quoted 1 line

I just don't want it getting lost somewhere and never making it upstream.

OK, but since I'm going to send it I looked at it a bit closer. Shouldn't the E2BIG be ENAMETOOLONG since it's a file path that's being passed?

I can change that and send it if you agree with the change.

Looks good to me, thanks!

Thanks,
Sasha