* [PATCH] dm-crypt: fix incorrect use of strcmp when telling if there is no key
@ 2022-11-07 12:22 ` Coiby Xu
0 siblings, 0 replies; 4+ messages in thread
From: Coiby Xu @ 2022-11-07 12:22 UTC (permalink / raw)
To: dm-devel; +Cc: Alasdair Kergon, Mike Snitzer, Milan Broz, open list
strcmp returns 0 when two strings are equal.
Fixes: 69a8cfcda210 ("dm crypt: set key size early")
Signed-off-by: Coiby Xu <coxu@redhat.com>
---
drivers/md/dm-crypt.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c
index 159c6806c19b..cfefe0f18150 100644
--- a/drivers/md/dm-crypt.c
+++ b/drivers/md/dm-crypt.c
@@ -2590,7 +2590,7 @@ static int crypt_set_key(struct crypt_config *cc, char *key)
int key_string_len = strlen(key);
/* Hyphen (which gives a key_size of zero) means there is no key. */
- if (!cc->key_size && strcmp(key, "-"))
+ if (!cc->key_size && !strcmp(key, "-"))
goto out;
/* ':' means the key is in kernel keyring, short-circuit normal key processing */
--
2.38.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [dm-devel] [PATCH] dm-crypt: fix incorrect use of strcmp when telling if there is no key
@ 2022-11-07 12:22 ` Coiby Xu
0 siblings, 0 replies; 4+ messages in thread
From: Coiby Xu @ 2022-11-07 12:22 UTC (permalink / raw)
To: dm-devel; +Cc: Mike Snitzer, open list, Alasdair Kergon, Milan Broz
strcmp returns 0 when two strings are equal.
Fixes: 69a8cfcda210 ("dm crypt: set key size early")
Signed-off-by: Coiby Xu <coxu@redhat.com>
---
drivers/md/dm-crypt.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c
index 159c6806c19b..cfefe0f18150 100644
--- a/drivers/md/dm-crypt.c
+++ b/drivers/md/dm-crypt.c
@@ -2590,7 +2590,7 @@ static int crypt_set_key(struct crypt_config *cc, char *key)
int key_string_len = strlen(key);
/* Hyphen (which gives a key_size of zero) means there is no key. */
- if (!cc->key_size && strcmp(key, "-"))
+ if (!cc->key_size && !strcmp(key, "-"))
goto out;
/* ':' means the key is in kernel keyring, short-circuit normal key processing */
--
2.38.1
--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [dm-devel] [PATCH] dm-crypt: fix incorrect use of strcmp when telling if there is no key
2022-11-07 12:22 ` [dm-devel] " Coiby Xu
@ 2022-11-08 14:51 ` Milan Broz
-1 siblings, 0 replies; 4+ messages in thread
From: Milan Broz @ 2022-11-08 14:51 UTC (permalink / raw)
To: Coiby Xu, dm-devel; +Cc: Mike Snitzer, open list, Alasdair Kergon
On 11/7/22 13:22, Coiby Xu wrote:
> strcmp returns 0 when two strings are equal.
>
> Fixes: 69a8cfcda210 ("dm crypt: set key size early")
> Signed-off-by: Coiby Xu <coxu@redhat.com>
> ---
> drivers/md/dm-crypt.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c
> index 159c6806c19b..cfefe0f18150 100644
> --- a/drivers/md/dm-crypt.c
> +++ b/drivers/md/dm-crypt.c
> @@ -2590,7 +2590,7 @@ static int crypt_set_key(struct crypt_config *cc, char *key)
> int key_string_len = strlen(key);
>
> /* Hyphen (which gives a key_size of zero) means there is no key. */
> - if (!cc->key_size && strcmp(key, "-"))
> + if (!cc->key_size && !strcmp(key, "-"))
> goto out;
NACK. The code is correct.
The comment is a little bit misleading - it actually says that "-" is valid here.
If key_size is 0 (see above: key_size = strlen(key) >> 1;) and key
is NOT "-" (empty key) return error.
Key "-" is a valid key, means no key used (used for null cipher).
Try this with and without your patch (it uses null cipher that takes no key):
dmsetup create test --table "0 8 crypt cipher_null-ecb - 0 /dev/sdb 0"
With your patch it no longer works.
Please, run cryptsetup testsuite before sending patches, tests/mode-tests fails
immediately with your patch!
Thanks,
Milan
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [dm-devel] [PATCH] dm-crypt: fix incorrect use of strcmp when telling if there is no key
@ 2022-11-08 14:51 ` Milan Broz
0 siblings, 0 replies; 4+ messages in thread
From: Milan Broz @ 2022-11-08 14:51 UTC (permalink / raw)
To: Coiby Xu, dm-devel; +Cc: Mike Snitzer, open list, Alasdair Kergon
On 11/7/22 13:22, Coiby Xu wrote:
> strcmp returns 0 when two strings are equal.
>
> Fixes: 69a8cfcda210 ("dm crypt: set key size early")
> Signed-off-by: Coiby Xu <coxu@redhat.com>
> ---
> drivers/md/dm-crypt.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c
> index 159c6806c19b..cfefe0f18150 100644
> --- a/drivers/md/dm-crypt.c
> +++ b/drivers/md/dm-crypt.c
> @@ -2590,7 +2590,7 @@ static int crypt_set_key(struct crypt_config *cc, char *key)
> int key_string_len = strlen(key);
>
> /* Hyphen (which gives a key_size of zero) means there is no key. */
> - if (!cc->key_size && strcmp(key, "-"))
> + if (!cc->key_size && !strcmp(key, "-"))
> goto out;
NACK. The code is correct.
The comment is a little bit misleading - it actually says that "-" is valid here.
If key_size is 0 (see above: key_size = strlen(key) >> 1;) and key
is NOT "-" (empty key) return error.
Key "-" is a valid key, means no key used (used for null cipher).
Try this with and without your patch (it uses null cipher that takes no key):
dmsetup create test --table "0 8 crypt cipher_null-ecb - 0 /dev/sdb 0"
With your patch it no longer works.
Please, run cryptsetup testsuite before sending patches, tests/mode-tests fails
immediately with your patch!
Thanks,
Milan
--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-11-08 14:52 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-07 12:22 [PATCH] dm-crypt: fix incorrect use of strcmp when telling if there is no key Coiby Xu
2022-11-07 12:22 ` [dm-devel] " Coiby Xu
2022-11-08 14:51 ` Milan Broz
2022-11-08 14:51 ` Milan Broz
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.