Skip to contentSkip to conversation

Whitespaces in ID_VENDOR and ID_MODEL

DISCUSSION Marcel Holtmann 2 participants 4 messages Jan 5, 2009 – Jan 6, 2009

lore
Share & tools
lore
#0 lore raw

Hi Kay,

so I was playing with adding environment variables to devices in the udev database for later easy enumeration. And I like having ID_VENDOR and ID_MODEL available and would like to extend this even to PCI and SDIO in the future, but why are all whitespace replaced with "_".

P: /devices/pci0000:00/0000:00:1a.1/usb3/3-1/3-1:1.0/ttyUSB0/tty/ttyUSB0
N: ttyUSB0
S: char/188:0
S: serial/by-path/pci-0000:00:1a.1-usb-0:1:1.0-port0
S: serial/by-id/usb-Novatel_Wireless_Novatel_Wireless_HSUPA_Modem_356846015115701-if00-port0
E: UDEV_LOG=3
E: DEVPATH=/devices/pci0000:00/0000:00:1a.1/usb3/3-1/3-1:1.0/ttyUSB0/tty/ttyUSB0
E: MAJOR8
E: MINOR=0
E: DEVNAME=/dev/ttyUSB0
E: ID_PORT=0
E: ID_PATH=pci-0000:00:1a.1-usb-0:1:1.0
E: ID_VENDOR=Novatel_Wireless
E: ID_MODEL=Novatel_Wireless_HSUPA_Modem
E: ID_REVISION00
E: ID_SERIAL=Novatel_Wireless_Novatel_Wireless_HSUPA_Modem_356846015115701
E: ID_SERIAL_SHORT56846015115701
E: ID_TYPE=generic
E: ID_BUS=usb
E: ID_IFACE
E: ID_MODEM_GSM=1
E: ID_MODEM_PROBED=1
E: DEVLINKS=/dev/char/188:0 /dev/serial/by-path/pci-0000:00:1a.1-usb-0:1:1.0-port0 /dev/serial/by-id/usb-Novatel_Wireless_Novatel_Wireless_HSUPA_Modem_356846015115701-if00-port0

This is one of my UMTS modem sticks and the corresponding USB details are this:

T:  Bus Lev Prnt Port Cnt Dev#=  3 Spd  MxCh= 0
D:  Ver= 1.10 Cls(>ifc ) Sub Prot MxPSd #Cfgs=  1
P:  Vendor10 ProdIDD00 Rev= 0.00
S:  Manufacturer=Novatel Wireless
S:  Product=Novatel Wireless HSUPA Modem
S:  SerialNumber56846015115701
C:* #Ifs= 2 Cfg#= 1 Atr  MxPwrP0mA
I:* If#= 0 Alt= 0 #EPs= 3 Clsÿ(vend.) Subÿ Protÿ Driver=option
E:  Ad�(I) Atr(Int.) MxPS=  16 Ivl8ms
E:  Ad‚(I) Atr(Bulk) MxPS=  64 Ivl=0ms
E:  Ad(O) Atr(Bulk) MxPS=  64 Ivl=0ms
I:* If#= 1 Alt= 0 #EPs= 2 Clsÿ(vend.) Subÿ Protÿ Driver=option
E:  Ad„(I) Atr(Bulk) MxPS=  64 Ivl=0ms
E:  Ad(O) Atr(Bulk) MxPS=  64 Ivl=0ms

So as you can see we are mangling the Manufacturer and Product whitespaces into "_". Is there are specific reason why we are doing it this way?

Regards

Marcel

--
To unsubscribe from this list: send the line "unsubscribe linux-hotplug" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#1 lore raw
Quoted 9 lines · Marcel Holtmann

so I was playing with adding environment variables to devices in the udev database for later easy enumeration. And I like having ID_VENDOR and ID_MODEL available and would like to extend this even to PCI and SDIO in the future, but why are all whitespace replaced with "_".

E: ID_VENDOR=Novatel_Wireless
E: ID_MODEL=Novatel_Wireless_HSUPA_Modem
E: ID_REVISION00
E: ID_SERIAL=Novatel_Wireless_Novatel_Wireless_HSUPA_Modem_356846015115701

Yeah, all strings in usb_id are mangled to be used in symlink names. Like all the other *_id tools do too. When we started doing that, nobody thought we would ever use these strings for anything else than creating symlinks. :)

Some of the values, like ATA and SCSI just fill the whole remaining string buffer with whitespaces, which need to be stripped too, to be used in symlinks.

For stuff that needs to be reversible, like filesystem label strings, which can contain any char, need to be valid and safe chars to be a symlink, and we need to be able to translate the name back to the original value, we encode the string with url encoding, like:
ID_FS_LABEL=/
ID_FS_LABEL_ENC=\x2f

We need to sanitize the values at least for things like newline, quoting and other control chars, because most of these values are completely "untrusted userdata", and a fake device with a usb model string like "Foo\nBAR=1" we don't want to import unmangled. :)

If you have an idea what we should do/change to make these values more useful, let me know.

Kay

#2 lore raw
In reply to Marcel Holtmann

Hi Kay,

Quoted 10 lines
Quoted 9 lines

so I was playing with adding environment variables to devices in the udev database for later easy enumeration. And I like having ID_VENDOR and ID_MODEL available and would like to extend this even to PCI and SDIO in the future, but why are all whitespace replaced with "_".

E: ID_VENDOR=Novatel_Wireless
E: ID_MODEL=Novatel_Wireless_HSUPA_Modem
E: ID_REVISION00
E: ID_SERIAL=Novatel_Wireless_Novatel_Wireless_HSUPA_Modem_356846015115701

Quoted 4 lines

Yeah, all strings in usb_id are mangled to be used in symlink names. Like all the other *_id tools do too. When we started doing that, nobody thought we would ever use these strings for anything else than creating symlinks. :)

for things like ID_SERIAL this makes sense to me. For ID_VENDOR and ID_MODEL not so much. Does udev itself use these values anywhere? Or can we have udev just do the stripping part and have *_id tools return the plain values?

Quoted 11 lines

Some of the values, like ATA and SCSI just fill the whole remaining string buffer with whitespaces, which need to be stripped too, to be used in symlinks.

For stuff that needs to be reversible, like filesystem label strings, which can contain any char, need to be valid and safe chars to be a symlink, and we need to be able to translate the name back to the original value, we encode the string with url encoding, like:
ID_FS_LABEL=/
ID_FS_LABEL_ENC=\x2f

Quoted 7 lines

We need to sanitize the values at least for things like newline, quoting and other control chars, because most of these values are completely "untrusted userdata", and a fake device with a usb model string like "Foo\nBAR=1" we don't want to import unmangled. :)

If you have an idea what we should do/change to make these values more useful, let me know.

I agree that we need to do at least some kind of sanitization, but for a lot of these values having the clear text strings available would be really nice. Especially the ID_VENDOR and ID_MODEL strings. If udev is having access to these string (like for USB or when creating unique symlinks) anyway, then it makes no sense to not duplicate the logic to these from the device.

Do you ever defined a character set for the environment values? It would be nice if it UTF-8, because then we can copy most values natively.

Regards

Marcel

#3 lore raw
In reply to Marcel Holtmann
Quoted 10 lines · Marcel Holtmann
Quoted 10 lines
Quoted 9 lines

so I was playing with adding environment variables to devices in the udev database for later easy enumeration. And I like having ID_VENDOR and ID_MODEL available and would like to extend this even to PCI and SDIO in the future, but why are all whitespace replaced with "_".

E: ID_VENDOR=Novatel_Wireless
E: ID_MODEL=Novatel_Wireless_HSUPA_Modem
E: ID_REVISION00
E: ID_SERIAL=Novatel_Wireless_Novatel_Wireless_HSUPA_Modem_356846015115701

Quoted 7 lines
Quoted 4 lines

Yeah, all strings in usb_id are mangled to be used in symlink names. Like all the other *_id tools do too. When we started doing that, nobody thought we would ever use these strings for anything else than creating symlinks. :)

for things like ID_SERIAL this makes sense to me. For ID_VENDOR and ID_MODEL not so much. Does udev itself use these values anywhere?

I don't think the usb_id keys are used, but the same key names are used directly from ata_id and scsi_id.

Quoted 3 lines

Or can
we have udev just do the stripping part and have *_id tools return the plain values?

We need to sanitize some chars in any case, and the question is how far you go here, do we allow $, backticks, backslash, quotes, and such things? It get's pretty difficult how to decide what "plaintext" is in that context.

All the values are from completely untrusted sources. Everybody can put any string in a fake USB device, and we would copy these strings in the environment of processes/shell scripts running as root. That's why we need to be very careful here.

Quoted 19 lines
Quoted 11 lines

Some of the values, like ATA and SCSI just fill the whole remaining string buffer with whitespaces, which need to be stripped too, to be used in symlinks.

For stuff that needs to be reversible, like filesystem label strings, which can contain any char, need to be valid and safe chars to be a symlink, and we need to be able to translate the name back to the original value, we encode the string with url encoding, like:
ID_FS_LABEL=/
ID_FS_LABEL_ENC=\x2f

Quoted 7 lines

We need to sanitize the values at least for things like newline, quoting and other control chars, because most of these values are completely "untrusted userdata", and a fake device with a usb model string like "Foo\nBAR=1" we don't want to import unmangled. :)

If you have an idea what we should do/change to make these values more useful, let me know.

Quoted 6 lines

I agree that we need to do at least some kind of sanitization, but for a lot of these values having the clear text strings available would be really nice. Especially the ID_VENDOR and ID_MODEL strings. If udev is having access to these string (like for USB or when creating unique symlinks) anyway, then it makes no sense to not duplicate the logic to these from the device.

Yeah, but as mentioned, we need to be careful and will need to mangle quoting and newlines at least. Some vendor values are known to contain single quotes, which we probably should not copy unmangled to an environment key.

Quoted 2 lines

Do you ever defined a character set for the environment values? It would be nice if it UTF-8, because then we can copy most values natively.

We don't do any transcoding or anything else here, we allow plain ascii [a-zA-Z0-9] and "#+-.:=@_" and also valid utf8 to pass unmangled, everything else gets replaced or encoded.

Should we add encoded versions of these values, to be safe? Like ID_VENDOR_ENC and ID_VENDOR_MODEL_ENC? The consumer of these strings would need to translate "%xx" back to the char value, like we do for the filesystem labels, and free-text uuids today.

Kay