Skip to content

Commit

Permalink
MD: Prevent sysfs operations on uninitialized kobjects
Browse files Browse the repository at this point in the history
MD: Prevent sysfs operations on uninitialized kobjects

Device-mapper does not use sysfs; but when device-mapper is leveraging
MD's RAID personalities, MD sometimes attempts to update sysfs.  This
patch adds checks for 'mddev-kobj.sd' in sysfs_[un]link_rdev to ensure
it is about to operate on something valid.  This patch also checks for
'mddev->kobj.sd' before calling 'sysfs_notify' in 'remove_and_add_spares'.
Although 'sysfs_notify' already makes this check, doing so in
'remove_and_add_spares' prevents an additional mutex operation.

Signed-off-by: Jonathan Brassow <[email protected]>
Signed-off-by: NeilBrown <[email protected]>
  • Loading branch information
jbrassow authored and neilbrown committed Mar 20, 2013
1 parent e3620a3 commit 90584fc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
6 changes: 2 additions & 4 deletions drivers/md/md.c
Original file line number Diff line number Diff line change
Expand Up @@ -7663,10 +7663,8 @@ static int remove_and_add_spares(struct mddev *mddev)
removed++;
}
}
if (removed)
sysfs_notify(&mddev->kobj, NULL,
"degraded");

if (removed && mddev->kobj.sd)
sysfs_notify(&mddev->kobj, NULL, "degraded");

rdev_for_each(rdev, mddev) {
if (rdev->raid_disk >= 0 &&
Expand Down
4 changes: 2 additions & 2 deletions drivers/md/md.h
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ static inline char * mdname (struct mddev * mddev)
static inline int sysfs_link_rdev(struct mddev *mddev, struct md_rdev *rdev)
{
char nm[20];
if (!test_bit(Replacement, &rdev->flags)) {
if (!test_bit(Replacement, &rdev->flags) && mddev->kobj.sd) {
sprintf(nm, "rd%d", rdev->raid_disk);
return sysfs_create_link(&mddev->kobj, &rdev->kobj, nm);
} else
Expand All @@ -516,7 +516,7 @@ static inline int sysfs_link_rdev(struct mddev *mddev, struct md_rdev *rdev)
static inline void sysfs_unlink_rdev(struct mddev *mddev, struct md_rdev *rdev)
{
char nm[20];
if (!test_bit(Replacement, &rdev->flags)) {
if (!test_bit(Replacement, &rdev->flags) && mddev->kobj.sd) {
sprintf(nm, "rd%d", rdev->raid_disk);
sysfs_remove_link(&mddev->kobj, nm);
}
Expand Down

0 comments on commit 90584fc

Please sign in to comment.