From patchwork Thu Oct 26 13:05:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magali Lemes X-Patchwork-Id: 1855818 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SGR0g5Q15z23jV for ; Fri, 27 Oct 2023 00:07:31 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1qw04u-0002Ts-2c; Thu, 26 Oct 2023 13:07:12 +0000 Received: from smtp-relay-internal-0.internal ([10.131.114.225] helo=smtp-relay-internal-0.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1qw04i-0002SJ-O8 for kernel-team@lists.ubuntu.com; Thu, 26 Oct 2023 13:07:01 +0000 Received: from mail-pl1-f199.google.com (mail-pl1-f199.google.com [209.85.214.199]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 76F5C3FD48 for ; Thu, 26 Oct 2023 13:06:59 +0000 (UTC) Received: by mail-pl1-f199.google.com with SMTP id d9443c01a7336-1c9dffb4256so5740805ad.0 for ; Thu, 26 Oct 2023 06:06:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698325617; x=1698930417; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Mu6Q7Yr2F4uZnu/zJKaJA6FlFP/1gj5tF9N3W0qg7xs=; b=nNfRv4LEA8iV53hcglozTRG0aegrTlp/+es7R5eEl9Rq9sDHIcI9V3V4ZGj2rnswyr s1Nw/0Zn5sBw5d9KLsgcK5yTX13Wd9P5mxvJWpIN1XP1fO5KSDGEQBJxqAFIZ3wPgA4W Ph3SATBo+1QHZCQT13Cnj1MYezVQ9QDOlsWVi7F9FBkFMjMXTxxykcMIgtk3yCCHVOzs o399PwPImdg/MDKKq+N9R0voWzTG+D7wqeEA/5ZylhrLnpJLGLf6iBvnH7uaMTteB2JE SUaVLwDIy6jA/WTH1cWU4gVMJKy9RYDck4mBFvUqoFU4H39RhAcetfvFqEgrIMuaH1Hv PcUA== X-Gm-Message-State: AOJu0YyY20m0GQHCkBJbisimEK17ce6XwcZQsER20CwznrExwdlCHk++ AOJBZ+VCnzTxOd1H/2hAWBfB+mTC9MKkkS+hCWDIsEkkpHxGuUgJe7A6Oh18aYOy4m3eTetiDIM 0wm9Dabco1o8lFD93Fh9d38snMW+mlFLVrIhfuRQ4KWdgm+qkAg== X-Received: by 2002:a17:902:d2cf:b0:1c7:49dd:2ff with SMTP id n15-20020a170902d2cf00b001c749dd02ffmr3148146plc.27.1698325617504; Thu, 26 Oct 2023 06:06:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFyimwrYxgSZDAy7tP6VuqM4BOcQWTFLIairawtCCAWpLkqcoo3BXLgCKHVeBN+Xjt84exJiQ== X-Received: by 2002:a17:902:d2cf:b0:1c7:49dd:2ff with SMTP id n15-20020a170902d2cf00b001c749dd02ffmr3148112plc.27.1698325616885; Thu, 26 Oct 2023 06:06:56 -0700 (PDT) Received: from localhost.localdomain ([2804:7f0:b440:4f55:1d0d:7a8:4206:a94d]) by smtp.gmail.com with ESMTPSA id iy10-20020a170903130a00b001c613091aeesm10994879plb.293.2023.10.26.06.06.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Oct 2023 06:06:56 -0700 (PDT) From: Magali Lemes To: kernel-team@lists.ubuntu.com Subject: [SRU][F/J/L][PATCH 1/1] netfilter: xt_u32: validate user space input Date: Thu, 26 Oct 2023 10:05:54 -0300 Message-Id: <20231026130554.248615-2-magali.lemes@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231026130554.248615-1-magali.lemes@canonical.com> References: <20231026130554.248615-1-magali.lemes@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Wander Lairson Costa 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") Cc: stable@vger.kernel.org Signed-off-by: Wander Lairson Costa Signed-off-by: Pablo Neira Ayuso (cherry picked from commit 69c5d284f67089b4750d28ff6ac6f52ec224b330) CVE-2023-39192 Signed-off-by: Magali Lemes --- 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; } +static int u32_mt_checkentry(const struct xt_mtchk_param *par) +{ + const struct xt_u32 *data = par->matchinfo; + const struct xt_u32_test *ct; + unsigned int i; + + if (data->ntests > ARRAY_SIZE(data->tests)) + return -EINVAL; + + for (i = 0; i < data->ntests; ++i) { + ct = &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 = { .name = "u32", .revision = 0, .family = NFPROTO_UNSPEC, .match = u32_mt, + .checkentry = u32_mt_checkentry, .matchsize = sizeof(struct xt_u32), .me = THIS_MODULE, };