Skip to content

Commit

Permalink
[PATCH] ptmx: fix duplicate idr_remove
Browse files Browse the repository at this point in the history
Remove duplicate call to idr_remove() in ptmx_open.

Error during open can result in call to release_dev() followed by call to
idr_remove().  release_dev already calls idr_remove so the second call can
cause a stack dump in idr_remove()->sub_remove() flagging an attempt to
release an already released entry.

I reproduces this on a machine with a misconfigured X server (attempting to
restart multiple times rapidly) getting the same error as the 1st link
below.

This also seems to be related to:
http://marc.theaimsgroup.com/?l=selinux&m=110536513426735&w=2
http://marc.theaimsgroup.com/?l=selinux&m=110596994916785&w=2

The stack dump can occur on close (as well as open) as shown
in the 1st instance above, possible from something like:

process A - open (index=0), open fail to out1,
  release_dev calls idr_remove (index 0), down(sem) sleeps
process B - open (index=0), open OK (idr allocated)
process A - wake and call idr_remove on index 0
...
process B - close, release_dev, stack dump on idr_remove (index=0)
  because entry already removed

Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
  • Loading branch information
Paul Fulghum authored and Linus Torvalds committed Apr 11, 2006
1 parent acc8dad commit 9453a5a
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions drivers/char/tty_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -2195,6 +2195,7 @@ static int ptmx_open(struct inode * inode, struct file * filp)
return 0;
out1:
release_dev(filp);
return retval;
out:
down(&allocated_ptys_lock);
idr_remove(&allocated_ptys, index);
Expand Down

0 comments on commit 9453a5a

Please sign in to comment.