netfilter: nf_log: don't hold nf_log_mutex during user access
Subsystems (3)
PATCH 1/1 netfilter: nf_log: don't hold nf_log_mutex during user access
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 266d07cb1c9a ("netfilter: nf_log: fix sleeping function called from invalid context"), which changed this code from using rcu_read_lock() to taking nf_log_mutex.
--- net/netfilter/nf_log.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
net/netfilter/nf_log.c +6 -3
@@ -442,14 +442,17 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,rcu_assign_pointer (net->nf.nf_loggers[tindex], logger);mutex_unlock (&nf_log_mutex); }else { +struct ctl_table tmp = *table; + + tmp.data = buf;mutex_lock (&nf_log_mutex); logger =nft_log_dereference (net->nf.nf_loggers[tindex]);if (!logger) - table->data ="NONE" ; +strlcpy (buf,"NONE" ,sizeof (buf));else - table->data = logger->name; - r =proc_dostring (table, write, buffer, lenp, ppos); +strlcpy (buf, logger->name,sizeof (buf));mutex_unlock (&nf_log_mutex); + r =proc_dostring (&tmp, write, buffer, lenp, ppos); }return r;
Signature · 1 line
2.18.0.rc2.346.g013aa6912e-goog
Quoted 7 lines · Jann Horn
The old code would indefinitely block other users of
nf_log_mutexif a userspace access inproc_dostring()blocked e.g. due to a userfaultfd region. Fix it by movingproc_dostring()out of the locked region.This is a followup to commit
266d07cb1c9a("netfilter:nf_log: fix sleeping function called from invalid context"), which changed this code from usingrcu_read_lock()to takingnf_log_mutex.
Applied.