Skip to contentSkip to conversation

libceph: don't WARN() if user tries to add invalid key

PATCH In review Eric Biggers 2 participants 2 messages Nov 7, 2017

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libceph: don't WARN() if user tries to add invalid key

From: Eric Biggers <[email protected]>

The WARN_ON(!key->len) in set_secret() in net/ceph/crypto.c is hit if a user tries to add a key of type "ceph" with an invalid payload as follows (assuming CONFIG_CEPH_LIB=y):

echo -e -n '\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' \
| keyctl padd ceph desc @s

This can be hit by fuzzers. As this is merely bad input and not a kernel bug, replace the WARN_ON() with return -EINVAL.

Fixes 7af3ea189a9a ("libceph: stop allocating a new cipher on every crypto request")
Cc <[email protected]> # v4.10+
---
 net/ceph/crypto.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
net/ceph/crypto.c +3 -1
index 489610ac1cdd..bf9d079cbafd 100644
@@ -37,7 +37,9 @@ static int set_secret(struct ceph_crypto_key *key, void *buf)
 		return -ENOTSUPP;
 	}
 
-	WARN_ON(!key->len);
+	if (!key->len)
+		return -EINVAL;
+
 	key->key = kmemdup(buf, key->len, GFP_NOIO);
 	if (!key->key) {
 		ret = -ENOMEM;
Signature · 1 line
2.15.0
maintainer
#1 lore raw
Quoted 24 lines · Eric Biggers

From: Eric Biggers <[email protected]>

The WARN_ON(!key->len) in set_secret() in net/ceph/crypto.c is hit if a user tries to add a key of type "ceph" with an invalid payload as follows (assuming CONFIG_CEPH_LIB=y):

echo -e -n '\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' \
| keyctl padd ceph desc @s

This can be hit by fuzzers. As this is merely bad input and not a kernel bug, replace the WARN_ON() with return -EINVAL.

Fixes 7af3ea189a9a ("libceph: stop allocating a new cipher on every crypto request")
Cc <[email protected]> # v4.10+
---
 net/ceph/crypto.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
net/ceph/crypto.c +0 -0
index 489610ac1cdd..bf9d079cbafd 100644

net/ceph/crypto.c static int set_secret(struct ceph_crypto_key *key, void *buf) · line 45

Quoted 10 lines
net/ceph/crypto.c +3 -1
@@ -37,7 +37,9 @@ static int set_secret(struct ceph_crypto_key *key, void *buf)
                return -ENOTSUPP;
        }
 
-       WARN_ON(!key->len);
+       if (!key->len)
+               return -EINVAL;
+
        key->key = kmemdup(buf, key->len, GFP_NOIO);
        if (!key->key) {
                ret = -ENOMEM;

Makes sense, applied.

Thanks,

Ilya