Skip to content

Commit 9e468a9

Browse files
authored
Merge pull request #7096 from julek-wolfssl/zd/17219
Add fencing to ClientSessionToSession()
2 parents a8c94cf + 0e1573a commit 9e468a9

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

src/ssl.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14461,6 +14461,9 @@ WOLFSSL_SESSION* ClientSessionToSession(const WOLFSSL_SESSION* session)
1446114461
WOLFSSL_MSG("Client cache serverRow or serverIdx invalid");
1446214462
error = -1;
1446314463
}
14464+
/* Prevent memory access before clientSession->serverRow and
14465+
* clientSession->serverIdx are sanitized. */
14466+
XFENCE();
1446414467
if (error == 0) {
1446514468
/* Lock row */
1446614469
sessRow = &SessionCache[clientSession->serverRow];

wolfssl/wolfcrypt/wc_port.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,6 +1180,33 @@ WOLFSSL_ABI WOLFSSL_API int wolfCrypt_Cleanup(void);
11801180
#endif
11811181
#endif
11821182

1183+
#ifdef WOLF_C99
1184+
/* use alternate keyword for compatibility with -std=c99 */
1185+
#define XASM_VOLATILE(a) __asm__ volatile(a)
1186+
#elif defined(__IAR_SYSTEMS_ICC__)
1187+
#define XASM_VOLATILE(a) asm volatile(a)
1188+
#elif defined(__KEIL__)
1189+
#define XASM_VOLATILE(a) __asm volatile(a)
1190+
#else
1191+
#define XASM_VOLATILE(a) __asm__ __volatile__(a)
1192+
#endif
1193+
1194+
#ifndef WOLFSSL_NO_FENCE
1195+
#if defined (__i386__) || defined(__x86_64__)
1196+
#define XFENCE() XASM_VOLATILE("lfence")
1197+
#elif defined (__arm__) || defined(__aarch64__)
1198+
#define XFENCE() XASM_VOLATILE("isb")
1199+
#elif defined(__riscv)
1200+
#define XFENCE() XASM_VOLATILE("fence")
1201+
#elif defined(__PPC__)
1202+
#define XFENCE() XASM_VOLATILE("isync; sync")
1203+
#else
1204+
#define XFENCE() do{}while(0)
1205+
#endif
1206+
#else
1207+
#define XFENCE() do{}while(0)
1208+
#endif
1209+
11831210

11841211
/* AFTER user_settings.h is loaded,
11851212
** determine if POSIX multi-threaded: HAVE_PTHREAD */

0 commit comments

Comments
 (0)