Skip to content

Commit fd58885

Browse files
authored
Merge pull request #9490 from douzzer/20251202-linuxkm-old-kernel-fixes
20251202-linuxkm-old-kernel-fixes
2 parents 5b74804 + e225bf8 commit fd58885

5 files changed

Lines changed: 76 additions & 23 deletions

File tree

linuxkm/linuxkm_wc_port.h

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,25 @@
116116
#endif
117117
#endif
118118

119+
#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 1, 0)
120+
/* added by 6bab69c650 */
121+
#define static_assert(expr, ...) __static_assert(expr, ##__VA_ARGS__, #expr)
122+
#define __static_assert(expr, msg, ...) _Static_assert(expr, msg)
123+
#endif
124+
119125
/* kernel printf doesn't implement fp. */
120126
#ifndef WOLFSSL_NO_FLOAT_FMT
121127
#define WOLFSSL_NO_FLOAT_FMT
122128
#endif
123129

130+
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 15, 0)) || \
131+
(defined(RHEL_MAJOR) && \
132+
((RHEL_MAJOR > 9) || ((RHEL_MAJOR == 9) && (RHEL_MINOR >= 5))))
133+
#define WOLFSSL_DEBUG_PRINTF_FN _printk
134+
#else
135+
#define WOLFSSL_DEBUG_PRINTF_FN printk
136+
#endif
137+
124138
#ifndef WOLFSSL_LINUXKM_USE_MUTEXES
125139
struct wolfSSL_Mutex;
126140
extern int wc_lkm_LockMutex(struct wolfSSL_Mutex* m);
@@ -250,6 +264,7 @@
250264
_Pragma("GCC diagnostic ignored \"-Wswitch-enum\"");
251265
_Pragma("GCC diagnostic ignored \"-Wcast-function-type\""); /* needed for kernel 4.14.336 */
252266
_Pragma("GCC diagnostic ignored \"-Wformat-nonliteral\""); /* needed for kernel 4.9.282 */
267+
_Pragma("GCC diagnostic ignored \"-Wattributes\"");
253268

254269
#include <linux/kconfig.h>
255270

@@ -544,9 +559,16 @@
544559

545560
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 0, 0)
546561
#include <asm/i387.h>
562+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0)
563+
/* added by a62b01cd6c */
564+
#include <asm-generic/simd.h>
565+
#endif
547566
#else
548567
#include <asm/simd.h>
549-
#include <crypto/internal/simd.h>
568+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0)
569+
/* added by 266d051601 */
570+
#include <crypto/internal/simd.h>
571+
#endif
550572
#endif
551573
#ifndef CAN_SAVE_VECTOR_REGISTERS
552574
#ifdef DEBUG_VECTOR_REGISTER_ACCESS_FUZZING
@@ -721,6 +743,9 @@
721743
struct Signer* GetCAByKeyHash(void* vp, const unsigned char* keyHash);
722744
#endif /* HAVE_OCSP */
723745
#ifdef WOLFSSL_AKID_NAME
746+
#ifdef WOLFSSL_API_PREFIX_MAP
747+
#define GetCAByAKID wolfSSL_GetCAByAKID
748+
#endif
724749
struct Signer* GetCAByAKID(void* vp, const unsigned char* issuer,
725750
unsigned int issuerSz,
726751
const unsigned char* serial,
@@ -1264,7 +1289,11 @@
12641289
#endif /* HAVE_OCSP */
12651290
#endif /* NO_SKID */
12661291
#ifdef WOLFSSL_AKID_NAME
1267-
#define GetCAByAKID WC_PIE_INDIRECT_SYM(GetCAByAKID)
1292+
#ifdef WOLFSSL_API_PREFIX_MAP
1293+
#define wolfSSL_GetCAByAKID WC_PIE_INDIRECT_SYM(wolfSSL_GetCAByAKID)
1294+
#else
1295+
#define GetCAByAKID WC_PIE_INDIRECT_SYM(GetCAByAKID)
1296+
#endif
12681297
#endif
12691298

12701299
#if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)

linuxkm/lkcapi_sha_glue.c

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,24 +1167,42 @@ static int wc_linuxkm_drbg_generate(struct crypto_rng *tfm,
11671167
}
11681168
}
11691169

1170-
ret = wc_RNG_GenerateBlock(&drbg->rng, dst, dlen);
1171-
1172-
if (unlikely(ret == WC_NO_ERR_TRACE(RNG_FAILURE_E)) && (! retried)) {
1173-
retried = 1;
1174-
wc_FreeRng(&drbg->rng);
1175-
ret = wc_InitRng(&drbg->rng);
1176-
if (ret == 0) {
1177-
pr_warn("WARNING: reinitialized DRBG #%d after RNG_FAILURE_E.", raw_smp_processor_id());
1178-
goto retry;
1170+
for (;;) {
1171+
#define RNG_MAX_BLOCK_LEN_ROUNDED (RNG_MAX_BLOCK_LEN & ~0xfU)
1172+
if (dlen > RNG_MAX_BLOCK_LEN_ROUNDED) {
1173+
ret = wc_RNG_GenerateBlock(&drbg->rng, dst, RNG_MAX_BLOCK_LEN_ROUNDED);
1174+
if (ret == 0) {
1175+
dlen -= RNG_MAX_BLOCK_LEN_ROUNDED;
1176+
dst += RNG_MAX_BLOCK_LEN_ROUNDED;
1177+
}
11791178
}
1179+
#undef RNG_MAX_BLOCK_LEN_ROUNDED
11801180
else {
1181-
pr_warn_once("ERROR: reinitialization of DRBG #%d after RNG_FAILURE_E failed with ret %d.", raw_smp_processor_id(), ret);
1181+
ret = wc_RNG_GenerateBlock(&drbg->rng, dst, dlen);
1182+
dlen -= dlen;
1183+
}
1184+
1185+
if (unlikely(ret == WC_NO_ERR_TRACE(RNG_FAILURE_E)) && (! retried)) {
1186+
retried = 1;
1187+
wc_FreeRng(&drbg->rng);
1188+
ret = wc_InitRng(&drbg->rng);
1189+
if (ret == 0) {
1190+
pr_warn("WARNING: reinitialized DRBG #%d after RNG_FAILURE_E.", raw_smp_processor_id());
1191+
goto retry;
1192+
}
1193+
else {
1194+
pr_warn_once("ERROR: reinitialization of DRBG #%d after RNG_FAILURE_E failed with ret %d.", raw_smp_processor_id(), ret);
1195+
ret = -EINVAL;
1196+
}
1197+
}
1198+
else if (ret != 0) {
1199+
pr_warn_once("WARNING: wc_RNG_GenerateBlock returned %d\n",ret);
11821200
ret = -EINVAL;
1201+
break;
11831202
}
1184-
}
1185-
else if (ret != 0) {
1186-
pr_warn_once("WARNING: wc_RNG_GenerateBlock returned %d\n",ret);
1187-
ret = -EINVAL;
1203+
1204+
if (! dlen)
1205+
break;
11881206
}
11891207

11901208
out:

wolfssl/internal.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6698,10 +6698,11 @@ WOLFSSL_LOCAL WC_RNG* WOLFSSL_RSA_GetRNG(WOLFSSL_RSA *rsa, WC_RNG **tmpRNG,
66986698
#ifndef GetCA
66996699
WOLFSSL_LOCAL Signer* GetCA(void* vp, byte* hash);
67006700
#endif
6701-
#if defined(WOLFSSL_AKID_NAME) && !defined(GetCAByAKID)
6702-
#ifdef WOLFSSL_API_PREFIX_MAP
6703-
#define GetCAByAKID wolfSSL_GetCAByAKID
6704-
#endif
6701+
#if defined(WOLFSSL_AKID_NAME) && !defined(WC_SYM_RELOC_TABLES)
6702+
/* note WOLFSSL_API_PREFIX_MAPping is in asn.h, and if
6703+
* WC_SYM_RELOC_TABLES, the prototype is in the port layer
6704+
* (e.g. linuxkm_wc_port.h), to allow shimming.
6705+
*/
67056706
WOLFSSL_TEST_VIS Signer* GetCAByAKID(void* vp, const byte* issuer,
67066707
word32 issuerSz, const byte* serial, word32 serialSz);
67076708
#endif

wolfssl/wolfcrypt/asn.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2084,6 +2084,13 @@ typedef enum MimeStatus
20842084
#define SetAlgoID wc_SetAlgoID
20852085
#define SetAsymKeyDer wc_SetAsymKeyDer
20862086
#define CalcHashId wc_CalcHashId
2087+
#if defined(WOLFSSL_AKID_NAME) && !defined(GetCAByAKID)
2088+
/* GetCAByAKID() has two implementations, a full implementation in
2089+
* src/ssl.c, and a dummy implementation in wolfcrypt/src/asn.c for
2090+
* WOLFCRYPT_ONLY builds.
2091+
*/
2092+
#define GetCAByAKID wolfSSL_GetCAByAKID
2093+
#endif
20872094
#endif /* WOLFSSL_API_PREFIX_MAP */
20882095

20892096
WOLFSSL_LOCAL int HashIdAlg(word32 oidSum);

wolfssl/wolfcrypt/logging.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ WOLFSSL_API void wolfSSL_SetLoggingPrefix(const char* prefix);
505505
* For custom debugging output, define your own WOLFSSL_DEBUG_PRINTF_FN
506506
*/
507507
#ifdef WOLFSSL_DEBUG_PRINTF_FN
508-
/* user-supplied definition */
508+
/* user- or port-supplied definition */
509509
#elif defined(ARDUINO)
510510
/* ARDUINO only has print and sprintf, no printf. */
511511
#elif defined(__WATCOMC__)
@@ -548,8 +548,6 @@ WOLFSSL_API void wolfSSL_SetLoggingPrefix(const char* prefix);
548548
#define WOLFSSL_DEBUG_PRINTF_FIRST_ARGS ANDROID_LOG_VERBOSE, "[wolfSSL]",
549549
#elif defined(WOLFSSL_XILINX)
550550
#define WOLFSSL_DEBUG_PRINTF_FN xil_printf
551-
#elif defined(WOLFSSL_LINUXKM)
552-
#define WOLFSSL_DEBUG_PRINTF_FN printk
553551
#elif defined(WOLFSSL_RENESAS_RA6M4)
554552
#define WOLFSSL_DEBUG_PRINTF_FN myprintf
555553
#elif defined(NO_STDIO_FILESYSTEM)

0 commit comments

Comments
 (0)