Bluetooth: Prevent stack info leak from the EFS element.

In the function l2cap_parse_conf_rsp and in the function
l2cap_parse_conf_req the following variable is declared without
initialization:

struct l2cap_conf_efs efs;

In addition, when parsing input configuration parameters in both of
these functions, the switch case for handling EFS elements may skip the
memcpy call that will write to the efs variable:

...
case L2CAP_CONF_EFS:
if (olen == sizeof(efs))
memcpy(&efs, (void *)val, olen);
...

The olen in the above if is attacker controlled, and regardless of that
if, in both of these functions the efs variable would eventually be
added to the outgoing configuration request that is being built:

l2cap_add_conf_opt(&ptr, L2CAP_CONF_EFS, sizeof(efs), (unsigned long) &efs);

So by sending a configuration request, or response, that contains an
L2CAP_CONF_EFS element, but with an element length that is not
sizeof(efs) - the memcpy to the uninitialized efs variable can be
avoided, and the uninitialized variable would be returned to the
attacker (16 bytes).

This issue has been assigned CVE-2017-1000410

Cc: Marcel Holtmann <marcel@holtmann.org>
Cc: Gustavo Padovan <gustavo@padovan.org>
Cc: Johan Hedberg <johan.hedberg@gmail.com>
Cc: stable <stable@vger.kernel.org>
Signed-off-by: Ben Seri <ben@armis.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by Ben Seri and committed by Greg Kroah-Hartman 06e7e776 30a7acd5

+11 -9
+11 -9
net/bluetooth/l2cap_core.c
··· 3363 break; 3364 3365 case L2CAP_CONF_EFS: 3366 - remote_efs = 1; 3367 - if (olen == sizeof(efs)) 3368 memcpy(&efs, (void *) val, olen); 3369 break; 3370 3371 case L2CAP_CONF_EWS: ··· 3585 break; 3586 3587 case L2CAP_CONF_EFS: 3588 - if (olen == sizeof(efs)) 3589 memcpy(&efs, (void *)val, olen); 3590 3591 - if (chan->local_stype != L2CAP_SERV_NOTRAFIC && 3592 - efs.stype != L2CAP_SERV_NOTRAFIC && 3593 - efs.stype != chan->local_stype) 3594 - return -ECONNREFUSED; 3595 3596 - l2cap_add_conf_opt(&ptr, L2CAP_CONF_EFS, sizeof(efs), 3597 - (unsigned long) &efs, endptr - ptr); 3598 break; 3599 3600 case L2CAP_CONF_FCS:
··· 3363 break; 3364 3365 case L2CAP_CONF_EFS: 3366 + if (olen == sizeof(efs)) { 3367 + remote_efs = 1; 3368 memcpy(&efs, (void *) val, olen); 3369 + } 3370 break; 3371 3372 case L2CAP_CONF_EWS: ··· 3584 break; 3585 3586 case L2CAP_CONF_EFS: 3587 + if (olen == sizeof(efs)) { 3588 memcpy(&efs, (void *)val, olen); 3589 3590 + if (chan->local_stype != L2CAP_SERV_NOTRAFIC && 3591 + efs.stype != L2CAP_SERV_NOTRAFIC && 3592 + efs.stype != chan->local_stype) 3593 + return -ECONNREFUSED; 3594 3595 + l2cap_add_conf_opt(&ptr, L2CAP_CONF_EFS, sizeof(efs), 3596 + (unsigned long) &efs, endptr - ptr); 3597 + } 3598 break; 3599 3600 case L2CAP_CONF_FCS: