Skip to contentSkip to conversation

udev and cdrom permissions

DISCUSSION Stefan Schweizer 4 participants 10 messages Nov 10, 2004 – Dec 7, 2004

lore
Share & tools
lore
#0 lore raw

Hi,

with udev we have the general problem that it sets the group disk for every hd* device. With this normal users cant write or read cdroms without being in the disk group which is a security problem. We really need to assign the cdrom group to cdrom-devices.

I have 2 solutions to propose:
1) We make udev follow symlinks while setting permissions. So if udev assigns permissions to /dev/cdroms/cdrom0 it should set the permission for the source of the symlink.

2) We make hd* the symlink. This way /dev/cdroms/cdrom* and /dev/discs/disc* would be the real device nodes and therefore have the right permissions.

Do you have other possible solutions, and what solution doyou think is best?

Thanks
Stefan Schweizer

-------------------------------------------------------
This SF.Net email is sponsored by:
Sybase ASE Linux Express Edition - download now for FREE LinuxWorld Reader's Choice Award Winner for best database on Linux.
http://ads.osdn.com/?ad_idU88&alloc_id065&op=click
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#1 lore raw
Quoted 4 lines · Stefan Schweizer

with udev we have the general problem that it sets the group disk for every hd* device. With this normal users cant write or read cdroms without being in the disk group which is a security problem. We really need to assign the cdrom group to cdrom-devices.

md@wonderland:~$cat /etc/udev/simple-cd-aliases.rules

# grouping of optical drives from multiple kernel subsystems
KERNEL="sr*",     NAME="%k", SYMLINK="cdrom%e"
KERNEL="scd*",    NAME="%k", SYMLINK="cdrom%e"
KERNEL="pcd*",    NAME="%k", SYMLINK="cdrom%e"
KERNEL="hd[a-z]", NAME="%k", SYMLINK="cdrom%e", PROGRAM="/bin/cat /proc/ide/%k/media", RESULT="cdrom"

md@wonderland:~$

Just add GROUP statements.

Signature · 13 lines
ciao, |
Marco | [9127 scp/Mb5GlCdUc]


-------------------------------------------------------
This SF.Net email is sponsored by:
Sybase ASE Linux Express Edition - download now for FREE
LinuxWorld Reader's Choice Award Winner for best database on Linux.
http://ads.osdn.com/?ad_idU88&alloc_id065&op=click
_______________________________________________
Linux-hotplug-devel mailing list  http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
#2 lore raw
In reply to Stefan Schweizer
Quoted 10 lines · Marco d'Itri

md@wonderland:~$cat /etc/udev/simple-cd-aliases.rules

# grouping of optical drives from multiple kernel subsystems
KERNEL="sr*",     NAME="%k", SYMLINK="cdrom%e"
KERNEL="scd*",    NAME="%k", SYMLINK="cdrom%e"
KERNEL="pcd*",    NAME="%k", SYMLINK="cdrom%e"
KERNEL="hd[a-z]", NAME="%k", SYMLINK="cdrom%e", PROGRAM="/bin/cat /proc/ide/%k/media", RESULT="cdrom"

md@wonderland:~$

Just add GROUP statements.

This is a very good idea. ide-devfs.sh should be modified to also produce GROUP= output.
And of course the default rule to also contain the GROUP= statement, calculated by ide-devfs.sh.

Change needed to make this work:

namedev.c 2004-11-11 00:23:24.228575344 +0100 renamed from namedev.c.orig 2004-11-11 00:22:11.646609480 +0100 +3 -0
@@ -785,6 +785,11 @@
                goto done;
 
        udev->partitions = dev->partitions;
+       if (dev->group[0] != '\0') {
+               strfieldcpy(udev->group, dev->group);
+               apply_format(udev, udev->group, sizeof(udev->group),

class_dev, sysfs_device);
+
+ }

        /* get permissions given in rule */
        set_empty_perms(udev, dev->mode,

in /etc/udev/rules.d/udev.rules:
BUS="ide", KERNEL="hd*", PROGRAM="/etc/udev/scripts/ide-devfs.sh %k %b %n", NAME="%k", SYMLINK="%c{1} %c{2}", GROUP="%c{3}"

in /etc/udev/scripts/ide-devfs.sh:

                echo ide/host${HOST}/bus${BUS}/target${TARGET}/lun0/cd
cdroms/cdrom`get_dev_number $1 cdrom` cdrom
        elif [ "${MEDIA}" = "floppy" ]; then
                echo
ide/host${HOST}/bus${BUS}/target${TARGET}/lun0/disc
floppies/floppy`get_dev_number $1 floppy`/disc floppy
        elif [ "${MEDIA}" = "disk" ]; then
                echo

ide/host${HOST}/bus${BUS}/target${TARGET}/lun0/disc discs/discget_dev_number $1 disk/disc disk

(add the type again at the end)

-------------------------------------------------------
This SF.Net email is sponsored by:
Sybase ASE Linux Express Edition - download now for FREE LinuxWorld Reader's Choice Award Winner for best database on Linux.
http://ads.osdn.com/?ad_idU88&alloc_id065&op=click
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#3 lore raw
In reply to Stefan Schweizer

Hi,
I have attached a rolled-up-patch that contains all necessarry changes to make it work.

Please check the C-part again because I am not quite sure with it, but it works :)

Stefan

etc/udev/udev.rules.gentoo +1 -1
diff -pur --show-c-function udev-044.orig/etc/udev/udev.rules.gentoo udev-044/etc/udev/udev.rules.gentoo
@@ -19,7 +19,7 @@ BUS="scsi", KERNEL="scd[a-z]", PROGRAM="
 
 # devfs-names for ide-devices (uncomment only one)
 #  /dev/ide/.../{disc,cd} and /dev/{cdroms,discs}/* type names
-BUS="ide", KERNEL="hd*", PROGRAM="/etc/udev/scripts/ide-devfs.sh %k %b %n", NAME="%k", SYMLINK="%c{1} %c{2}"
+BUS="ide", KERNEL="hd*", PROGRAM="/etc/udev/scripts/ide-devfs.sh %k %b %n", NAME="%k", SYMLINK="%c{1} %c{2}", GROUP="%c{3}"
 
 # DRI devices
 KERNEL="card*", NAME="dri/card%n"
extras/ide-devfs.sh +3 -3
diff -pur --show-c-function udev-044.orig/extras/ide-devfs.sh udev-044/extras/ide-devfs.sh
@@ -36,11 +36,11 @@ get_dev_number() {
 if [ -z "$3" ] && [ -f /proc/ide/${1}/media ]; then
 	MEDIA=`cat /proc/ide/${1}/media`
 	if [ "${MEDIA}" = "cdrom" ]; then
-		echo ide/host${HOST}/bus${BUS}/target${TARGET}/lun0/cd cdroms/cdrom`get_dev_number $1 cdrom`
+		echo ide/host${HOST}/bus${BUS}/target${TARGET}/lun0/cd cdroms/cdrom`get_dev_number $1 cdrom` ${MEDIA}
 	elif [ "${MEDIA}" = "floppy" ]; then
-		echo ide/host${HOST}/bus${BUS}/target${TARGET}/lun0/disc floppies/floppy`get_dev_number $1 floppy`/disc
+		echo ide/host${HOST}/bus${BUS}/target${TARGET}/lun0/disc floppies/floppy`get_dev_number $1 floppy`/disc ${MEDIA}
 	elif [ "${MEDIA}" = "disk" ]; then
-		echo ide/host${HOST}/bus${BUS}/target${TARGET}/lun0/disc discs/disc`get_dev_number $1 disk`/disc
+		echo ide/host${HOST}/bus${BUS}/target${TARGET}/lun0/disc discs/disc`get_dev_number $1 disk`/disc ${MEDIA}
 	fi
 else
 	echo ide/host${HOST}/bus${BUS}/target${TARGET}/lun0/part$3 discs/disc`get_dev_number $1 disk`/part$3
namedev.c +5 -0
diff -pur --show-c-function udev-044.orig/namedev.c udev-044/namedev.c
@@ -786,6 +786,11 @@ found:
 
 	udev->partitions = dev->partitions;
 
+	if (dev->group[0] != '\0') {
+		strfieldcpy(udev->group, dev->group);
+		apply_format(udev, udev->group, sizeof(udev->group), class_dev, sysfs_device);	
+	}
+
 	/* get permissions given in rule */
 	set_empty_perms(udev, dev->mode,
 			      dev->owner,
#4 lore raw
In reply to Stefan Schweizer

I do not see this included in udev-045, are there any problems with it?

-------------------------------------------------------
This SF.Net email is sponsored by: InterSystems CACHE
FREE OODBMS DOWNLOAD - A multidimensional database that combines robust object and relational technologies, making it a perfect match for Java, C++,COM, XML, ODBC and JDBC. www.intersystems.com/match8
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#5 lore raw
In reply to Stefan Schweizer
Quoted 6 lines · Stefan Schweizer

Hi,
I have attached a rolled-up-patch that contains all necessarry changes to make it work.

Please check the C-part again because I am not quite sure with it, but it works :)

It looks good, sorry for the long delay in looking at this.

I've added it to the tree. Care to make up a test for the udev-test.pl script to test that this feature works properly?

thanks,

greg k-h

-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now.
http://productguide.itmanagersjournal.com/
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#6 lore raw
In reply to Stefan Schweizer
Quoted 3 lines · Greg KH

It looks good, sorry for the long delay in looking at this.

Thank you very much for making this working :)

Quoted 2 lines

I've added it to the tree. Care to make up a test for the udev-test.pl script to test that this feature works properly?

sorry, did not come around to.

Stefan

-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now.
http://productguide.itmanagersjournal.com/
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#7 lore raw
In reply to Stefan Schweizer
Quoted 5 lines · Stefan Schweizer
Quoted 3 lines · Greg KH

It looks good, sorry for the long delay in looking at this.

Thank you very much for making this working :)

Hm, I think the recent merge with Kay, caused this code to be removed. Can you get a snapshot of the current bk tree and see if it works for you or not? If not, care to send another patch?

thanks,

greg k-h

-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now.
http://productguide.itmanagersjournal.com/
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#8 lore raw
In reply to Stefan Schweizer
Quoted 10 lines · Greg KH
Quoted 5 lines · Stefan Schweizer
Quoted 3 lines · Greg KH

It looks good, sorry for the long delay in looking at this.

Thank you very much for making this working :)

Hm, I think the recent merge with Kay, caused this code to be removed. Can you get a snapshot of the current bk tree and see if it works for you or not? If not, care to send another patch?

Yeah, sorry. I've restored it and applied it to my tree.

Thanks,
Kay

-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now.
http://productguide.itmanagersjournal.com/
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#9 lore raw
In reply to Stefan Schweizer
Quoted 6 lines · Kay Sievers
Quoted 5 lines · Greg KH
Quoted 4 lines · Stefan Schweizer
Quoted 3 lines · Greg KH

It looks good, sorry for the long delay in looking at this.

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

Thank you very much for making this working :)

Hm, I think the recent merge with Kay, caused this code to be removed. Can you get a snapshot of the current bk tree and see if it works for you or not? If not, care to send another patch?

Yeah, sorry. I've restored it and applied it to my tree.

Thanks for doing that.

greg k-h

-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now.
http://productguide.itmanagersjournal.com/
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel