2001-10-27 17:28:31

by Johannes Kloos

[permalink] [raw]
Subject: Deadlock in current devfs with nested symlinks

Hello kernel hackers,
I have found a deadlock in the current version of devfs.
It can be reproduced like this on a system with an IDE CD-ROM drive:
0. Make sure devfs is mounted on /dev and devfsd is running with
MKOLDCOMPAT and MKNEWCOMPAT enabled.
1. Create a symlink from /dev/cdroms/cdrom0 to /dev/cdrom
2. rmmod ide-cd
3a. mount /dev/cdrom /mnt
or
3b. file -L /dev/cdrom

I've traced this bug to the symlink semaphore in devfs.
As far as I can tell, the following events lead to a deadlock:
1. file -L tries to stat(2) /dev/cdrom. stat will follow the symlinks
and acquires symlink_rwsem for reading.
2. /dev/cdroms/cdrom0 doesn't exist, so the kernel tells devfsd
to look up /dev/cdroms/cdrom0.
3. devfsd loads ide-cd.o. Then, it will try to create the appropriate
symlinks in /dev.
4. devfs_do_symlink tries to acquire symlink_rwsem for writing - deadlock.

I've verified this on 2.4.12ac3 and 2.4.13. I had this problem on 2.4.12 as
well.
Updating to a current devfsd didn't help.

--
Johannes Kloos
Developer Version
Programmpaket mit Dokumentation
-- Kristian K?hntopp


Attachments:
(No filename) (1.07 kB)
(No filename) (248.00 B)
Download all attachments

2001-10-30 23:30:15

by Richard Gooch

[permalink] [raw]
Subject: Re: Deadlock in current devfs with nested symlinks

[Apologies for not responding to your earlier email, but I've been
travelling, moving house and caught the 'flu]
Johannes Kloos writes:
> I have found a deadlock in the current version of devfs.
> It can be reproduced like this on a system with an IDE CD-ROM drive:
> 0. Make sure devfs is mounted on /dev and devfsd is running with
> MKOLDCOMPAT and MKNEWCOMPAT enabled.
> 1. Create a symlink from /dev/cdroms/cdrom0 to /dev/cdrom
> 2. rmmod ide-cd
> 3a. mount /dev/cdrom /mnt
> or
> 3b. file -L /dev/cdrom
>
> I've traced this bug to the symlink semaphore in devfs.
> As far as I can tell, the following events lead to a deadlock:
> 1. file -L tries to stat(2) /dev/cdrom. stat will follow the symlinks
> and acquires symlink_rwsem for reading.
> 2. /dev/cdroms/cdrom0 doesn't exist, so the kernel tells devfsd
> to look up /dev/cdroms/cdrom0.
> 3. devfsd loads ide-cd.o. Then, it will try to create the appropriate
> symlinks in /dev.
> 4. devfs_do_symlink tries to acquire symlink_rwsem for writing - deadlock.

Sigh. There's just no clean way of fixing this with the current
code. I'll probably just do what I've been avoiding, which is to
allocate temporary buffer space in the readlink() and follow_link()
methods, and free it prior to return. However, I'll be travelling for
the next couple of days, and will be out of 'net contact. But feel
free to code up a patch along these lines :-)

After this, I really want to avoid band-aid fixes and instead
concentrate on getting the new code to a usable state, since so many
of these problems are not there in the new code.

Regards,

Richard....
Permanent: [email protected]
Current: [email protected]