All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH nf] netfilter: nft_numgen: disable preempt to access per-cpu data
@ 2022-05-16  8:55 Pablo Neira Ayuso
  2022-05-18 14:03 ` Pablo Neira Ayuso
  0 siblings, 1 reply; 3+ messages in thread
From: Pablo Neira Ayuso @ 2022-05-16  8:55 UTC (permalink / raw)
  To: netfilter-devel; +Cc: fasnacht

[233241.951068] BUG: using smp_processor_id() in preemptible [00000000] code: nginx/2725
[233241.951220] caller is nft_ng_random_eval+0x24/0x54 [nft_numgen]
[233241.951225] CPU: 2 PID: 2725 Comm: nginx Tainted: G           OE 5.16.0-0.bpo.4-amd64 #1  Debian 5.16.12-1~bpo11+1
[233241.951227] Hardware name: Supermicro SYS-5039MC-H8TRF/X11SCD-F, BIOS 1.7 11/23/2021
[233241.951228] Call Trace:
[233241.951231]  <TASK>
[233241.951233]  dump_stack_lvl+0x48/0x5e
[233241.951236]  check_preemption_disabled+0xde/0xe0
[233241.951239]  nft_ng_random_eval+0x24/0x54 [nft_numgen]

Fixes: 978d8f9055c3 ("netfilter: nft_numgen: add map lookups for numgen random operations")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
See https://bugzilla.netfilter.org/show_bug.cgi?id=1603

 net/netfilter/nft_numgen.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/net/netfilter/nft_numgen.c b/net/netfilter/nft_numgen.c
index 81b40c663d86..78f860555c76 100644
--- a/net/netfilter/nft_numgen.c
+++ b/net/netfilter/nft_numgen.c
@@ -137,10 +137,15 @@ struct nft_ng_random {
 
 static u32 nft_ng_random_gen(struct nft_ng_random *priv)
 {
-	struct rnd_state *state = this_cpu_ptr(&nft_numgen_prandom_state);
+	struct rnd_state *state;
+	u32 ret;
 
-	return reciprocal_scale(prandom_u32_state(state), priv->modulus) +
-	       priv->offset;
+	preempt_disable();
+	state = this_cpu_ptr(&nft_numgen_prandom_state);
+	ret = reciprocal_scale(prandom_u32_state(state), priv->modulus) + priv->offset;
+	preempt_enable();
+
+	return ret;
 }
 
 static void nft_ng_random_eval(const struct nft_expr *expr,
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH nf] netfilter: nft_numgen: disable preempt to access per-cpu data
  2022-05-16  8:55 [PATCH nf] netfilter: nft_numgen: disable preempt to access per-cpu data Pablo Neira Ayuso
@ 2022-05-18 14:03 ` Pablo Neira Ayuso
  2022-05-18 15:35   ` Pablo Neira Ayuso
  0 siblings, 1 reply; 3+ messages in thread
From: Pablo Neira Ayuso @ 2022-05-18 14:03 UTC (permalink / raw)
  To: netfilter-devel; +Cc: fasnacht

On Mon, May 16, 2022 at 10:55:52AM +0200, Pablo Neira Ayuso wrote:
> [233241.951068] BUG: using smp_processor_id() in preemptible [00000000] code: nginx/2725
> [233241.951220] caller is nft_ng_random_eval+0x24/0x54 [nft_numgen]
> [233241.951225] CPU: 2 PID: 2725 Comm: nginx Tainted: G           OE 5.16.0-0.bpo.4-amd64 #1  Debian 5.16.12-1~bpo11+1
> [233241.951227] Hardware name: Supermicro SYS-5039MC-H8TRF/X11SCD-F, BIOS 1.7 11/23/2021
> [233241.951228] Call Trace:
> [233241.951231]  <TASK>
> [233241.951233]  dump_stack_lvl+0x48/0x5e
> [233241.951236]  check_preemption_disabled+0xde/0xe0
> [233241.951239]  nft_ng_random_eval+0x24/0x54 [nft_numgen]

For the record, patch applied to nf.git

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH nf] netfilter: nft_numgen: disable preempt to access per-cpu data
  2022-05-18 14:03 ` Pablo Neira Ayuso
@ 2022-05-18 15:35   ` Pablo Neira Ayuso
  0 siblings, 0 replies; 3+ messages in thread
From: Pablo Neira Ayuso @ 2022-05-18 15:35 UTC (permalink / raw)
  To: netfilter-devel; +Cc: fasnacht

On Wed, May 18, 2022 at 04:03:00PM +0200, Pablo Neira Ayuso wrote:
> On Mon, May 16, 2022 at 10:55:52AM +0200, Pablo Neira Ayuso wrote:
> > [233241.951068] BUG: using smp_processor_id() in preemptible [00000000] code: nginx/2725
> > [233241.951220] caller is nft_ng_random_eval+0x24/0x54 [nft_numgen]
> > [233241.951225] CPU: 2 PID: 2725 Comm: nginx Tainted: G           OE 5.16.0-0.bpo.4-amd64 #1  Debian 5.16.12-1~bpo11+1
> > [233241.951227] Hardware name: Supermicro SYS-5039MC-H8TRF/X11SCD-F, BIOS 1.7 11/23/2021
> > [233241.951228] Call Trace:
> > [233241.951231]  <TASK>
> > [233241.951233]  dump_stack_lvl+0x48/0x5e
> > [233241.951236]  check_preemption_disabled+0xde/0xe0
> > [233241.951239]  nft_ng_random_eval+0x24/0x54 [nft_numgen]
> 
> For the record, patch applied to nf.git

I don't think my patch is correct, I should disable_bh instead.

I kept it back.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-05-18 15:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-16  8:55 [PATCH nf] netfilter: nft_numgen: disable preempt to access per-cpu data Pablo Neira Ayuso
2022-05-18 14:03 ` Pablo Neira Ayuso
2022-05-18 15:35   ` Pablo Neira Ayuso

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.