From: NeilBrown <neilb@suse.de>
To: Jonathan Brassow <jbrassow@redhat.com>
Cc: linux-raid@vger.kernel.org
Subject: Re: [PATCH] MD: Prevent sysfs operations on uninitialized kobjects
Date: Mon, 11 Mar 2013 11:35:22 +1100 [thread overview]
Message-ID: <20130311113522.71dd6435@notabene.brown> (raw)
In-Reply-To: <1362695066.28152.7.camel@f16>
[-- Attachment #1: Type: text/plain, Size: 2278 bytes --]
On Thu, 07 Mar 2013 16:24:26 -0600 Jonathan Brassow <jbrassow@redhat.com>
wrote:
> 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 <jbrassow@redhat.com>
>
> Index: linux-upstream/drivers/md/md.h
> ===================================================================
> --- linux-upstream.orig/drivers/md/md.h
> +++ linux-upstream/drivers/md/md.h
> @@ -506,7 +506,7 @@ static inline char * mdname (struct mdde
> 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
> @@ -516,7 +516,7 @@ static inline int sysfs_link_rdev(struct
> 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);
> }
> Index: linux-upstream/drivers/md/md.c
> ===================================================================
> --- linux-upstream.orig/drivers/md/md.c
> +++ linux-upstream/drivers/md/md.c
> @@ -7646,10 +7646,8 @@ static int remove_and_add_spares(struct
> 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 &&
>
Applied, thanks.
NeilBrown
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 828 bytes --]
prev parent reply other threads:[~2013-03-11 0:35 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-07 22:24 [PATCH] MD: Prevent sysfs operations on uninitialized kobjects Jonathan Brassow
2013-03-11 0:35 ` NeilBrown [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130311113522.71dd6435@notabene.brown \
--to=neilb@suse.de \
--cc=jbrassow@redhat.com \
--cc=linux-raid@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.