diff mbox series

[v8,10/10] integrity: support EC-RDSA signatures for asymmetric_verify

Message ID 20190326125842.24110-11-vt@altlinux.org (mailing list archive)
State New, archived
Headers show
Series crypto: add EC-RDSA (GOST 34.10) algorithm | expand

Commit Message

Vitaly Chikunov March 26, 2019, 12:58 p.m. UTC
Allow to use EC-RDSA signatures for IMA by determining signature type by
the hash algorithm name. This works good for EC-RDSA since Streebog and
EC-RDSA should always be used together.

Cc: Mimi Zohar <zohar@linux.ibm.com>
Cc: Dmitry Kasatkin <dmitry.kasatkin@gmail.com>
Cc: linux-integrity@vger.kernel.org
Signed-off-by: Vitaly Chikunov <vt@altlinux.org>
---
 security/integrity/digsig_asymmetric.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

Comments

Mimi Zohar March 27, 2019, 6:10 p.m. UTC | #1
On Tue, 2019-03-26 at 15:58 +0300, Vitaly Chikunov wrote:
> Allow to use EC-RDSA signatures for IMA by determining signature type by
> the hash algorithm name. This works good for EC-RDSA since Streebog and
> EC-RDSA should always be used together.
> 
> Cc: Mimi Zohar <zohar@linux.ibm.com>
> Cc: Dmitry Kasatkin <dmitry.kasatkin@gmail.com>
> Cc: linux-integrity@vger.kernel.org
> Signed-off-by: Vitaly Chikunov <vt@altlinux.org>
> ---
>  security/integrity/digsig_asymmetric.c | 11 +++++++++--
>  1 file changed, 9 insertions(+), 2 deletions(-)
> 
> diff --git a/security/integrity/digsig_asymmetric.c b/security/integrity/digsig_asymmetric.c
> index d775e03fbbcc..99080871eb9f 100644
> --- a/security/integrity/digsig_asymmetric.c
> +++ b/security/integrity/digsig_asymmetric.c
> @@ -104,9 +104,16 @@ int asymmetric_verify(struct key *keyring, const char *sig,
>  
>  	memset(&pks, 0, sizeof(pks));
>  
> -	pks.pkey_algo = "rsa";
>  	pks.hash_algo = hash_algo_name[hdr->hash_algo];
> -	pks.encoding = "pkcs1";
> +	if (hdr->hash_algo == HASH_ALGO_STREEBOG_256 ||
> +	    hdr->hash_algo == HASH_ALGO_STREEBOG_512) {
> +		/* EC-RDSA and Streebog should go together. */
> +		pks.pkey_algo = "ecrdsa";
> +		pks.encoding = "raw";

IMA signatures are stored as xattrs, making them persistent.  Support
for streebog was upstreamed in linux-5.0.  This change would break
existing systems using streebog.  As long as this is not yet a concern

Reviewed-by:  Mimi Zohar <zohar@linux.ibm.com>

> +	} else {
> +		pks.pkey_algo = "rsa";
> +		pks.encoding = "pkcs1";
> +	}
>  	pks.digest = (u8 *)data;
>  	pks.digest_size = datalen;
>  	pks.s = hdr->sig;
Vitaly Chikunov March 27, 2019, 8:14 p.m. UTC | #2
On Wed, Mar 27, 2019 at 02:10:20PM -0400, Mimi Zohar wrote:
> On Tue, 2019-03-26 at 15:58 +0300, Vitaly Chikunov wrote:
> > Allow to use EC-RDSA signatures for IMA by determining signature type by
> > the hash algorithm name. This works good for EC-RDSA since Streebog and
> > EC-RDSA should always be used together.
> > 
> > Cc: Mimi Zohar <zohar@linux.ibm.com>
> > Cc: Dmitry Kasatkin <dmitry.kasatkin@gmail.com>
> > Cc: linux-integrity@vger.kernel.org
> > Signed-off-by: Vitaly Chikunov <vt@altlinux.org>
> > ---
> >  security/integrity/digsig_asymmetric.c | 11 +++++++++--
> >  1 file changed, 9 insertions(+), 2 deletions(-)
> > 
> > diff --git a/security/integrity/digsig_asymmetric.c b/security/integrity/digsig_asymmetric.c
> > index d775e03fbbcc..99080871eb9f 100644
> > --- a/security/integrity/digsig_asymmetric.c
> > +++ b/security/integrity/digsig_asymmetric.c
> > @@ -104,9 +104,16 @@ int asymmetric_verify(struct key *keyring, const char *sig,
> >  
> >  	memset(&pks, 0, sizeof(pks));
> >  
> > -	pks.pkey_algo = "rsa";
> >  	pks.hash_algo = hash_algo_name[hdr->hash_algo];
> > -	pks.encoding = "pkcs1";
> > +	if (hdr->hash_algo == HASH_ALGO_STREEBOG_256 ||
> > +	    hdr->hash_algo == HASH_ALGO_STREEBOG_512) {
> > +		/* EC-RDSA and Streebog should go together. */
> > +		pks.pkey_algo = "ecrdsa";
> > +		pks.encoding = "raw";
> 
> IMA signatures are stored as xattrs, making them persistent.  Support
> for streebog was upstreamed in linux-5.0.  This change would break
> existing systems using streebog.  As long as this is not yet a concern

In what sense it would break systems?

Unless kernel crashes or signature is recognized as valid, I think, it should
not be called a break.

> Reviewed-by:  Mimi Zohar <zohar@linux.ibm.com>

Thanks!

> 
> > +	} else {
> > +		pks.pkey_algo = "rsa";
> > +		pks.encoding = "pkcs1";
> > +	}
> >  	pks.digest = (u8 *)data;
> >  	pks.digest_size = datalen;
> >  	pks.s = hdr->sig;
Mimi Zohar March 27, 2019, 8:21 p.m. UTC | #3
> > diff --git a/security/integrity/digsig_asymmetric.c
b/security/integrity/digsig_asymmetric.c
> > > index d775e03fbbcc..99080871eb9f 100644
> > > --- a/security/integrity/digsig_asymmetric.c
> > > +++ b/security/integrity/digsig_asymmetric.c
> > > @@ -104,9 +104,16 @@ int asymmetric_verify(struct key *keyring, const char *sig,
> > >  
> > >  	memset(&pks, 0, sizeof(pks));
> > >  
> > > -	pks.pkey_algo = "rsa";
> > >  	pks.hash_algo = hash_algo_name[hdr->hash_algo];
> > > -	pks.encoding = "pkcs1";
> > > +	if (hdr->hash_algo == HASH_ALGO_STREEBOG_256 ||
> > > +	    hdr->hash_algo == HASH_ALGO_STREEBOG_512) {
> > > +		/* EC-RDSA and Streebog should go together. */
> > > +		pks.pkey_algo = "ecrdsa";
> > > +		pks.encoding = "raw";
> > 
> > IMA signatures are stored as xattrs, making them persistent.  Support
> > for streebog was upstreamed in linux-5.0.  This change would break
> > existing systems using streebog.  As long as this is not yet a concern
> 
> In what sense it would break systems?

For example, if executable files are currently labeled with
rsa/streebog signatures, then enforcing file data integrity I assume
would break if the kernel uses ecrdsa/streebog.

Mimi

> 
> Unless kernel crashes or signature is recognized as valid, I think, it should
> not be called a break.
> 
> > Reviewed-by:  Mimi Zohar <zohar@linux.ibm.com>
> 
> Thanks!
> 
> > 
> > > +	} else {
> > > +		pks.pkey_algo = "rsa";
> > > +		pks.encoding = "pkcs1";
> > > +	}
> > >  	pks.digest = (u8 *)data;
> > >  	pks.digest_size = datalen;
> > >  	pks.s = hdr->sig;
>
Vitaly Chikunov March 28, 2019, 6:16 a.m. UTC | #4
On Wed, Mar 27, 2019 at 04:21:07PM -0400, Mimi Zohar wrote:
> > > diff --git a/security/integrity/digsig_asymmetric.c
> b/security/integrity/digsig_asymmetric.c
> > > > index d775e03fbbcc..99080871eb9f 100644
> > > > --- a/security/integrity/digsig_asymmetric.c
> > > > +++ b/security/integrity/digsig_asymmetric.c
> > > > @@ -104,9 +104,16 @@ int asymmetric_verify(struct key *keyring, const char *sig,
> > > >  
> > > >  	memset(&pks, 0, sizeof(pks));
> > > >  
> > > > -	pks.pkey_algo = "rsa";
> > > >  	pks.hash_algo = hash_algo_name[hdr->hash_algo];
> > > > -	pks.encoding = "pkcs1";
> > > > +	if (hdr->hash_algo == HASH_ALGO_STREEBOG_256 ||
> > > > +	    hdr->hash_algo == HASH_ALGO_STREEBOG_512) {
> > > > +		/* EC-RDSA and Streebog should go together. */
> > > > +		pks.pkey_algo = "ecrdsa";
> > > > +		pks.encoding = "raw";
> > > 
> > > IMA signatures are stored as xattrs, making them persistent.  Support
> > > for streebog was upstreamed in linux-5.0.  This change would break
> > > existing systems using streebog.  As long as this is not yet a concern
> > 
> > In what sense it would break systems?
> 
> For example, if executable files are currently labeled with
> rsa/streebog signatures, then enforcing file data integrity I assume
> would break if the kernel uses ecrdsa/streebog.

Ah. No, I did not implement RSA(Streebog) intentionally, since Streebog is
not in the list of permitted hashes for PKCS1. You may notice this by the
lack of appropriate rsa_asn1_template[] entry.

Thanks,

> 
> Mimi
> 
> > 
> > Unless kernel crashes or signature is recognized as valid, I think, it should
> > not be called a break.
> > 
> > > Reviewed-by:  Mimi Zohar <zohar@linux.ibm.com>
> > 
> > Thanks!
> > 
> > > 
> > > > +	} else {
> > > > +		pks.pkey_algo = "rsa";
> > > > +		pks.encoding = "pkcs1";
> > > > +	}
> > > >  	pks.digest = (u8 *)data;
> > > >  	pks.digest_size = datalen;
> > > >  	pks.s = hdr->sig;
> >
diff mbox series

Patch

diff --git a/security/integrity/digsig_asymmetric.c b/security/integrity/digsig_asymmetric.c
index d775e03fbbcc..99080871eb9f 100644
--- a/security/integrity/digsig_asymmetric.c
+++ b/security/integrity/digsig_asymmetric.c
@@ -104,9 +104,16 @@  int asymmetric_verify(struct key *keyring, const char *sig,
 
 	memset(&pks, 0, sizeof(pks));
 
-	pks.pkey_algo = "rsa";
 	pks.hash_algo = hash_algo_name[hdr->hash_algo];
-	pks.encoding = "pkcs1";
+	if (hdr->hash_algo == HASH_ALGO_STREEBOG_256 ||
+	    hdr->hash_algo == HASH_ALGO_STREEBOG_512) {
+		/* EC-RDSA and Streebog should go together. */
+		pks.pkey_algo = "ecrdsa";
+		pks.encoding = "raw";
+	} else {
+		pks.pkey_algo = "rsa";
+		pks.encoding = "pkcs1";
+	}
 	pks.digest = (u8 *)data;
 	pks.digest_size = datalen;
 	pks.s = hdr->sig;