Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2006007imm; Tue, 10 Jul 2018 11:27:51 -0700 (PDT) X-Google-Smtp-Source: AAOMgpc0bJzJgZVz+VzuQVNWPPnzw5QUk2fah37JF7F9hJjqDFT7tmcwoVBDEdk/aN5zTAChaQ7j X-Received: by 2002:a63:aa44:: with SMTP id x4-v6mr24186268pgo.120.1531247270996; Tue, 10 Jul 2018 11:27:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531247270; cv=none; d=google.com; s=arc-20160816; b=tUbYpW03GeS1ldzil7Nf3uEQMgpum1tgj814137lPYWqBuWmWHHCg1AAuK9M8PS0QM HqcQhB2O7DyPMWeo38swutRW3zowTYYTRTQ9l0sktFFyaJl9WLAt/C7Dqwl8gvscEn6K 3ZRFWU8G9S54BwsPexcGEhCXXLpx3YQV6va+eyH4XPFr3m1HuPAQzSmUowEfgMTnf1yX AWkstF9Gu2Gkxp7O5u5Nv0FQoOWwKWR+8h9P0iF0RuR3OCe9vQL2O0nq7iKZDaCluXKe nuSnQcbRP5UmaWb/rkN9RDU3fFm2Y8f++XP2TUnfmp6wgrK6KAYfcX9yqDSfy1Jq2cx3 f6vQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=QY7V7yB8J58LaaaZoXNhP0ln1mrti2cr9z1xMFFLyp8=; b=lLKKXRYW+LjatO238rYQtlJdVABh6LN8k2xZBTDM0/BusSs3OjHkfhYK726PL+zM64 rO8nSSiaJc6i6KvCTwzo4u0I+74u9P6HKDCL7Nophug/hwE275Qr6DnHrSA8xx8rWXLI Ha0y8nEqJfwMwjWZhRZH0v+VkmORz5gIdEyR2Va1U/fE/Lfc2mJBzai0uaTJe0Copnau ebcAbcFg99kX+C75EvxrbFMSLjEinOzn8z/7aM1lhNH1M6OBYfVBaUqz25T6lMoUSX3s txRxl2O1W+xODVtg+s+yxhMEgX0DS5jaW3+t63U8K7UiIpSUuPWDwogczlpnkNHVH363 9uBg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i2-v6si6689408pgh.565.2018.07.10.11.27.35; Tue, 10 Jul 2018 11:27:50 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732832AbeGJS0j (ORCPT + 99 others); Tue, 10 Jul 2018 14:26:39 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:43790 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732387AbeGJS0j (ORCPT ); Tue, 10 Jul 2018 14:26:39 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id A2ADDE88; Tue, 10 Jul 2018 18:26:28 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jann Horn , Pablo Neira Ayuso Subject: [PATCH 3.18 23/23] netfilter: nf_log: dont hold nf_log_mutex during user access Date: Tue, 10 Jul 2018 20:24:56 +0200 Message-Id: <20180710182309.864863963@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180710182308.877332304@linuxfoundation.org> References: <20180710182308.877332304@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jann Horn commit ce00bf07cc95a57cd20b208e02b3c2604e532ae8 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 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. Fixes: 266d07cb1c9a ("netfilter: nf_log: fix sleeping function calle[...]") Signed-off-by: Jann Horn Signed-off-by: Pablo Neira Ayuso Signed-off-by: Greg Kroah-Hartman --- net/netfilter/nf_log.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) --- a/net/netfilter/nf_log.c +++ b/net/netfilter/nf_log.c @@ -387,14 +387,17 @@ static int nf_log_proc_dostring(struct c 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;