mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Markus Elfring <Markus.Elfring@web.de>
To: dm-devel@lists.linux.dev, kernel-janitors@vger.kernel.org,
	Alasdair Kergon <agk@redhat.com>,
	Mike Snitzer <snitzer@kernel.org>,
	Mikulas Patocka <mpatocka@redhat.com>,
	Ondrej Kozina <okozina@redhat.com>,
	Waiman Long <longman@redhat.com>
Cc: LKML <linux-kernel@vger.kernel.org>
Subject: [PATCH 1/2] dm-crypt: Use up_read() together with key_put() only once in crypt_set_keyring_key()
Date: Wed, 18 Sep 2024 16:08:09 +0200	[thread overview]
Message-ID: <ab7f53e6-128b-4c75-8227-b38a10d134b6@web.de> (raw)
In-Reply-To: <68ee5a00-888c-420f-a3a9-a556c19ee6eb@web.de>

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 18 Sep 2024 15:05:29 +0200

The combination of the calls “up_read(&key->sem)” and “key_put(key)”
was immediately used after a return code check for a set_key() call
in this function implementation.
Thus use such a function call pair only once instead directly
before the check.

This issue was transformed by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/md/dm-crypt.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c
index d5533b43054e..dae2fe3cb182 100644
--- a/drivers/md/dm-crypt.c
+++ b/drivers/md/dm-crypt.c
@@ -2621,16 +2621,13 @@ static int crypt_set_keyring_key(struct crypt_config *cc, const char *key_string
 	down_read(&key->sem);

 	ret = set_key(cc, key);
+	up_read(&key->sem);
+	key_put(key);
 	if (ret < 0) {
-		up_read(&key->sem);
-		key_put(key);
 		kfree_sensitive(new_key_string);
 		return ret;
 	}

-	up_read(&key->sem);
-	key_put(key);
-
 	/* clear the flag since following operations may invalidate previously valid key */
 	clear_bit(DM_CRYPT_KEY_VALID, &cc->flags);

--
2.46.0


  reply	other threads:[~2024-09-18 14:08 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-18 14:05 [PATCH 0/2] dm-crypt: Adjustments for crypt_set_keyring_key() Markus Elfring
2024-09-18 14:08 ` Markus Elfring [this message]
2024-09-18 14:10 ` [PATCH 2/2] dm-crypt: Use common error handling code in crypt_set_keyring_key() Markus Elfring
2024-09-18 16:38   ` Mikulas Patocka

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=ab7f53e6-128b-4c75-8227-b38a10d134b6@web.de \
    --to=markus.elfring@web.de \
    --cc=agk@redhat.com \
    --cc=dm-devel@lists.linux.dev \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=longman@redhat.com \
    --cc=mpatocka@redhat.com \
    --cc=okozina@redhat.com \
    --cc=snitzer@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

all inboxes | Powered by JetHome®