Skip to contentSkip to conversation

crypto: user - Fix lookup of algorithms with IV generator

PATCH Superseded Steffen Klassert 2 participants 6 messages Mar 26, 2012 – Mar 29, 2012 Crypto API

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 crypto: user - Fix lookup of algorithms with IV generator

We lookup algorithms with crypto_alg_mod_lookup() when instantiating via crypto_add_alg(). However, algorithms that are wrapped by an IV genearator (e.g. aead or givcipher type algorithms) need special care. The userspace process hangs until it gets a timeout when we use crypto_alg_mod_lookup() to lookup these algorithms. So export the lookup functions for these algorithms and use them when instantiating via crypto_add_alg().

---
 crypto/ablkcipher.c                |    4 +-
 crypto/aead.c                      |    4 +-
 crypto/crypto_user.c               |   71 +++++++++++++++++++++++++++++++++++-
 include/crypto/internal/aead.h     |    2 +
 include/crypto/internal/skcipher.h |    2 +
 5 files changed, 78 insertions(+), 5 deletions(-)
crypto/ablkcipher.c +2 -2
index a0f768c..8d3a056 100644
@@ -613,8 +613,7 @@ out:
 	return err;
 }
 
-static struct crypto_alg *crypto_lookup_skcipher(const char *name, u32 type,
-						 u32 mask)
+struct crypto_alg *crypto_lookup_skcipher(const char *name, u32 type, u32 mask)
 {
 	struct crypto_alg *alg;
 
@@ -652,6 +651,7 @@ static struct crypto_alg *crypto_lookup_skcipher(const char *name, u32 type,
 
 	return ERR_PTR(crypto_givcipher_default(alg, type, mask));
 }
+EXPORT_SYMBOL_GPL(crypto_lookup_skcipher);
 
 int crypto_grab_skcipher(struct crypto_skcipher_spawn *spawn, const char *name,
 			 u32 type, u32 mask)
crypto/aead.c +2 -2
index 04add3d..e4cb351 100644
@@ -470,8 +470,7 @@ out:
 	return err;
 }
 
-static struct crypto_alg *crypto_lookup_aead(const char *name, u32 type,
-					     u32 mask)
+struct crypto_alg *crypto_lookup_aead(const char *name, u32 type, u32 mask)
 {
 	struct crypto_alg *alg;
 
@@ -503,6 +502,7 @@ static struct crypto_alg *crypto_lookup_aead(const char *name, u32 type,
 
 	return ERR_PTR(crypto_nivaead_default(alg, type, mask));
 }
+EXPORT_SYMBOL_GPL(crypto_lookup_aead);
 
 int crypto_grab_aead(struct crypto_aead_spawn *spawn, const char *name,
 		     u32 type, u32 mask)
crypto/crypto_user.c +70 -1

89 lines not on this page · raw message

include/crypto/internal/aead.h +2 -0
index d838c94..2eba340 100644
@@ -31,6 +31,8 @@ static inline void crypto_set_aead_spawn(
 	crypto_set_spawn(&spawn->base, inst);
 }
 
+struct crypto_alg *crypto_lookup_aead(const char *name, u32 type, u32 mask);
+
 int crypto_grab_aead(struct crypto_aead_spawn *spawn, const char *name,
 		     u32 type, u32 mask);
 
include/crypto/internal/skcipher.h +2 -0
index 3a748a6..06e8b32 100644
@@ -34,6 +34,8 @@ static inline void crypto_set_skcipher_spawn(
 int crypto_grab_skcipher(struct crypto_skcipher_spawn *spawn, const char *name,
 			 u32 type, u32 mask);
 
+struct crypto_alg *crypto_lookup_skcipher(const char *name, u32 type, u32 mask);
+
 static inline void crypto_drop_skcipher(struct crypto_skcipher_spawn *spawn)
 {
 	crypto_drop_spawn(&spawn->base);
Signature · 1 line
1.7.0.4
#1 lore raw

PATCH 2/2 crypto: user - Fix size of netlink dump message

The default netlink message size limit might be exceeded when dumping a lot of algorithms to userspace. As a result, not all of the instantiated algorithms dumped to userspace. So calculate an upper bound on the message size and call netlink_dump_start() with that value.

---
 crypto/crypto_user.c       |    8 +++++++-
 include/linux/cryptouser.h |    3 +++
 2 files changed, 10 insertions(+), 1 deletions(-)
crypto/crypto_user.c +7 -1
index 38534aa..7fca04c 100644
@@ -456,11 +456,17 @@ static int crypto_user_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
 
 	if ((type == (CRYPTO_MSG_GETALG - CRYPTO_MSG_BASE) &&
 	    (nlh->nlmsg_flags & NLM_F_DUMP))) {
+		struct crypto_alg *alg;
+		u16 dump_alloc = 0;
+
 		if (link->dump == NULL)
 			return -EINVAL;
 
+		list_for_each_entry(alg, &crypto_alg_list, cra_list)
+			dump_alloc += CRYPTO_REPORT_MAXSIZE;
+
 		return netlink_dump_start(crypto_nlsk, skb, nlh,
-					  link->dump, link->done, 0);
+					  link->dump, link->done, dump_alloc);
 	}
 
 	err = nlmsg_parse(nlh, crypto_msg_min[type], attrs, CRYPTOCFGA_MAX,
include/linux/cryptouser.h +3 -0
index 532fb58..4abf2ea 100644
@@ -100,3 +100,6 @@ struct crypto_report_rng {
 	char type[CRYPTO_MAX_NAME];
 	unsigned int seedsize;
 };
+
+#define CRYPTO_REPORT_MAXSIZE (sizeof(struct crypto_user_alg) + \
+			       sizeof(struct crypto_report_blkcipher))
Signature · 1 line
1.7.0.4
#2 lore raw

Re: [PATCH 2/2] crypto: user - Fix size of netlink dump message

crypto/crypto_user.c static int crypto_user_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh) · line 469

Quoted 4 lines · Steffen Klassert
crypto/crypto_user.c +2 -1
+
 		return netlink_dump_start(crypto_nlsk, skb, nlh,
-					  link->dump, link->done, 0);
+					  link->dump, link->done, dump_alloc);

I've just noticed that the interface to netlink_dump_start() changed in the mainline (with commit 80d326fab534a5380e8f6e509a0b9076655a9670), so this will cause a conflict. The crypto-2.6 tree is way behind the mainline (v3.2 + some patches). Could you please update the crypto-2.6 tree so that I can respin this patch?

Thanks!

maintainer
#3 lore raw

Re: [PATCH 2/2] crypto: user - Fix size of netlink dump message

Quoted 11 lines · Steffen Klassert

crypto/crypto_user.c static int crypto_user_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh) · line 469

Quoted 4 lines · Steffen Klassert
crypto/crypto_user.c +2 -1
+
 		return netlink_dump_start(crypto_nlsk, skb, nlh,
-					  link->dump, link->done, 0);
+					  link->dump, link->done, dump_alloc);

I've just noticed that the interface to netlink_dump_start() changed in the mainline (with commit 80d326fab534a5380e8f6e509a0b9076655a9670), so this will cause a conflict. The crypto-2.6 tree is way behind the mainline (v3.2 + some patches). Could you please update the crypto-2.6 tree so that I can respin this patch?

As long as your patch is against mainline it should be fine. I will rebase cryptodev before applying any patches for the next release.

Cheers,

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
#4 lore raw

Re: [PATCH 2/2] crypto: user - Fix size of netlink dump message

Quoted 14 lines · Herbert Xu
Quoted 11 lines · Steffen Klassert

crypto/crypto_user.c static int crypto_user_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh) · line 469

Quoted 4 lines · Steffen Klassert
crypto/crypto_user.c +2 -1
+
 		return netlink_dump_start(crypto_nlsk, skb, nlh,
-					  link->dump, link->done, 0);
+					  link->dump, link->done, dump_alloc);

I've just noticed that the interface to netlink_dump_start() changed in the mainline (with commit 80d326fab534a5380e8f6e509a0b9076655a9670), so this will cause a conflict. The crypto-2.6 tree is way behind the mainline (v3.2 + some patches). Could you please update the crypto-2.6 tree so that I can respin this patch?

Quoted 3 lines

As long as your patch is against mainline it should be fine. I will rebase cryptodev before applying any patches for the next release.

Ok, so I'll respin this one to the mainline and resend. Anyway, would be nice to see this fix in v3.4.

#5 lore raw

Re: [PATCH 2/2] crypto: user - Fix size of netlink dump message

Quoted 2 lines · Steffen Klassert

Ok, so I'll respin this one to the mainline and resend.

I'll resend the whole patchset, please ignore this one.

Thanks!