mirror of
https://github.com/vanhoefm/fragattacks.git
synced 2024-11-28 18:28:23 -05:00
SAE: Avoid undefined behavior in pointer arithmetic
Reorder terms in a way that no invalid pointers are generated with pos+len operations. end-pos is always defined (with a valid pos pointer) while pos+len could end up pointing beyond the end pointer which would be undefined behavior. Signed-off-by: Jouni Malinen <j@w1.fi>
This commit is contained in:
parent
f88bcad015
commit
80c620dbd7
@ -923,7 +923,7 @@ static void sae_parse_commit_token(struct sae_data *sae, const u8 **pos,
|
||||
const u8 *end, const u8 **token,
|
||||
size_t *token_len)
|
||||
{
|
||||
if (*pos + (sae->tmp->ec ? 3 : 2) * sae->tmp->prime_len < end) {
|
||||
if ((sae->tmp->ec ? 3 : 2) * sae->tmp->prime_len < end - *pos) {
|
||||
size_t tlen = end - (*pos + (sae->tmp->ec ? 3 : 2) *
|
||||
sae->tmp->prime_len);
|
||||
wpa_hexdump(MSG_DEBUG, "SAE: Anti-Clogging Token", *pos, tlen);
|
||||
@ -946,7 +946,7 @@ static u16 sae_parse_commit_scalar(struct sae_data *sae, const u8 **pos,
|
||||
{
|
||||
struct crypto_bignum *peer_scalar;
|
||||
|
||||
if (*pos + sae->tmp->prime_len > end) {
|
||||
if (sae->tmp->prime_len > end - *pos) {
|
||||
wpa_printf(MSG_DEBUG, "SAE: Not enough data for scalar");
|
||||
return WLAN_STATUS_UNSPECIFIED_FAILURE;
|
||||
}
|
||||
@ -994,7 +994,7 @@ static u16 sae_parse_commit_element_ecc(struct sae_data *sae, const u8 *pos,
|
||||
{
|
||||
u8 prime[SAE_MAX_ECC_PRIME_LEN];
|
||||
|
||||
if (pos + 2 * sae->tmp->prime_len > end) {
|
||||
if (2 * sae->tmp->prime_len > end - pos) {
|
||||
wpa_printf(MSG_DEBUG, "SAE: Not enough data for "
|
||||
"commit-element");
|
||||
return WLAN_STATUS_UNSPECIFIED_FAILURE;
|
||||
@ -1040,7 +1040,7 @@ static u16 sae_parse_commit_element_ffc(struct sae_data *sae, const u8 *pos,
|
||||
struct crypto_bignum *res, *one;
|
||||
const u8 one_bin[1] = { 0x01 };
|
||||
|
||||
if (pos + sae->tmp->prime_len > end) {
|
||||
if (sae->tmp->prime_len > end - pos) {
|
||||
wpa_printf(MSG_DEBUG, "SAE: Not enough data for "
|
||||
"commit-element");
|
||||
return WLAN_STATUS_UNSPECIFIED_FAILURE;
|
||||
@ -1098,7 +1098,7 @@ u16 sae_parse_commit(struct sae_data *sae, const u8 *data, size_t len,
|
||||
u16 res;
|
||||
|
||||
/* Check Finite Cyclic Group */
|
||||
if (pos + 2 > end)
|
||||
if (end - pos < 2)
|
||||
return WLAN_STATUS_UNSPECIFIED_FAILURE;
|
||||
res = sae_group_allowed(sae, allowed_groups, WPA_GET_LE16(pos));
|
||||
if (res != WLAN_STATUS_SUCCESS)
|
||||
|
Loading…
Reference in New Issue
Block a user