From nobody Thu Dec 18 08:26:33 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5788BC83F15 for ; Mon, 28 Aug 2023 13:23:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231593AbjH1NWf (ORCPT ); Mon, 28 Aug 2023 09:22:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53388 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232086AbjH1NW0 (ORCPT ); Mon, 28 Aug 2023 09:22:26 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BFCFA12E for ; Mon, 28 Aug 2023 06:21:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693228895; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=XObW/irKrFMvdZD/5mdweJdM7rYD71QsYjFo9kkuf18=; b=eObDWo0E+sv9T+e7TXosRRQ8IdoxWIu5aGYPh5jGWE6TaE9734TmULk24S/Yx0nm8MKPTi QURlqImIsznJVuHHvgneHQYX9gTDzpQ+SA4KBwuMYjCcyfp+XjxcIC381f6Y3Zwxx2sTF/ dC47H9WjBCd8KZZNlGpFaPsUx4uEBtA= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-580-yZB3xwcoMQipTDtpjyk_HQ-1; Mon, 28 Aug 2023 09:21:27 -0400 X-MC-Unique: yZB3xwcoMQipTDtpjyk_HQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 953538D40A5; Mon, 28 Aug 2023 13:21:26 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.16.86]) by smtp.corp.redhat.com (Postfix) with ESMTP id A26E940C6F4E; Mon, 28 Aug 2023 13:21:23 +0000 (UTC) From: Wander Lairson Costa To: Pablo Neira Ayuso , Jozsef Kadlecsik , Florian Westphal , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Patrick McHardy , Jan Engelhardt , netfilter-devel@vger.kernel.org (open list:NETFILTER), coreteam@netfilter.org (open list:NETFILTER), netdev@vger.kernel.org (open list:NETWORKING [GENERAL]), linux-kernel@vger.kernel.org (open list) Cc: Wander Lairson Costa Subject: [PATCH nf] netfilter/xt_u32: validate user space input Date: Mon, 28 Aug 2023 10:21:07 -0300 Message-ID: <20230828132107.18376-1-wander@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The xt_u32 module doesn't validate the fields in the xt_u32 structure. An attacker may take advantage of this to trigger an OOB read by setting the size fields with a value beyond the arrays boundaries. Add a checkentry function to validate the structure. This was originally reported by the ZDI project (ZDI-CAN-18408). Fixes: 1b50b8a371e9 ("[NETFILTER]: Add u32 match") Signed-off-by: Wander Lairson Costa --- net/netfilter/xt_u32.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/net/netfilter/xt_u32.c b/net/netfilter/xt_u32.c index 177b40d08098..117d4615d668 100644 --- a/net/netfilter/xt_u32.c +++ b/net/netfilter/xt_u32.c @@ -96,11 +96,32 @@ static bool u32_mt(const struct sk_buff *skb, struct xt= _action_param *par) return ret ^ data->invert; } =20 +static int u32_mt_checkentry(const struct xt_mtchk_param *par) +{ + const struct xt_u32 *data =3D par->matchinfo; + const struct xt_u32_test *ct; + unsigned int i; + + if (data->ntests > ARRAY_SIZE(data->tests)) + return -EINVAL; + + for (i =3D 0; i < data->ntests; ++i) { + ct =3D &data->tests[i]; + + if (ct->nnums > ARRAY_SIZE(ct->location) || + ct->nvalues > ARRAY_SIZE(ct->value)) + return -EINVAL; + } + + return 0; +} + static struct xt_match xt_u32_mt_reg __read_mostly =3D { .name =3D "u32", .revision =3D 0, .family =3D NFPROTO_UNSPEC, .match =3D u32_mt, + .checkentry =3D u32_mt_checkentry, .matchsize =3D sizeof(struct xt_u32), .me =3D THIS_MODULE, }; --=20 2.41.0