lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20211003181413.12465-5-nstange@suse.de>
Date:   Sun,  3 Oct 2021 20:14:09 +0200
From:   Nicolai Stange <nstange@...e.de>
To:     Herbert Xu <herbert@...dor.apana.org.au>,
        "David S. Miller" <davem@...emloft.net>
Cc:     linux-crypto@...r.kernel.org, linux-kernel@...r.kernel.org,
        Stephan Müller <smueller@...onox.de>,
        Torsten Duwe <duwe@...e.de>, Nicolai Stange <nstange@...e.de>
Subject: [PATCH 4/8] crypto: api - don't add larvals for !(type & CRYPTO_ALG_TESTED) lookups

As of now, the only valid (and existent) usecase for requesting an
algorithm with !(type & CRYPTO_ALG_TESTED) and (mask & CRYPTO_ALG_TESTED)
via crypto_alg_mod_lookup() is the testmgr invoked upon a
CRYPTO_MSG_ALG_REGISTER notification.

However, in this case it is expected and required that the lookup returns
the actual crypto_alg instance subject to testing.

If OTOH we were to assume for a moment that the crypto_larval_lookup()
called from crypto_alg_mod_lookup() would allocate and return a lookup
larval (which cannot happen, except for perhaps in some corner case like
with concurrent crypto_alg unregistrations), the subsequent wait in
crypto_alg_mod_lookup() would timeout anyway.

Make crypto_larval_wait() skip the lookup larval allocation if the
specified values of mask and type indicate a lookup request for some
crypto_alg instance still not in CRYPTO_ALG_TESTED state and the search for
such one failed. Instead, fail the call with -ENOENT in this case.

This reduces the number of possible ->mask and ->type configurations with
respect to CRYPTO_ALG_TESTED for pending lookup larvals and will enable
further cleanup with subsequent patches.

There is no change in functionality.

Signed-off-by: Nicolai Stange <nstange@...e.de>
---
 crypto/api.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/crypto/api.c b/crypto/api.c
index 5cced204b6b4..3bee52d7fe4b 100644
--- a/crypto/api.c
+++ b/crypto/api.c
@@ -283,8 +283,22 @@ static struct crypto_alg *crypto_larval_lookup(const char *name, u32 type,
 
 	if (!IS_ERR_OR_NULL(alg) && crypto_is_larval(alg))
 		alg = crypto_larval_wait(alg);
-	else if (!alg)
-		alg = crypto_larval_add(name, type, mask);
+	else if (!alg) {
+		/*
+		 * Only add a lookup larval if the request is for a
+		 * tested algorithm, everything else makes no sense.
+		 */
+		bool tested = type & mask & CRYPTO_ALG_TESTED;
+
+		if (!(mask & CRYPTO_ALG_TESTED)) {
+			WARN_ON_ONCE((type & CRYPTO_ALG_TESTED));
+			tested = true;
+		}
+		if (tested)
+			alg = crypto_larval_add(name, type, mask);
+		else
+			alg = ERR_PTR(-ENOENT);
+	}
 
 	return alg;
 }
-- 
2.26.2

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ