Skip to contentSkip to conversation

autofs: sanity check status reported with AUTOFS_DEV_IOCTL_FAIL

PATCH Applied NeilBrown 4 participants 5 messages Jun 7, 2017 – Jun 16, 2017 Kernel automounter

lore
Share & tools
lore

NeilBrown

author
#0 lore raw

PATCH 1/1 autofs: sanity check status reported with AUTOFS_DEV_IOCTL_FAIL

If a positive status is passed with the AUTOFS_DEV_IOCTL_FAIL ioctl, autofs4_d_automount() will return
ERR_PTR(status)
with that status to follow_automount(), which will then dereference an invalid pointer.

So treat a positive status the same as zero, and map to ENOENT.

See comment in systemd src/core/automount.c::automount_send_ready().

---
 fs/autofs4/dev-ioctl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/autofs4/dev-ioctl.c +1 -1
index 734cbf8d9676..dd9f1bebb5a3 100644
@@ -344,7 +344,7 @@ static int autofs_dev_ioctl_fail(struct file *fp,
 	int status;
 
 	token = (autofs_wqt_t) param->fail.token;
-	status = param->fail.status ? param->fail.status : -ENOENT;
+	status = param->fail.status < 0 ? param->fail.status : -ENOENT;
 	return autofs4_wait_release(sbi, token, status);
 }
 
Signature · 1 line
2.12.2
#1 lore raw
Quoted 17 lines · On Wed, 07 Jun 2017 12:08:38 +1000 NeilBrown <[email protected]> wrote:

If a positive status is passed with the AUTOFS_DEV_IOCTL_FAIL ioctl, autofs4_d_automount() will return
ERR_PTR(status)
with that status to follow_automount(), which will then dereference an invalid pointer.

So treat a positive status the same as zero, and map to ENOENT.

See comment in systemd src/core/automount.c::automount_send_ready().

...

fs/autofs4/dev-ioctl.c static int autofs_dev_ioctl_fail(struct file *fp, · line 349

Quoted 7 lines
fs/autofs4/dev-ioctl.c +1 -1
@@ -344,7 +344,7 @@ static int autofs_dev_ioctl_fail(struct file *fp,
 	int status;
 
 	token = (autofs_wqt_t) param->fail.token;
-	status = param->fail.status ? param->fail.status : -ENOENT;
+	status = param->fail.status < 0 ? param->fail.status : -ENOENT;
 	return autofs4_wait_release(sbi, token, status);
 }

Sounds serious. Was the absence of a cc:stable deliberate? --
To unsubscribe from this list: send the line "unsubscribe autofs" in

author
#2 lore raw
Quoted 21 lines · Andrew Morton
Quoted 19 lines · On Wed, 07 Jun 2017 12:08:38 +1000 NeilBrown <[email protected]> wrote:

If a positive status is passed with the AUTOFS_DEV_IOCTL_FAIL ioctl, autofs4_d_automount() will return
ERR_PTR(status)
with that status to follow_automount(), which will then dereference an invalid pointer.

So treat a positive status the same as zero, and map to ENOENT.

See comment in systemd src/core/automount.c::automount_send_ready().

...

fs/autofs4/dev-ioctl.c +0 -0
@@ -344,7 +344,7 @@ static int autofs_dev_ioctl_fail(struct file *fp,
 	int status;
 
Quoted 7 lines

fs/autofs4/dev-ioctl.c static int autofs_dev_ioctl_fail(struct file *fp, · line 349

Quoted 5 lines
fs/autofs4/dev-ioctl.c +1 -1
 	token = (autofs_wqt_t) param->fail.token;
-	status = param->fail.status ? param->fail.status : -ENOENT;
+	status = param->fail.status < 0 ? param->fail.status : -ENOENT;
 	return autofs4_wait_release(sbi, token, status);
 }

Sounds serious. Was the absence of a cc:stable deliberate?

You need CAP_SYS_ADMIN to get the ioctl even looked at. Doesn't that mean the bug can only be triggered by a process that could easily do worse?

Or do containers allow admins to give out CAP_SYS_ADMIN to untrusted people?? I haven't been keeping up.

Given how simple the patch is, it probably makes sense to add a cc:stable, just in case.

Thanks,
NeilBrown

maintainer
#3 lore raw
Quoted 31 lines · NeilBrown
Quoted 16 lines · Andrew Morton
Quoted 14 lines · On Wed, 07 Jun 2017 12:08:38 +1000 NeilBrown <[email protected]> wrote:

If a positive status is passed with the AUTOFS_DEV_IOCTL_FAIL ioctl, autofs4_d_automount() will return ERR_PTR(status)
with that status to follow_automount(), which will then dereference an invalid pointer.

So treat a positive status the same as zero, and map to ENOENT.

See comment in systemd src/core/automount.c::automount_send_ready().

...

Quoted 12 lines
Quoted 10 lines
fs/autofs4/dev-ioctl.c +0 -0
@@ -344,7 +344,7 @@ static int autofs_dev_ioctl_fail(struct file *fp,
  	int status;


  token = (autofs_wqt_t) param->fail.token;

fs/autofs4/dev-ioctl.c +1 -1
-	status = param->fail.status ? param->fail.status : -ENOENT;
+	status = param->fail.status < 0 ? param->fail.status : -ENOENT;

  return autofs4_wait_release(sbi, token, status); }

Sounds serious.  Was the absence of a cc:stable deliberate?

Quoted 3 lines

You need CAP_SYS_ADMIN to  get the ioctl even looked at.  Doesn't that mean the bug can only be triggered by a process that could easily do worse?

Think so, yes.

Quoted 3 lines

Or do containers allow admins to give out CAP_SYS_ADMIN to untrusted people??  I haven't been keeping up.

Maybe, with docker root can start a container with --privileged to give the container admin capabilities. It may be the case that capabilities can be used now I don't know.

Quoted 3 lines

Given how simple the patch is, it probably makes sense to add a cc:stable, just in case.

IMHO it needs to be applied to stable as well.

Quoted 3 lines

Thanks,
NeilBrown

--
To unsubscribe from this list: send the line "unsubscribe autofs" in

#4 lore raw
In reply to NeilBrown
Quoted 15 lines · NeilBrown
Quoted 6 lines · Andrew Morton
Quoted 5 lines · On Wed, 07 Jun 2017 12:08:38 +1000 NeilBrown <[email protected]> wrote:
fs/autofs4/dev-ioctl.c +0 -0
@@ -344,7 +344,7 @@ static int autofs_dev_ioctl_fail(struct file *fp,
 	int status;
 
Quoted 7 lines

fs/autofs4/dev-ioctl.c static int autofs_dev_ioctl_fail(struct file *fp, · line 349

Quoted 5 lines
fs/autofs4/dev-ioctl.c +1 -1
 	token = (autofs_wqt_t) param->fail.token;
-	status = param->fail.status ? param->fail.status : -ENOENT;
+	status = param->fail.status < 0 ? param->fail.status : -ENOENT;
 	return autofs4_wait_release(sbi, token, status);
 }

Sounds serious. Was the absence of a cc:stable deliberate?

Quoted 6 lines

You need CAP_SYS_ADMIN to get the ioctl even looked at. Doesn't that mean the bug can only be triggered by a process that could easily do worse?

Or do containers allow admins to give out CAP_SYS_ADMIN to untrusted people?? I haven't been keeping up.

Yep. They can be configured individually in fact, eg:

  $ docker run --cap-drop=ALL --cap-add=sys_admin -it debian:jessie /bin/bash
  root@aedebe8c46e0:/# capsh --print
  Current: = cap_sys_admin+eip
  Bounding set =cap_sys_admin
  Securebits: 00/0x0/1'b0
   secure-noroot: no (unlocked)
   secure-no-suid-fixup: no (unlocked)
   secure-keep-caps: no (unlocked)
  uid=0(root)
  gid=0(root)
  groups=

cheers
--
To unsubscribe from this list: send the line "unsubscribe autofs" in