dm-table: Check that a dm device doesn't reference itself
Benjamin Marzinski
maintainerPATCH 1/1 dm-table: Check that a dm device doesn't reference itself
If a dm device table references itself, it will crash the kernel with an infinite recursion. Check for a self-reference in dm_get_device(). This is a quick check, but it won't catch more complicated circular references.
--- drivers/md/dm-table.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/md/dm-table.c +2 -0
@@ -364,6 +364,8 @@ int dm_get_device(struct dm_target *ti, const char *path, fmode_t mode,if (!dev)return -ENODEV ; } +if (dev ==disk_devt (t->md->disk)) +return -EINVAL ; dd =find_device (&t->devices, dev);if (!dd) {
Signature · 6 lines
2.30.2 -- dm-devel mailing list [email protected] https://listman.redhat.com/mailman/listinfo/dm-devel
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512
Quoted 25 lines · Benjamin Marzinski
If a dm device table references itself, it will crash the kernel with an infinite recursion. Check for a self-reference in
dm_get_device(). This is a quick check, but it won't catch more complicated circular references.Signed-off-by Benjamin Marzinski <[email protected]>--- drivers/md/dm-table.c | 2 ++ 1 file changed, 2 insertions(+)drivers/md/dm-table.c +2
-0@@ -364,6 +364,8 @@ int dm_get_device(struct dm_target *ti, const char *path, fmode_t mode,if (!dev)return -ENODEV ; } +if (dev ==disk_devt (t->md->disk)) +return -EINVAL ; dd =find_device (&t->devices, dev);if (!dd) {Signature · 1 line
2.30.2
I like this! More generally, should the kernel fail with -ELOOP if devices are stacked too deeply?
- --
Sincerely,
Demi Marie Obenour (she/her/hers)
Invisible Things Lab
-----BEGIN PGP SIGNATURE-----
iQIzBAEBCgAdFiEEdodNnxM2uiJZBxxxsoi1X/+cIsEFAmPjJhYACgkQsoi1X/+c IsHwnRAAsJgax1pLhHw0jvXgbwb+XGM+j2bHwg/9DsmTakxAlJgDYAUGhC4wIu3n bWzs0TY0ON0h6BAVm4+xUFBCpQpSZTf2Z95YCHHvhj2ImEdSYrbk+ccnZaXhaP5f mUFEG7PmBA6Zl/xJvAwZgG4V/Szp73UdlSe+Ph3qcjNf/+n2EznZBFjXpO45PGaL xvd7D7QcqEbhiH5kDVvZibX4Np2xWecbIYNoGuiCf+tnUVM+QyFIMiLZhWS+nZ4y QOzcn7gG5543dSlwnKJJXKmW/LBXqNAzyLvhqxWX/5ExwENQxEQ5fQ/w1EcuIgLq EaNCm7yCabgG11d6En4er2etUB9Q2mowugSvdzryblF01x0GMz2aqFQ12Ogbag9t 8t1sHx+ohk03H4vjbT3NJZnqDsTmAYVV7v/nxCKYot3EcylB0R9b3BIeRoKYiFK0 f/1ap8MfvHE/Nc4hyVapD6DOQ3Gn9ZK5Y6eNrpzlG6C5JVjWJjB8tCoON8upgj3t 5P77sFVVczj2/Uu8T+1uhYQ9XSnFREsQGSEULZoA60MAwRktyhQVGTMwTLnX/BVg kHpCeaFnEN1IZ1R5PFZXoPPztPcnZG1ZjMjrpqjKqd1Udokqti+i9vf3sAI7mfo3 mvB4XyxH6PdLz2UD1GvTvF2DKKyJeE2W4ezCxSBSNHhrMIwaPvE= =Kzsf
-----END PGP SIGNATURE-----
--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel