Return-Path: Received: from mail-sn1nam02on0137.outbound.protection.outlook.com ([104.47.36.137]:63678 "EHLO NAM02-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1032136AbeCAPaV (ORCPT ); Thu, 1 Mar 2018 10:30:21 -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 parse_exthdrs() Date: Thu, 1 Mar 2018 15:24:23 +0000 Message-ID: <20180301152116.1486-186-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 4e765b4972af7b07adcb1feb16e7a525ce1f6b28 ] If a message sent to a PF_KEY socket ended with an incomplete extension header (fewer than 4 bytes remaining), then parse_exthdrs() read past the end of the message, into uninitialized memory. Fix it by returning -EINVAL in this case. Reproducer: #include #include #include int main() { int sock =3D socket(PF_KEY, SOCK_RAW, PF_KEY_V2); char buf[17] =3D { 0 }; struct sadb_msg *msg =3D (void *)buf; msg->sadb_msg_version =3D PF_KEY_V2; msg->sadb_msg_type =3D SADB_DELETE; msg->sadb_msg_len =3D 2; write(sock, buf, 17); } 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 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/net/key/af_key.c b/net/key/af_key.c index 1dc7b8894135..354c43a1c43d 100644 --- a/net/key/af_key.c +++ b/net/key/af_key.c @@ -516,6 +516,9 @@ static int parse_exthdrs(struct sk_buff *skb, const str= uct sadb_msg *hdr, void * uint16_t ext_type; int ext_len; =20 + if (len < sizeof(*ehdr)) + return -EINVAL; + ext_len =3D ehdr->sadb_ext_len; ext_len *=3D sizeof(uint64_t); ext_type =3D ehdr->sadb_ext_type; --=20 2.14.1