Skip to content

Commit 5b65178

Browse files
author
Florian Westphal
committed
netfilter: nft_set_pipapo: use GFP_KERNEL for insertions
An earlier attempt changed this to GFP_KERNEL, but the get helper is also called for get requests from userspace, which uses rcu. Let the caller pass in the kmalloc flags to allow insertions to schedule if needed. Suggested-by: Pablo Neira Ayuso <[email protected]> Signed-off-by: Florian Westphal <[email protected]>
1 parent 9f439bd commit 5b65178

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

net/netfilter/nft_set_pipapo.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,7 @@ bool nft_pipapo_lookup(const struct net *net, const struct nft_set *set,
507507
* @data: Key data to be matched against existing elements
508508
* @genmask: If set, check that element is active in given genmask
509509
* @tstamp: timestamp to check for expired elements
510+
* @gfp: the type of memory to allocate (see kmalloc).
510511
*
511512
* This is essentially the same as the lookup function, except that it matches
512513
* key data against the uncommitted copy and doesn't use preallocated maps for
@@ -517,7 +518,7 @@ bool nft_pipapo_lookup(const struct net *net, const struct nft_set *set,
517518
static struct nft_pipapo_elem *pipapo_get(const struct net *net,
518519
const struct nft_set *set,
519520
const u8 *data, u8 genmask,
520-
u64 tstamp)
521+
u64 tstamp, gfp_t gfp)
521522
{
522523
struct nft_pipapo_elem *ret = ERR_PTR(-ENOENT);
523524
struct nft_pipapo *priv = nft_set_priv(set);
@@ -530,13 +531,13 @@ static struct nft_pipapo_elem *pipapo_get(const struct net *net,
530531
if (m->bsize_max == 0)
531532
return ret;
532533

533-
res_map = kmalloc_array(m->bsize_max, sizeof(*res_map), GFP_ATOMIC);
534+
res_map = kmalloc_array(m->bsize_max, sizeof(*res_map), gfp);
534535
if (!res_map) {
535536
ret = ERR_PTR(-ENOMEM);
536537
goto out;
537538
}
538539

539-
fill_map = kcalloc(m->bsize_max, sizeof(*res_map), GFP_ATOMIC);
540+
fill_map = kcalloc(m->bsize_max, sizeof(*res_map), gfp);
540541
if (!fill_map) {
541542
ret = ERR_PTR(-ENOMEM);
542543
goto out;
@@ -614,7 +615,8 @@ nft_pipapo_get(const struct net *net, const struct nft_set *set,
614615
struct nft_pipapo_elem *e;
615616

616617
e = pipapo_get(net, set, (const u8 *)elem->key.val.data,
617-
nft_genmask_cur(net), get_jiffies_64());
618+
nft_genmask_cur(net), get_jiffies_64(),
619+
GFP_ATOMIC);
618620
if (IS_ERR(e))
619621
return ERR_CAST(e);
620622

@@ -1275,7 +1277,7 @@ static int nft_pipapo_insert(const struct net *net, const struct nft_set *set,
12751277
else
12761278
end = start;
12771279

1278-
dup = pipapo_get(net, set, start, genmask, tstamp);
1280+
dup = pipapo_get(net, set, start, genmask, tstamp, GFP_KERNEL);
12791281
if (!IS_ERR(dup)) {
12801282
/* Check if we already have the same exact entry */
12811283
const struct nft_data *dup_key, *dup_end;
@@ -1297,7 +1299,8 @@ static int nft_pipapo_insert(const struct net *net, const struct nft_set *set,
12971299

12981300
if (PTR_ERR(dup) == -ENOENT) {
12991301
/* Look for partially overlapping entries */
1300-
dup = pipapo_get(net, set, end, nft_genmask_next(net), tstamp);
1302+
dup = pipapo_get(net, set, end, nft_genmask_next(net), tstamp,
1303+
GFP_KERNEL);
13011304
}
13021305

13031306
if (PTR_ERR(dup) != -ENOENT) {
@@ -1865,7 +1868,8 @@ static void *pipapo_deactivate(const struct net *net, const struct nft_set *set,
18651868
{
18661869
struct nft_pipapo_elem *e;
18671870

1868-
e = pipapo_get(net, set, data, nft_genmask_next(net), nft_net_tstamp(net));
1871+
e = pipapo_get(net, set, data, nft_genmask_next(net),
1872+
nft_net_tstamp(net), GFP_KERNEL);
18691873
if (IS_ERR(e))
18701874
return NULL;
18711875

0 commit comments

Comments
 (0)