Skip to content

Commit 6b10c16

Browse files
committed
netfilter: nf_tables: remove busy mark and gc batch API
jira VULN-597 subsystem-sync netfilter:nf_tables 4.18.0-534 commit-author Pablo Neira Ayuso <pablo@netfilter.org> commit a2dd023 upstream-diff cherry-pick occassionally pulls in big blobs of unrelated crap. I had to excise significant portions of code in the process of resolving the conflicts. As per usual in this netfilter series I have relied on 4.18.0-534 code as a source of truth. Ditch it, it has been replace it by the GC transaction API and it has no clients anymore. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org> (cherry picked from commit a2dd023) Signed-off-by: Greg Rose <g.v.rose@ciq.com>
1 parent 41f4e1e commit 6b10c16

File tree

2 files changed

+4
-120
lines changed

2 files changed

+4
-120
lines changed

include/net/netfilter/nf_tables.h

Lines changed: 3 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -740,62 +740,6 @@ int nft_set_elem_expr_clone(const struct nft_ctx *ctx, struct nft_set *set,
740740
void nft_set_elem_destroy(const struct nft_set *set, void *elem,
741741
bool destroy_expr);
742742

743-
/**
744-
* struct nft_set_gc_batch_head - nf_tables set garbage collection batch
745-
*
746-
* @rcu: rcu head
747-
* @set: set the elements belong to
748-
* @cnt: count of elements
749-
*/
750-
struct nft_set_gc_batch_head {
751-
struct rcu_head rcu;
752-
const struct nft_set *set;
753-
unsigned int cnt;
754-
};
755-
756-
#define NFT_SET_GC_BATCH_SIZE ((PAGE_SIZE - \
757-
sizeof(struct nft_set_gc_batch_head)) / \
758-
sizeof(void *))
759-
760-
/**
761-
* struct nft_set_gc_batch - nf_tables set garbage collection batch
762-
*
763-
* @head: GC batch head
764-
* @elems: garbage collection elements
765-
*/
766-
struct nft_set_gc_batch {
767-
struct nft_set_gc_batch_head head;
768-
void *elems[NFT_SET_GC_BATCH_SIZE];
769-
};
770-
771-
struct nft_set_gc_batch *nft_set_gc_batch_alloc(const struct nft_set *set,
772-
gfp_t gfp);
773-
void nft_set_gc_batch_release(struct rcu_head *rcu);
774-
775-
static inline void nft_set_gc_batch_complete(struct nft_set_gc_batch *gcb)
776-
{
777-
if (gcb != NULL)
778-
call_rcu(&gcb->head.rcu, nft_set_gc_batch_release);
779-
}
780-
781-
static inline struct nft_set_gc_batch *
782-
nft_set_gc_batch_check(const struct nft_set *set, struct nft_set_gc_batch *gcb,
783-
gfp_t gfp)
784-
{
785-
if (gcb != NULL) {
786-
if (gcb->head.cnt + 1 < ARRAY_SIZE(gcb->elems))
787-
return gcb;
788-
nft_set_gc_batch_complete(gcb);
789-
}
790-
return nft_set_gc_batch_alloc(set, gfp);
791-
}
792-
793-
static inline void nft_set_gc_batch_add(struct nft_set_gc_batch *gcb,
794-
void *elem)
795-
{
796-
gcb->elems[gcb->head.cnt++] = elem;
797-
}
798-
799743
struct nft_expr_ops;
800744
/**
801745
* struct nft_expr_type - nf_tables expression type
@@ -1412,47 +1356,12 @@ static inline void nft_set_elem_change_active(const struct net *net,
14121356
ext->genmask ^= nft_genmask_next(net);
14131357
}
14141358

1415-
/*
1416-
* We use a free bit in the genmask field to indicate the element
1417-
* is busy, meaning it is currently being processed either by
1418-
* the netlink API or GC.
1419-
*
1420-
* Even though the genmask is only a single byte wide, this works
1421-
* because the extension structure if fully constant once initialized,
1422-
* so there are no non-atomic write accesses unless it is already
1423-
* marked busy.
1424-
*/
1425-
#define NFT_SET_ELEM_BUSY_MASK (1 << 2)
1426-
1427-
#if defined(__LITTLE_ENDIAN_BITFIELD)
1428-
#define NFT_SET_ELEM_BUSY_BIT 2
1429-
#elif defined(__BIG_ENDIAN_BITFIELD)
1430-
#define NFT_SET_ELEM_BUSY_BIT (BITS_PER_LONG - BITS_PER_BYTE + 2)
1431-
#else
1432-
#error
1433-
#endif
1434-
1435-
static inline int nft_set_elem_mark_busy(struct nft_set_ext *ext)
1436-
{
1437-
unsigned long *word = (unsigned long *)ext;
1438-
1439-
BUILD_BUG_ON(offsetof(struct nft_set_ext, genmask) != 0);
1440-
return test_and_set_bit(NFT_SET_ELEM_BUSY_BIT, word);
1441-
}
1442-
1443-
static inline void nft_set_elem_clear_busy(struct nft_set_ext *ext)
1444-
{
1445-
unsigned long *word = (unsigned long *)ext;
1446-
1447-
clear_bit(NFT_SET_ELEM_BUSY_BIT, word);
1448-
}
1449-
1450-
#define NFT_SET_ELEM_DEAD_MASK (1 << 3)
1359+
#define NFT_SET_ELEM_DEAD_MASK (1 << 2)
14511360

14521361
#if defined(__LITTLE_ENDIAN_BITFIELD)
1453-
#define NFT_SET_ELEM_DEAD_BIT 3
1362+
#define NFT_SET_ELEM_DEAD_BIT 2
14541363
#elif defined(__BIG_ENDIAN_BITFIELD)
1455-
#define NFT_SET_ELEM_DEAD_BIT (BITS_PER_LONG - BITS_PER_BYTE + 3)
1364+
#define NFT_SET_ELEM_DEAD_BIT (BITS_PER_LONG - BITS_PER_BYTE + 2)
14561365
#else
14571366
#error
14581367
#endif

net/netfilter/nf_tables_api.c

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5630,7 +5630,7 @@ static int nft_add_set_elem(struct nft_ctx *ctx, struct nft_set *set,
56305630
goto err_elem_expr;
56315631
}
56325632

5633-
ext->genmask = nft_genmask_cur(ctx->net) | NFT_SET_ELEM_BUSY_MASK;
5633+
ext->genmask = nft_genmask_cur(ctx->net);
56345634
err = set->ops->insert(ctx->net, set, &elem, &ext2);
56355635
if (err) {
56365636
if (err == -EEXIST) {
@@ -5947,31 +5947,6 @@ static int nf_tables_delsetelem(struct net *net, struct sock *nlsk,
59475947
return err;
59485948
}
59495949

5950-
void nft_set_gc_batch_release(struct rcu_head *rcu)
5951-
{
5952-
struct nft_set_gc_batch *gcb;
5953-
unsigned int i;
5954-
5955-
gcb = container_of(rcu, struct nft_set_gc_batch, head.rcu);
5956-
for (i = 0; i < gcb->head.cnt; i++)
5957-
nft_set_elem_destroy(gcb->head.set, gcb->elems[i], true);
5958-
kfree(gcb);
5959-
}
5960-
EXPORT_SYMBOL_GPL(nft_set_gc_batch_release);
5961-
5962-
struct nft_set_gc_batch *nft_set_gc_batch_alloc(const struct nft_set *set,
5963-
gfp_t gfp)
5964-
{
5965-
struct nft_set_gc_batch *gcb;
5966-
5967-
gcb = kzalloc(sizeof(*gcb), gfp);
5968-
if (gcb == NULL)
5969-
return gcb;
5970-
gcb->head.set = set;
5971-
return gcb;
5972-
}
5973-
EXPORT_SYMBOL_GPL(nft_set_gc_batch_alloc);
5974-
59755950
/*
59765951
* Stateful objects
59775952
*/

0 commit comments

Comments
 (0)