linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Lukas Bulwahn <lukas.bulwahn@gmail.com>
To: Shaohua Li <shli@kernel.org>, Neil Brown <neilb@suse.com>,
	Arnd Bergmann <arnd@arndb.de>,
	Himanshu Jha <himanshujha199639@gmail.com>
Cc: clang-built-linux@googlegroups.com, linux-raid@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Lukas Bulwahn <lukas.bulwahn@gmail.com>
Subject: [PATCH] md: properly lock and unlock in rdev_attr_store()
Date: Sun, 28 Apr 2019 12:40:41 +0200	[thread overview]
Message-ID: <20190428104041.11262-1-lukas.bulwahn@gmail.com> (raw)

rdev_attr_store() should lock and unlock mddev->reconfig_mutex in a
balanced way with mddev_lock() and mddev_unlock().

But when rdev->mddev is NULL, rdev_attr_store() would try to unlock
without locking before. Resolve this locking issue..

This locking issue was detected with Clang Thread Safety Analyser:

drivers/md/md.c:3393:3: warning: releasing mutex 'mddev->reconfig_mutex' that was not held [-Wthread-safety-analysis]
                mddev_unlock(mddev);
                ^

This warning was reported after annotating mutex functions and
mddev_lock() and mddev_unlock().

Fixes: 27c529bb8e90 ("md: lock access to rdev attributes properly")
Link: https://groups.google.com/d/topic/clang-built-linux/CvBiiQLB0H4/discussion
Signed-off-by: Lukas Bulwahn <lukas.bulwahn@gmail.com>
---
Arnd, Neil, here a proposal to fix lock and unlocking asymmetry.

I quite sure that if mddev is NULL, it should just return.

I am still puzzled if the return value from mddev_lock() should be really
return by rdev_attr_store() when it is not 0. But that was the behaviour
before, so I will keep it that way.

 drivers/md/md.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/md/md.c b/drivers/md/md.c
index 05ffffb8b769..a9735d8f1e70 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -3384,7 +3384,9 @@ rdev_attr_store(struct kobject *kobj, struct attribute *attr,
 		return -EIO;
 	if (!capable(CAP_SYS_ADMIN))
 		return -EACCES;
-	rv = mddev ? mddev_lock(mddev): -EBUSY;
+	if (!mddev)
+		return -EBUSY;
+	rv = mddev_lock(mddev);
 	if (!rv) {
 		if (rdev->mddev == NULL)
 			rv = -EBUSY;
-- 
2.17.1


             reply	other threads:[~2019-04-28 10:41 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-28 10:40 Lukas Bulwahn [this message]
2019-04-28 19:53 ` [PATCH] md: properly lock and unlock in rdev_attr_store() Song Liu
2019-04-28 22:47 ` NeilBrown
2019-05-06  5:03   ` Lukas Bulwahn

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=20190428104041.11262-1-lukas.bulwahn@gmail.com \
    --to=lukas.bulwahn@gmail.com \
    --cc=arnd@arndb.de \
    --cc=clang-built-linux@googlegroups.com \
    --cc=himanshujha199639@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-raid@vger.kernel.org \
    --cc=neilb@suse.com \
    --cc=shli@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).