From patchwork Thu Jul 14 21:28:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thadeu Lima de Souza Cascardo X-Patchwork-Id: 1656665 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=cAbDElcV; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LkSKZ6jm3z9s09 for ; Fri, 15 Jul 2022 07:28:50 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1oC6O6-000452-2t; Thu, 14 Jul 2022 21:28:46 +0000 Received: from smtp-relay-canonical-0.internal ([10.131.114.83] helo=smtp-relay-canonical-0.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1oC6O3-000434-Vl for kernel-team@lists.ubuntu.com; Thu, 14 Jul 2022 21:28:43 +0000 Received: from quatroqueijos.. (unknown [177.9.88.15]) (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-canonical-0.canonical.com (Postfix) with ESMTPSA id F1DE83F0E1 for ; Thu, 14 Jul 2022 21:28:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1657834122; bh=aMqRMe7rbL8hs81N6VfYJNxoHekzHDVwQiesMJRBouc=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=cAbDElcV7kcOrlQkUl0jLRXzIr3hEpDzRIdcrnvoOEZ1+qyPc/4/LrNsQNJjGMUDw hnahnMQwmuAS0uZt8LuVKKgB3EP/3WwMjLWCfIhnn/mUBjlwRqKeYL22RH3WifMb6r ICPXT0YRI74qWZyJH6OIVMIzU3OHmlqHMixJie1UrWzBp39b90PwECWpi44y58UfY7 EuztASV9LbYRQw9xXt2V8kMQ4s+aA8Nc4uU5qSeTrLyAV5P4BwwPHVdyeEMmrXxRy2 hyzKSIEDtW4zKYxCO07yWxTpXzecbAJUs4w0PARSBPjQiJeBlDG1mLTokPu7HAGgtN 9il1Dzyq8fzaQ== From: Thadeu Lima de Souza Cascardo To: kernel-team@lists.ubuntu.com Subject: [SRU Focal 1/1] netfilter: nf_tables: stricter validation of element data Date: Thu, 14 Jul 2022 18:28:28 -0300 Message-Id: <20220714212828.623587-3-cascardo@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220714212828.623587-1-cascardo@canonical.com> References: <20220714212828.623587-1-cascardo@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: Pablo Neira Ayuso Make sure element data type and length do not mismatch the one specified by the set declaration. Fixes: 7d7402642eaf ("netfilter: nf_tables: variable sized set element keys / data") Reported-by: Hugues ANGUELKOV Signed-off-by: Pablo Neira Ayuso CVE-2022-34918 (backported from commit 7e6bc1f6cabcd30aba0b11219d8e01b952eacbb6) [cengizcan: target function does not exist until 5.8 so follow history backwards, find previous place of length check and adapt the change for 5.4] Signed-off-by: Cengiz Can Signed-off-by: Thadeu Lima de Souza Cascardo --- net/netfilter/nf_tables_api.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c index 24f18d6a0a50..54efb96705e5 100644 --- a/net/netfilter/nf_tables_api.c +++ b/net/netfilter/nf_tables_api.c @@ -4531,6 +4531,7 @@ static int nft_add_set_elem(struct nft_ctx *ctx, struct nft_set *set, struct nft_data data; enum nft_registers dreg; struct nft_trans *trans; + u32 dtype; u32 flags = 0; u64 timeout; u64 expiration; @@ -4630,7 +4631,13 @@ static int nft_add_set_elem(struct nft_ctx *ctx, struct nft_set *set, goto err2; err = -EINVAL; - if (set->dtype != NFT_DATA_VERDICT && d2.len != set->dlen) + + if (set->dtype == NFT_DATA_VERDICT) + dtype = NFT_DATA_VERDICT; + else + dtype = NFT_DATA_VALUE; + + if (dtype != d2.type || set->dlen != d2.len) goto err3; dreg = nft_type_to_reg(set->dtype);