multipathd: verify udev WWIDs with the device before moving paths
v2 cover multipathd: verify udev WWIDs with the device before moving paths
During an array controller failover on an iSCSI host, multipathd briefly put a path to one LUN into the map of another LUN, and I/O meant for the first LUN landed on the second. The host ran RHEL 9 device-mapper-multipath 0.8.7, but the code involved is essentially unchanged in master. See the v1 cover letter for the full sequence.
Changes in v2, after Ben's review:
- ev_add_path() no longer double-checks the WWID on every add. Ben was concerned about adding a check to perfectly normal adds, since a SCSI device can report several identifiers in VPD 0x83 and multipath's SG_IO code has to pick the same one udev does.
The need_do_map argument of uev_add_path() and ev_add_path() is now enum path_add_mode, with a new PATH_ADD_REINIT value. It behaves like PATH_ADD_MAP, and is passed only when a path is re-added from uev_update_path(): after udev reported a changed WWID, or after udev data was missing at first. Only then is the WWID checked against the device. Ordinary adds never run the SG_IO check.
- The uev_update_path() check is unchanged. It only runs when the WWID from udev differs from the cached one, and falls back to the old behavior if the device doesn't confirm the cached WWID.
About how likely this is: we hit it because a test tool was opening and closing the sd devices read-write many times a second, and with udev's "watch" rule every close generates a change uevent that runs scsi_id against the device. That is far more udev traffic than a normal host generates, so we expect the window to be rare in practice. We don't know why the bad WWID was reported; the array may have answered the INQUIRY wrongly during the takeover, or the bad value may have arisen elsewhere in the udev path. What the patch does is stop multipathd from acting on a changed WWID without confirming it, since the result of acting on a wrong one is data going to the wrong LUN.
Open points, as in v1:
- If the SG_IO read fails, behavior is unchanged. Refusing the add in that case would be stricter; opinions welcome.
- "multipathd reconfigure" builds maps through configure(), not ev_add_path(), so it isn't covered.
Brian Bunker (1):
multipathd: verify udev WWIDs with the device before moving paths
multipathd/cli_handlers.c | 2 +- multipathd/main.c | 79 +++++++++++++++++++++++++++++++-------- multipathd/main.h | 12 +++++- 3 files changed, 76 insertions(+), 17 deletions(-)
Signature · 1 line
2.56.0
PATCH v2 1/1 multipathd: verify udev WWIDs with the device before moving paths
multipathd takes a path's WWID from udev. When a change uevent reports a different WWID, uev_update_path() removes the path from its map and re-adds it through uev_add_path(), which places it in whatever map owns the new WWID. Nothing checks the new value against the device itself; recheck_wwid only covers paths coming back up in the checker and "multipathd add path". If udev reports the wrong WWID, or the uevent is stale by the time it is processed, the path goes into the map of a different LUN and I/O for one LUN is silently sent to another.
Use SG_IO to read VPD page 0x83 from the device in two places, for paths where can_recheck_wwid() is true:
- In uev_update_path(), if the device still reports the cached WWID, ignore the udev value and leave the path where it is.
- In ev_add_path(), when a path is being re-added because its udev data was missing or changed, refuse to add it if the device doesn't confirm its WWID. The path is orphaned, its WWID is cleared and it is marked INIT_MISSING_UDEV, so the checker retriggers udev (bounded by retrigger_tries) and the path is re-added from fresh data.
To tell re-adds from ordinary adds, turn the need_do_map argument of uev_add_path() and ev_add_path() into enum path_add_mode, with a new PATH_ADD_REINIT value that behaves like PATH_ADD_MAP and also requests the WWID check. Ordinary adds are unchanged and never read the WWID from the device.
If the SG_IO read fails, behavior is unchanged.
Split the SG_IO read out of check_path_wwid_change() into get_sgio_wwid() so all the checks share it.
--- multipathd/cli_handlers.c | 2 +- multipathd/main.c | 79 +++++++++++++++++++++++++++++++-------- multipathd/main.h | 12 +++++- 3 files changed, 76 insertions(+), 17 deletions(-)
multipathd/cli_handlers.c +1 -1
@@ -673,7 +673,7 @@ cli_add_path (void *v, struct strbuf *reply, void *data)return 1 ; } } -return ev_add_path (pp, vecs,1 ); +return ev_add_path (pp, vecs,PATH_ADD_MAP ); blacklisted:append_strbuf_str (reply,"blacklisted\n" );condlog (2 ,"%s: path blacklisted" , param);
multipathd/main.c +64 -15
171 lines not on this page · raw message
multipathd/main.h +11 -1
@@ -36,7 +36,17 @@ enum daemon_status wait_for_state_change_if(enum daemon_status oldstate, unsigned long ms);void schedule_reconfigure (enum force_reload_types requested_type);int need_to_delay_reconfig (struct vectors *); -int ev_add_path (struct path *,struct vectors *,int ); +/* +* PATH_ADD_REINIT is PATH_ADD_MAP for a path that is being re-added +* because its udev data was missing or changed. Its WWID is verified +* with the device before the path is put into a map. +*/ +enum path_add_mode { +PATH_ADD_NO_MAP , +PATH_ADD_MAP , +PATH_ADD_REINIT , +}; +int ev_add_path (struct path *,struct vectors *,enum path_add_mode );int ev_remove_path (struct path *,struct vectors *,int );int ev_add_map (char *,const char *,struct vectors *);int flush_map (struct multipath *,struct vectors *);
Signature · 1 line
2.56.0
Quoted 27 lines · Brian Bunker
multipathd takes a path's WWID from udev. When a change uevent reports a different WWID,
uev_update_path()removes the path from its map and re-adds it throughuev_add_path(), which places it in whatever map owns the new WWID. Nothing checks the new value against the device itself;recheck_wwidonly covers paths coming back up in the checker and "multipathd add path". If udev reports the wrong WWID, or the uevent is stale by the time it is processed, the path goes into the map of a different LUN and I/O for one LUN is silently sent to another.Use
SG_IOto read VPD page0x83from the device in two places, for paths wherecan_recheck_wwid()is true:- In
uev_update_path(), if the device still reports the cached WWID, ignore the udev value and leave the path where it is.- In
ev_add_path(), when a path is being re-added because its udev data was missing or changed, refuse to add it if the device doesn't confirm its WWID. The path is orphaned, its WWID is cleared and it is markedINIT_MISSING_UDEV, so the checker retriggers udev (bounded byretrigger_tries) and the path is re-added from fresh data.To tell re-adds from ordinary adds, turn the
need_do_mapargument ofuev_add_path()andev_add_path()into enumpath_add_mode, with a newPATH_ADD_REINITvalue that behaves likePATH_ADD_MAPand also requests the WWID check. Ordinary adds are unchanged and never read the WWID from the device.
Quoted 6 lines
If the
SG_IOread fails, behavior is unchanged.Split the
SG_IOread out ofcheck_path_wwid_change()intoget_sgio_wwid()so all the checks share it.Signed-off-by Brian Bunker <[email protected]>
Quoted 40 lines · Benjamin Marzinski
Quoted 39 lines · Brian Bunker
multipathd takes a path's WWID from udev. When a change uevent reports
a different WWID,uev_update_path()removes the path from its map and
re-adds it throughuev_add_path(), which places it in whatever map owns
the new WWID. Nothing checks the new value against the device itself;recheck_wwidonly covers paths coming back up in the checker and "multipathd add path". If udev reports the wrong WWID, or the uevent is
stale by the time it is processed, the path goes into the map of a different LUN and I/O for one LUN is silently sent to another.Use
SG_IOto read VPD page0x83from the device in two places, for paths wherecan_recheck_wwid()is true:- In
uev_update_path(), if the device still reports the cached WWID,
ignore the udev value and leave the path where it is.- In
ev_add_path(), when a path is being re-added because its udev data was missing or changed, refuse to add it if the device doesn't
confirm its WWID. The path is orphaned, its WWID is cleared and it
is markedINIT_MISSING_UDEV, so the checker retriggers udev (bounded
byretrigger_tries) and the path is re-added from fresh data.To tell re-adds from ordinary adds, turn the
need_do_mapargument ofuev_add_path()andev_add_path()into enumpath_add_mode, with a newPATH_ADD_REINITvalue that behaves likePATH_ADD_MAPand also requests
the WWID check. Ordinary adds are unchanged and never read the WWID from the device.
Quoted 7 lines
Quoted 6 lines
If the
SG_IOread fails, behavior is unchanged.Split the
SG_IOread out ofcheck_path_wwid_change()intoget_sgio_wwid()so all the checks share it.Signed-off-by Brian Bunker <[email protected]>Reviewed-by Benjamin Marzinski <[email protected]>
You will need convince me that this doesn't do more harm than good. We can't just use udev in one place and other methods elsewhere.
I am open for a general redesign that uses sysfs for retrieving WWIDs, rather than udev. But using SG_IO seems wrong to me in general, because it can hang. If anything, we'd need to make this configurable, and we'd then need to use SG_IO consistently throughout the code (and SG_IO has significant disadvantages, as already mentioned). Also, SG_IO works for SCSI only. That may be a minor issue these days, because almost all disks handled by dm-multipath are SCSI disks, but at least formally we still support other block devices like NVMe and DASD.
Unfortunately there's already a zoo of options for WWID detection which has grown over time.
Quoted 4 lines
About how likely this is: we hit it because a test tool was opening and closing the sd devices read-write many times a second, and with udev's "watch" rule every close generates a change uevent that runs
scsi_idagainst the device.
I wouldn't call this a valid test. It's a deliberate abuse of udev functionality. If you do this, you need to disable udev's watch functionality, which is merely a convenience for users anyway. It's questionable if it's a useful feature on production servers in general.
Thinking about it, I wonder if we should simply set "nowatch" for multipath members by default. AFAIU that would avoid the issue Brian encountered, at least in this test scenario.
Regards
Martin
Signature · 5 lines
Dr. Martin Wilck <[email protected]> SUSE Software Solutions Germany GmbH, Frankenstr. 146, 90461 Nürnberg, Germany Geschäftsführer: Stefan Gaiser, Jochen Jaser, Abhinav Puri (HRB 36809,AG Nürnberg)
Quoted 6 lines · Martin Wilck
You will need convince me that this doesn't do more harm than good. We can't just use udev in one place and other methods elsewhere.
I am open for a general redesign that uses sysfs for retrieving WWIDs, rather than udev. But using
SG_IOseems wrong to me in general, because it can hang.
Agreed on SG_IO. v3 drops it: the re-add check compares the udev WWID with one built from the VPD page 0x83 data cached in sysfs, using the same get_vpd_uid()/parse_vpd_pg83() code as the existing sysfs fallback in get_uid(). It does no I/O on the device.
On mixing methods, one thing I should have said earlier: on RHEL 9 the udev WWID isn't taken from sysfs. The RHEL sg3_utils package installs 55-scsi-sg3_id.rules as 61-scsi-sg3_id.rules ("need to run after 60-persistent-storage.rules"), so ID_SERIAL comes from "scsi_id --whitelisted", which sends INQUIRY over SG_IO; strace on our host shows it on every run. The bad WWID came from that INQUIRY.
Where the sg3 rules run first, ID_SERIAL is derived from the same sysfs page the check reads, with the same designator selection when everything is at defaults, and can_recheck_wwid() limits the check to that case. So I'd argue it isn't another way of computing the WWID, but a comparison of udev's value with the data it is meant to come from.
I also dropped the uev_update_path() check from v2. With cached data it could keep a path to a really remapped LUN in its old map, which is worse than the problem it was meant to fix.
Quoted 2 lines
I wouldn't call this a valid test. It's a deliberate abuse of udev functionality.
Fair. The tool doing this is ours, and we've changed it to open the devices read-only, which stops the flood of change events in our testing. The reason
I'd still like multipathd to check the re-add is that when it goes wrong, the result is silent data corruption on another LUN, and nothing else in the stack notices.
Quoted 2 lines
Thinking about it, I wonder if we should simply set "nowatch" for multipath members by default.
I think that's worth doing regardless of this patch, and I'm happy to look at it separately.
Brian
Benjamin Marzinski
maintainerQuoted 43 lines · Martin Wilck
Quoted 42 lines · Benjamin Marzinski
Quoted 41 lines · Brian Bunker
multipathd takes a path's WWID from udev. When a change uevent reports
a different WWID,uev_update_path()removes the path from its map and
re-adds it throughuev_add_path(), which places it in whatever map owns
the new WWID. Nothing checks the new value against the device itself;recheck_wwidonly covers paths coming back up in the checker and "multipathd add path". If udev reports the wrong WWID, or the uevent is
stale by the time it is processed, the path goes into the map of a different LUN and I/O for one LUN is silently sent to another.Use
SG_IOto read VPD page0x83from the device in two places, for paths wherecan_recheck_wwid()is true:- In
uev_update_path(), if the device still reports the cached WWID,
ignore the udev value and leave the path where it is.- In
ev_add_path(), when a path is being re-added because its udev data was missing or changed, refuse to add it if the device doesn't
confirm its WWID. The path is orphaned, its WWID is cleared and it
is markedINIT_MISSING_UDEV, so the checker retriggers udev (bounded
byretrigger_tries) and the path is re-added from fresh data.To tell re-adds from ordinary adds, turn the
need_do_mapargument ofuev_add_path()andev_add_path()into enumpath_add_mode, with a newPATH_ADD_REINITvalue that behaves likePATH_ADD_MAPand also requests
the WWID check. Ordinary adds are unchanged and never read the WWID from the device.If the
SG_IOread fails, behavior is unchanged.
Quoted 8 lines
Quoted 5 lines
Quoted 4 lines
Split the
SG_IOread out ofcheck_path_wwid_change()intoget_sgio_wwid()so all the checks share it.Signed-off-by Brian Bunker <[email protected]>Reviewed-by Benjamin Marzinski <[email protected]>You will need convince me that this doesn't do more harm than good. We can't just use udev in one place and other methods elsewhere.
I get your concern, but we already do this when recheck_wwid is set. Perhaps we could also gate this with that config option.
Quoted 17 lines
I am open for a general redesign that uses sysfs for retrieving WWIDs, rather than udev. But using
SG_IOseems wrong to me in general, because it can hang. If anything, we'd need to make this configurable, and we'd then need to useSG_IOconsistently throughout the code (andSG_IOhas significant disadvantages, as already mentioned). Also,SG_IOworks for SCSI only. That may be a minor issue these days, because almost all disks handled by dm-multipath are SCSI disks, but at least formally we still support other block devices like NVMe and DASD.Unfortunately there's already a zoo of options for WWID detection which has grown over time.
Quoted 4 lines
About how likely this is: we hit it because a test tool was opening and closing the sd devices read-write many times a second, and with udev's "watch" rule every close generates a change uevent that runs
scsi_idagainst the device.
Quoted 8 lines
I wouldn't call this a valid test. It's a deliberate abuse of udev functionality. If you do this, you need to disable udev's watch functionality, which is merely a convenience for users anyway. It's questionable if it's a useful feature on production servers in general.
Thinking about it, I wonder if we should simply set "nowatch" for multipath members by default. AFAIU that would avoid the issue Brian encountered, at least in this test scenario.
I can't think of anything wrong with disabling that off the top of my head. Nothing should be directly opening these devices read-write once they are part of a multipath device.
-Ben
Quoted 9 lines
Regards
MartinSignature · 5 lines
Dr. Martin Wilck <[email protected]> SUSE Software Solutions Germany GmbH, Frankenstr. 146, 90461 Nürnberg, Germany Geschäftsführer: Stefan Gaiser, Jochen Jaser, Abhinav Puri (HRB 36809,AG Nürnberg)