Commit 5595683d authored by Jann Horn's avatar Jann Horn Committed by Stefan Bader

netfilter: nf_log: don't hold nf_log_mutex during user access

BugLink: https://bugs.launchpad.net/bugs/1784409

commit ce00bf07 upstream.

The old code would indefinitely block other users of nf_log_mutex if
a userspace access in proc_dostring() blocked e.g. due to a userfaultfd
region. Fix it by moving proc_dostring() out of the locked region.

This is a followup to commit 266d07cb ("netfilter: nf_log: fix
sleeping function called from invalid context"), which changed this code
from using rcu_read_lock() to taking nf_log_mutex.

Fixes: 266d07cb ("netfilter: nf_log: fix sleeping function calle[...]")
Signed-off-by: default avatarJann Horn <jannh@google.com>
Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarKleber Sacilotto de Souza <kleber.souza@canonical.com>
Signed-off-by: default avatarKhalid Elmously <khalid.elmously@canonical.com>
parent 04f28ad3
...@@ -437,14 +437,17 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write, ...@@ -437,14 +437,17 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,
rcu_assign_pointer(net->nf.nf_loggers[tindex], logger); rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
mutex_unlock(&nf_log_mutex); mutex_unlock(&nf_log_mutex);
} else { } else {
struct ctl_table tmp = *table;
tmp.data = buf;
mutex_lock(&nf_log_mutex); mutex_lock(&nf_log_mutex);
logger = nft_log_dereference(net->nf.nf_loggers[tindex]); logger = nft_log_dereference(net->nf.nf_loggers[tindex]);
if (!logger) if (!logger)
table->data = "NONE"; strlcpy(buf, "NONE", sizeof(buf));
else else
table->data = logger->name; strlcpy(buf, logger->name, sizeof(buf));
r = proc_dostring(table, write, buffer, lenp, ppos);
mutex_unlock(&nf_log_mutex); mutex_unlock(&nf_log_mutex);
r = proc_dostring(&tmp, write, buffer, lenp, ppos);
} }
return r; return r;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment