From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-sn1nam02on0109.outbound.protection.outlook.com ([104.47.36.109]:7623 "EHLO NAM02-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1032162AbeCAPaT (ORCPT ); Thu, 1 Mar 2018 10:30:19 -0500 From: Sasha Levin To: "stable@vger.kernel.org" , "stable-commits@vger.kernel.org" CC: Eric Biggers , Steffen Klassert , Sasha Levin Subject: [added to the 4.1 stable tree] af_key: fix buffer overread in verify_address_len() Date: Thu, 1 Mar 2018 15:24:22 +0000 Message-ID: <20180301152116.1486-185-alexander.levin@microsoft.com> References: <20180301152116.1486-1-alexander.levin@microsoft.com> In-Reply-To: <20180301152116.1486-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: Eric Biggers This patch has been added to the 4.1 stable tree. If you have any objections, please let us know. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D [ Upstream commit 06b335cb51af018d5feeff5dd4fd53847ddb675a ] If a message sent to a PF_KEY socket ended with one of the extensions that takes a 'struct sadb_address' but there were not enough bytes remaining in the message for the ->sa_family member of the 'struct sockaddr' which is supposed to follow, then verify_address_len() read past the end of the message, into uninitialized memory. Fix it by returning -EINVAL in this case. This bug was found using syzkaller with KMSAN. Reproducer: #include #include #include int main() { int sock =3D socket(PF_KEY, SOCK_RAW, PF_KEY_V2); char buf[24] =3D { 0 }; struct sadb_msg *msg =3D (void *)buf; struct sadb_address *addr =3D (void *)(msg + 1); msg->sadb_msg_version =3D PF_KEY_V2; msg->sadb_msg_type =3D SADB_DELETE; msg->sadb_msg_len =3D 3; addr->sadb_address_len =3D 1; addr->sadb_address_exttype =3D SADB_EXT_ADDRESS_SRC; write(sock, buf, 24); } Reported-by: Alexander Potapenko Cc: stable@vger.kernel.org Signed-off-by: Eric Biggers Signed-off-by: Steffen Klassert Signed-off-by: Sasha Levin --- net/key/af_key.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/net/key/af_key.c b/net/key/af_key.c index 39c78c9e1c68..1dc7b8894135 100644 --- a/net/key/af_key.c +++ b/net/key/af_key.c @@ -401,6 +401,11 @@ static int verify_address_len(const void *p) #endif int len; =20 + if (sp->sadb_address_len < + DIV_ROUND_UP(sizeof(*sp) + offsetofend(typeof(*addr), sa_family), + sizeof(uint64_t))) + return -EINVAL; + switch (addr->sa_family) { case AF_INET: len =3D DIV_ROUND_UP(sizeof(*sp) + sizeof(*sin), sizeof(uint64_t)); --=20 2.14.1