Return-Path: Received: from mail-sn1nam01on0112.outbound.protection.outlook.com ([104.47.32.112]:45039 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1032394AbeCAPgj (ORCPT ); Thu, 1 Mar 2018 10:36:39 -0500 From: Sasha Levin To: "stable@vger.kernel.org" , "stable-commits@vger.kernel.org" CC: Eric Dumazet , Pablo Neira Ayuso , Sasha Levin Subject: [added to the 4.1 stable tree] netfilter: x_tables: avoid out-of-bounds reads in xt_request_find_{match|target} Date: Thu, 1 Mar 2018 15:26:42 +0000 Message-ID: <20180301152116.1486-391-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 Dumazet 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 da17c73b6eb74aad3c3c0654394635675b623b3e ] It looks like syzbot found its way into netfilter territory. Issue here is that @name comes from user space and might not be null terminated. Out-of-bound reads happen, KASAN is not happy. v2 added similar fix for xt_request_find_target(), as Florian advised. Signed-off-by: Eric Dumazet Reported-by: syzbot Acked-by: Florian Westphal Signed-off-by: Pablo Neira Ayuso Signed-off-by: Sasha Levin --- net/netfilter/x_tables.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/net/netfilter/x_tables.c b/net/netfilter/x_tables.c index a7d9d021c0c7..f4fcd9441561 100644 --- a/net/netfilter/x_tables.c +++ b/net/netfilter/x_tables.c @@ -209,6 +209,9 @@ xt_request_find_match(uint8_t nfproto, const char *name= , uint8_t revision) { struct xt_match *match; =20 + if (strnlen(name, XT_EXTENSION_MAXNAMELEN) =3D=3D XT_EXTENSION_MAXNAMELEN= ) + return ERR_PTR(-EINVAL); + match =3D xt_find_match(nfproto, name, revision); if (IS_ERR(match)) { request_module("%st_%s", xt_prefix[nfproto], name); @@ -251,6 +254,9 @@ struct xt_target *xt_request_find_target(u8 af, const c= har *name, u8 revision) { struct xt_target *target; =20 + if (strnlen(name, XT_EXTENSION_MAXNAMELEN) =3D=3D XT_EXTENSION_MAXNAMELEN= ) + return ERR_PTR(-EINVAL); + target =3D xt_find_target(af, name, revision); if (IS_ERR(target)) { request_module("%st_%s", xt_prefix[af], name); --=20 2.14.1