From patchwork Sat Sep 16 00:48:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cengiz Can X-Patchwork-Id: 1835327 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 4RnXcR3417z1yhP for ; Sat, 16 Sep 2023 10:53:43 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1qhJYv-0001Qw-DA; Sat, 16 Sep 2023 00:53:29 +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 1qhJWo-00083k-G3 for kernel-team@lists.ubuntu.com; Sat, 16 Sep 2023 00:51:19 +0000 Received: from mail-pf1-f200.google.com (mail-pf1-f200.google.com [209.85.210.200]) (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 4BAC83F665 for ; Sat, 16 Sep 2023 00:51:18 +0000 (UTC) Received: by mail-pf1-f200.google.com with SMTP id d2e1a72fcca58-68fe22b77b6so2396627b3a.1 for ; Fri, 15 Sep 2023 17:51:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694825476; x=1695430276; 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=Dwn9ZNEQqL+sdUARBZueX/hWa/ZgzEkHN8xkhY1DmGA=; b=kSerLdMMts5YmgbJsk9jU9W6Fj2roCaZCDH/2B2rHGl+VTnMmp+90V7DQS3Mpi8Ai2 o9etW85sp4Ii4DBDQM//RuP1jdGL/7Q1g5HxaGwp3lxXuS9iHcB+vQ3BDowXw2Q/4KRf 7inttuSzyXHi6eXPbD+ETzrrbX/HOQQQLntTaEq4vp8gtkk7LNHv78ofYuynxrBOTBr9 QRDcf5uT/mP4D4dq5pT+Yhloa7A1yRJLMBt/gtJ5kk0MwqEOPFlm8Jei3r6b/7+q8Vjw I+VyibPhvcpFLsLuVws+JxYq6+sYxgGVMd/ovGa/jBr9hKjazC/Q5PX+AlEPzUm2fhNU Q/pg== X-Gm-Message-State: AOJu0YxAIZ4UGogQCE4AqM2KHyFTHrUEbAqwCj7Td57yqoX+ITwlslLC 5Vt4DaVy8RvMQ0sPUkfFDkiFWo0/jMDv/8LNwwPTi9L+HDHrMdQczCeYdWvWjzZ87FP4E6au0wm xZfzDfVIWqb7IkRzKzLle8Wk86hQE5rRVtTTQJq9j28Tli+ZoIxeY X-Received: by 2002:a05:6a00:b4e:b0:68f:cba5:412d with SMTP id p14-20020a056a000b4e00b0068fcba5412dmr3958400pfo.32.1694825475905; Fri, 15 Sep 2023 17:51:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHrB1jPJVII5DWKS62ocu13XVBHkaIWsItzBjVgiDy79kX6fyhwlgXPmrvWJvu4TXCKEXI4KA== X-Received: by 2002:a05:6a00:b4e:b0:68f:cba5:412d with SMTP id p14-20020a056a000b4e00b0068fcba5412dmr3958387pfo.32.1694825475581; Fri, 15 Sep 2023 17:51:15 -0700 (PDT) Received: from localhost (uk.sesame.canonical.com. [185.125.190.60]) by smtp.gmail.com with ESMTPSA id fm25-20020a056a002f9900b0068782960099sm3486076pfb.22.2023.09.15.17.51.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 17:51:15 -0700 (PDT) From: Cengiz Can To: kernel-team@lists.ubuntu.com Subject: [SRU Jammy, OEM-6.0, OEM-6.1, Lunar] netfilter: nf_tables: don't fail inserts if duplicate has expired Date: Sat, 16 Sep 2023 03:48:32 +0300 Message-Id: <20230916004839.706452-23-cengiz.can@canonical.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230916004839.706452-1-cengiz.can@canonical.com> References: <20230916004839.706452-1-cengiz.can@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: Florian Westphal nftables selftests fail: run-tests.sh testcases/sets/0044interval_overlap_0 Expected: 0-2 . 0-3, got: W: [FAILED] ./testcases/sets/0044interval_overlap_0: got 1 Insertion must ignore duplicate but expired entries. Moreover, there is a strange asymmetry in nft_pipapo_activate: It refetches the current element, whereas the other ->activate callbacks (bitmap, hash, rhash, rbtree) use elem->priv. Same for .remove: other set implementations take elem->priv, nft_pipapo_remove fetches elem->priv, then does a relookup, remove this. I suspect this was the reason for the change that prompted the removal of the expired check in pipapo_get() in the first place, but skipping exired elements there makes no sense to me, this helper is used for normal get requests, insertions (duplicate check) and deactivate callback. In first two cases expired elements must be skipped. For ->deactivate(), this gets called for DELSETELEM, so it seems to me that expired elements should be skipped as well, i.e. delete request should fail with -ENOENT error. Fixes: 24138933b97b ("netfilter: nf_tables: don't skip expired elements during walk") Signed-off-by: Florian Westphal (cherry picked from commit 7845914f45f066497ac75b30c50dbc735e84e884) CVE-2023-4244 [cengizcan: fixes the fix commit] Signed-off-by: Cengiz Can --- net/netfilter/nft_set_pipapo.c | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/net/netfilter/nft_set_pipapo.c b/net/netfilter/nft_set_pipapo.c index a0490794085f..49d07e804a3e 100644 --- a/net/netfilter/nft_set_pipapo.c +++ b/net/netfilter/nft_set_pipapo.c @@ -566,6 +566,8 @@ static struct nft_pipapo_elem *pipapo_get(const struct net *net, goto out; if (last) { + if (nft_set_elem_expired(&f->mt[b].e->ext)) + goto next_match; if ((genmask && !nft_set_elem_active(&f->mt[b].e->ext, genmask))) goto next_match; @@ -600,17 +602,8 @@ static struct nft_pipapo_elem *pipapo_get(const struct net *net, static void *nft_pipapo_get(const struct net *net, const struct nft_set *set, const struct nft_set_elem *elem, unsigned int flags) { - struct nft_pipapo_elem *ret; - - ret = pipapo_get(net, set, (const u8 *)elem->key.val.data, + return pipapo_get(net, set, (const u8 *)elem->key.val.data, nft_genmask_cur(net)); - if (IS_ERR(ret)) - return ret; - - if (nft_set_elem_expired(&ret->ext)) - return ERR_PTR(-ENOENT); - - return ret; } /** @@ -1732,11 +1725,7 @@ static void nft_pipapo_activate(const struct net *net, const struct nft_set *set, const struct nft_set_elem *elem) { - struct nft_pipapo_elem *e; - - e = pipapo_get(net, set, (const u8 *)elem->key.val.data, 0); - if (IS_ERR(e)) - return; + struct nft_pipapo_elem *e = elem->priv; nft_set_elem_change_active(net, set, &e->ext); } @@ -1950,10 +1939,6 @@ static void nft_pipapo_remove(const struct net *net, const struct nft_set *set, data = (const u8 *)nft_set_ext_key(&e->ext); - e = pipapo_get(net, set, data, 0); - if (IS_ERR(e)) - return; - while ((rules_f0 = pipapo_rules_same_key(m->f, first_rule))) { union nft_pipapo_map_bucket rulemap[NFT_PIPAPO_MAX_FIELDS]; const u8 *match_start, *match_end;