Skip to content

Commit 01e8815

Browse files
committed
wolfssl/wolfcrypt/settings.h: add #define WOLFSSL_NO_PUBLIC_FFDHE and #undef HAVE_PUBLIC_FFDHE to WOLFSSL_LINUXKM setup to avoid .data.rel.ro.local functions in dh.c;
linuxkm/linuxkm_wc_port.h: only use kvrealloc() on kernel >=6.11 -- the version in 5.15-6.10 is incompatible (oldsize arg). also, restore use of kvmalloc on 4.12+, but with XREALLOC undefined, suitable for cryptonly modules; add #include <linux/sched.h> even on __PIE__ objects to make cond_sched() available; wolfcrypt/src/asn.c: harmonize gate around definitions of BEGIN_DSA_PRIV and END_DSA_PRIV; wolfcrypt/src/asn.c: in EccSpecifiedECDomainDecode(), work around "const char[]" types in WOLFSSL_ECC_CURVE_STATIC struct ecc_set_type on FIPS <6; wolfcrypt/src/asn.c, wolfcrypt/src/wc_xmss.c, wolfssl/wolfcrypt/wc_lms.h: add comments to new WOLFSSL_NAMES_STATIC slots explaining where the size comes from.
1 parent 7c6afeb commit 01e8815

6 files changed

Lines changed: 41 additions & 18 deletions

File tree

linuxkm/linuxkm_wc_port.h

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,16 @@
8080
/* kvmalloc()/kvfree() and friends added in linux commit a7c3e901, merged for 4.12.
8181
* kvrealloc() added in de2860f463, merged for 5.15, backported to 5.10.137.
8282
* moved to ultimate home (slab.h) in 8587ca6f34, merged for 5.16.
83-
83+
*
84+
* however, until 6.11, it took an extra argument, oldsize, that makes it
85+
* incompatible with traditional libc usage patterns, so we don't try to use it.
8486
*/
85-
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 15, 0)) || \
86-
((LINUX_VERSION_CODE >= KERNEL_VERSION(5, 10, 137)) && \
87-
(LINUX_VERSION_CODE < KERNEL_VERSION(5, 11, 90)))
87+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0)
8888
#define HAVE_KVMALLOC
8989
#endif
90+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 11, 0)
91+
#define HAVE_KVREALLOC
92+
#endif
9093

9194
/* kernel printf doesn't implement fp. */
9295
#ifndef WOLFSSL_NO_FLOAT_FMT
@@ -306,6 +309,7 @@
306309
#endif
307310

308311
#include <linux/slab.h>
312+
#include <linux/sched.h>
309313

310314
#ifndef __PIE__
311315
#ifndef SINGLE_THREADED
@@ -637,12 +641,16 @@
637641
typeof(kzalloc_noprof) *kzalloc_noprof;
638642
typeof(kvmalloc_node_noprof) *kvmalloc_node_noprof;
639643
typeof(kmalloc_trace_noprof) *kmalloc_trace_noprof;
640-
typeof(kvrealloc_noprof) *kvrealloc_noprof;
644+
#ifdef HAVE_KVREALLOC
645+
typeof(kvrealloc_noprof) *kvrealloc_noprof;
646+
#endif
641647
#else /* <6.10.0 */
642648
typeof(kmalloc) *kmalloc;
643649
typeof(krealloc) *krealloc;
644650
#ifdef HAVE_KVMALLOC
645651
typeof(kvmalloc_node) *kvmalloc_node;
652+
#endif
653+
#ifdef HAVE_KVREALLOC
646654
typeof(kvrealloc) *kvrealloc;
647655
#endif
648656
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 0)
@@ -879,6 +887,8 @@
879887
#define kzalloc(size, flags) kmalloc(size, (flags) | __GFP_ZERO)
880888
#ifdef HAVE_KVMALLOC
881889
#define kvmalloc_node (wolfssl_linuxkm_get_pie_redirect_table()->kvmalloc_node)
890+
#endif
891+
#ifdef HAVE_KVREALLOC
882892
#define kvrealloc (wolfssl_linuxkm_get_pie_redirect_table()->kvrealloc)
883893
#endif
884894
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 0)
@@ -1175,7 +1185,11 @@
11751185
#ifdef HAVE_KVMALLOC
11761186
#define malloc(size) kvmalloc_node(WC_LINUXKM_ROUND_UP_P_OF_2(size), (preempt_count() == 0 ? GFP_KERNEL : GFP_ATOMIC), NUMA_NO_NODE)
11771187
#define free(ptr) kvfree(ptr)
1178-
#define realloc(ptr, newsize) kvrealloc(ptr, WC_LINUXKM_ROUND_UP_P_OF_2(newsize), (preempt_count() == 0 ? GFP_KERNEL : GFP_ATOMIC))
1188+
#ifdef HAVE_KVREALLOC
1189+
#define realloc(ptr, newsize) kvrealloc(ptr, WC_LINUXKM_ROUND_UP_P_OF_2(newsize), (preempt_count() == 0 ? GFP_KERNEL : GFP_ATOMIC))
1190+
#else
1191+
#define realloc(ptr, newsize) ((void)(ptr), (void)(newsize), NULL)
1192+
#endif
11791193
#else
11801194
#define malloc(size) kmalloc(WC_LINUXKM_ROUND_UP_P_OF_2(size), (preempt_count() == 0 ? GFP_KERNEL : GFP_ATOMIC))
11811195
#define free(ptr) kfree(ptr)
@@ -1204,7 +1218,9 @@
12041218
#else
12051219
#define XFREE(p, h, t) ({void* _xp; (void)(h); (void)(t); _xp = (p); if(_xp) free(_xp);})
12061220
#endif
1207-
#define XREALLOC(p, n, h, t) ({(void)(h); (void)(t); realloc(p, n);})
1221+
#if defined(HAVE_KVREALLOC) || !defined(HAVE_KVMALLOC)
1222+
#define XREALLOC(p, n, h, t) ({(void)(h); (void)(t); realloc(p, n);})
1223+
#endif
12081224
#endif
12091225

12101226
#include <linux/limits.h>

linuxkm/module_hooks.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,8 @@ static int set_up_wolfssl_linuxkm_pie_redirect_table(void) {
523523
wolfssl_linuxkm_pie_redirect_table.krealloc = krealloc;
524524
#ifdef HAVE_KVMALLOC
525525
wolfssl_linuxkm_pie_redirect_table.kvmalloc_node = kvmalloc_node;
526+
#endif
527+
#ifdef HAVE_KVREALLOC
526528
wolfssl_linuxkm_pie_redirect_table.kvrealloc = kvrealloc;
527529
#endif
528530
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 0)

wolfcrypt/src/asn.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14323,7 +14323,9 @@ static int GetHashId(const byte* id, int length, byte* hash, int hashAlg)
1432314323
typedef struct CertNameData {
1432414324
/* Type string of name component. */
1432514325
#ifdef WOLFSSL_NAMES_STATIC
14326-
const char str[20];
14326+
const char str[20]; /* large enough for largest string in certNameSubject[]
14327+
* below
14328+
*/
1432714329
#define EMPTY_STR { 0 }
1432814330
#else
1432914331
const char* str;
@@ -26192,8 +26194,7 @@ static wcchar END_ENC_PRIV_KEY = "-----END ENCRYPTED PRIVATE KEY-----";
2619226194
static wcchar BEGIN_PKCS7 = "-----BEGIN PKCS7-----";
2619326195
static wcchar END_PKCS7 = "-----END PKCS7-----";
2619426196
#endif
26195-
#if defined(HAVE_ECC) || defined(HAVE_ED25519) || defined(HAVE_ED448) || \
26196-
!defined(NO_DSA)
26197+
#if defined(HAVE_ECC) || !defined(NO_DSA)
2619726198
static wcchar BEGIN_DSA_PRIV = "-----BEGIN DSA PRIVATE KEY-----";
2619826199
static wcchar END_DSA_PRIV = "-----END DSA PRIVATE KEY-----";
2619926200
#endif
@@ -35701,25 +35702,25 @@ static int EccSpecifiedECDomainDecode(const byte* input, word32 inSz,
3570135702
#else
3570235703
if (ret == 0) {
3570335704
/* Base X-ordinate */
35704-
DataToHexString(base + 1, (word32)curve->size, curve->Gx);
35705+
DataToHexString(base + 1, (word32)curve->size, (char *)curve->Gx);
3570535706
/* Base Y-ordinate */
35706-
DataToHexString(base + 1 + curve->size, (word32)curve->size, curve->Gy);
35707+
DataToHexString(base + 1 + curve->size, (word32)curve->size, (char *)curve->Gy);
3570735708
/* Prime */
3570835709
DataToHexString(dataASN[ECCSPECIFIEDASN_IDX_PRIME_P].data.ref.data,
3570935710
dataASN[ECCSPECIFIEDASN_IDX_PRIME_P].data.ref.length,
35710-
curve->prime);
35711+
(char *)curve->prime);
3571135712
/* Parameter A */
3571235713
DataToHexString(dataASN[ECCSPECIFIEDASN_IDX_PARAM_A].data.ref.data,
3571335714
dataASN[ECCSPECIFIEDASN_IDX_PARAM_A].data.ref.length,
35714-
curve->Af);
35715+
(char *)curve->Af);
3571535716
/* Parameter B */
3571635717
DataToHexString(dataASN[ECCSPECIFIEDASN_IDX_PARAM_B].data.ref.data,
3571735718
dataASN[ECCSPECIFIEDASN_IDX_PARAM_B].data.ref.length,
35718-
curve->Bf);
35719+
(char *)curve->Bf);
3571935720
/* Order of curve */
3572035721
DataToHexString(dataASN[ECCSPECIFIEDASN_IDX_ORDER].data.ref.data,
3572135722
dataASN[ECCSPECIFIEDASN_IDX_ORDER].data.ref.length,
35722-
curve->order);
35723+
(char *)curve->order);
3572335724
}
3572435725
#endif /* WOLFSSL_ECC_CURVE_STATIC */
3572535726

wolfcrypt/src/wc_xmss.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,9 @@ static WC_INLINE void wc_xmss_state_free(XmssState* state)
150150
typedef struct wc_XmssString {
151151
/* Name of algorithm as a string. */
152152
#ifdef WOLFSSL_NAMES_STATIC
153-
const char str[32];
153+
const char str[32]; /* large enough for largest string in wc_xmss_alg[] or
154+
* wc_xmssmt_alg[]
155+
*/
154156
#else
155157
const char* str;
156158
#endif

wolfssl/wolfcrypt/settings.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3699,6 +3699,8 @@ extern void uITRON4_free(void *p) ;
36993699
#define WC_NO_INTERNAL_FUNCTION_POINTERS
37003700
#define WOLFSSL_ECC_CURVE_STATIC
37013701
#define WOLFSSL_NAMES_STATIC
3702+
#define WOLFSSL_NO_PUBLIC_FFDHE
3703+
#undef HAVE_PUBLIC_FFDHE
37023704
#endif
37033705

37043706
#ifndef NO_OLD_WC_NAMES

wolfssl/wolfcrypt/wc_lms.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ typedef struct wc_LmsParamsMap {
385385
enum wc_LmsParm id;
386386
/* String representation of identifier of parameters. */
387387
#ifdef WOLFSSL_NAMES_STATIC
388-
const char str[32];
388+
const char str[32]; /* large enough for largest string in wc_lms_map[] */
389389
#else
390390
const char* str;
391391
#endif

0 commit comments

Comments
 (0)