Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2024721imm; Tue, 10 Jul 2018 11:49:38 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfzBQssZKOFYsFd3voLhrUyaUg9Suvzr+r4RLA9Om5G8/Z+HUWFFJ/e2DZg0zLo6rJVhRSU X-Received: by 2002:a65:5784:: with SMTP id b4-v6mr17880980pgr.315.1531248578672; Tue, 10 Jul 2018 11:49:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531248578; cv=none; d=google.com; s=arc-20160816; b=z3bz9XwxDo08YRByQsQLcCbx1IHtX8b/K4eM9+gnu0tWnp8xuOcyLTkSOdz5SSmndH 1a9mJTH2i+wW3oI351lHsLXpM/0yEO0EViRvGR+mA5L4wR69G8CQa+krHllZBCUAbOk+ nW3qTaN4aA9jP+MMnvmFxHxDwu4XHwXXajOpI5rGK5pbICFfilMA3icevKoIvztftY5k odgG53WPga+GpdKy2naUH+uH6xu6QLs4ADcgh8Ty3T1d9BCha/9LakFI7hoEOrm7FIkm VosTBOPpuqjuB4l6k3Dq+GWRCqTZ+6bHBds9rSfBiHGqPvQlznYPx1XhPeQaYm8odxPL tB4w== 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=G6fH9z4NY8hdFXuaDoQ+UeD3Jx9CLwBaR91T5JmkoNA=; b=m8MrZ02zvSSujHfr9nuntQwGZwoRKGYcDDsLEpeFapxN762m2+q3ZjOKAfgTpK5EFX uabyUjlWiceYh0XPqTE6QWB5La78AGZC97thtXcibHCAEkwJpbQ16ii3WYk2OZU8Cepq 3ITkqHTN2d9XdHXMzjtZzafYb8WmuhrEcwadrssgCxJ3ngG1TjLL0y6XNz/VIDh6FawP imzJX4jpg5NplwRBy6xLyPMRmDjp8l5iHjTWHlxLz2DvgT6ydcxJhFVbORJAKrdEU17q hjmLu+MJxDglRAb4YA6DdFDZTdfXUIa150/opQWwItlFq7Y6uB66cyOrI9QMt8krAH1x 6VlA== 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 w26-v6si16968082pgk.372.2018.07.10.11.49.23; Tue, 10 Jul 2018 11:49:38 -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 S2388367AbeGJSb1 (ORCPT + 99 others); Tue, 10 Jul 2018 14:31:27 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:45836 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388357AbeGJSb0 (ORCPT ); Tue, 10 Jul 2018 14:31:26 -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 7AA0EEC7; Tue, 10 Jul 2018 18:31:14 +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 4.9 51/52] netfilter: nf_log: dont hold nf_log_mutex during user access Date: Tue, 10 Jul 2018 20:25:19 +0200 Message-Id: <20180710182454.060336361@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180710182449.285532226@linuxfoundation.org> References: <20180710182449.285532226@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 4.9-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 @@ -444,14 +444,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;