⬢ DragonFlyBSD Kernel Audit
DF-3569 / fix.diff
← back to finding ↓ download raw
Fix DF-3569: validate Camellia key length at the API boundary
(camellia-api.c forward-validated nothing; camellia.c:1253 KASSERT is
 compiled out on production kernels -> invalid bits = uninitialized
 schedule + identity-function encryption.  No in-tree consumers;
 void->int return is statement-call compatible.)

--- a/sys/crypto/camellia/camellia.h	2026-09-15 02:39:09.366784293 +0000
+++ b/sys/crypto/camellia/camellia.h	2026-09-15 02:39:09.390783990 +0000
@@ -38,7 +38,7 @@
     uint32_t subkey[CAMELLIA_SUBKEYWORD]; /* encrypt/decrypt key schedule */
 } camellia_ctx;
 
-void camellia_set_key(camellia_ctx *, const u_char *, int);
+int camellia_set_key(camellia_ctx *, const u_char *, int);
 void camellia_decrypt(const camellia_ctx *, const u_char *, u_char *);
 void camellia_encrypt(const camellia_ctx *, const u_char *, u_char *);
 
--- a/sys/crypto/camellia/camellia-api.c	2026-09-15 02:39:09.366784293 +0000
+++ b/sys/crypto/camellia/camellia-api.c	2026-09-15 02:39:09.394783939 +0000
@@ -33,18 +33,28 @@
 #endif
 #include <crypto/camellia/camellia.h>
 
-void
+/*
+ * Returns 0 on success, -1 if `bits' is not a valid Camellia key length
+ * ({128, 192, 256}).  On rejection neither the key material nor *ctx is
+ * touched; callers must not use the context afterwards.
+ */
+int
 camellia_set_key(camellia_ctx *ctx, const u_char *key, int bits)
 {
 
+    if (bits != 128 && bits != 192 && bits != 256)
+	return (-1);
     Camellia_Ekeygen(bits, key, ctx->subkey);
     ctx->bits = bits;
+    return (0);
 }
 
 void
 camellia_decrypt(const camellia_ctx *ctx, const u_char *src, u_char *dst)
 {
 
+    if (ctx->bits != 128 && ctx->bits != 192 && ctx->bits != 256)
+	return;			/* invalid schedule: leave dst untouched */
     Camellia_DecryptBlock(ctx->bits, src, ctx->subkey, dst);
 }
 
@@ -52,5 +62,7 @@
 camellia_encrypt(const camellia_ctx *ctx, const u_char *src, u_char *dst)
 {
 
+    if (ctx->bits != 128 && ctx->bits != 192 && ctx->bits != 256)
+	return;			/* invalid schedule: leave dst untouched */
     Camellia_EncryptBlock(ctx->bits, src, ctx->subkey, dst);
 }