Skip to content

Commit ce00bf0

Browse files
thejhummakynes
authored andcommitted
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 266d07c ("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: 266d07c ("netfilter: nf_log: fix sleeping function calle[...]") Signed-off-by: Jann Horn <jannh@google.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
1 parent dffd22a commit ce00bf0

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

net/netfilter/nf_log.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -446,14 +446,17 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,
446446
rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
447447
mutex_unlock(&nf_log_mutex);
448448
} else {
449+
struct ctl_table tmp = *table;
450+
451+
tmp.data = buf;
449452
mutex_lock(&nf_log_mutex);
450453
logger = nft_log_dereference(net->nf.nf_loggers[tindex]);
451454
if (!logger)
452-
table->data = "NONE";
455+
strlcpy(buf, "NONE", sizeof(buf));
453456
else
454-
table->data = logger->name;
455-
r = proc_dostring(table, write, buffer, lenp, ppos);
457+
strlcpy(buf, logger->name, sizeof(buf));
456458
mutex_unlock(&nf_log_mutex);
459+
r = proc_dostring(&tmp, write, buffer, lenp, ppos);
457460
}
458461

459462
return r;

0 commit comments

Comments
 (0)