Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3321431imu; Sun, 11 Nov 2018 12:19:20 -0800 (PST) X-Google-Smtp-Source: AJdET5ev+r2vWyVdloTl9b/9dInin3LPSn9hDO40FJsVtFczUTJMRBZYzgvyhQ7PCy1VgMbgV+3U X-Received: by 2002:a62:d703:: with SMTP id b3-v6mr17647531pfh.90.1541967560766; Sun, 11 Nov 2018 12:19:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541967560; cv=none; d=google.com; s=arc-20160816; b=VW7NWv0zlh2zlhAy1HvpKyc9FBvzpCGXNpLtqa+XrRQ69EghHRUFiXmzgn53f7McVm YktyrFFPAVrx64nGoD19yMJxk1ZmOf/phMYsRGp95a7jQQmhh6dK3Ur6aq1c4aYomsa1 +DNVl0OBgerst/ICAVmBRFiZzv8Jbq+RsLKgEEyTxmEwp1x3bjUvhVDeSbx7JnaBjKP/ 5fPQmxdqtOwYHCOWD7Bfikz0z8L5YDlB1qHb32UN4GJk2d6GG/jXIgC/qJdXnmsNcpGs GNQv7RYP0d7InqgQPEFZrmaTpZJ0EjHJLJ7CKPCrvWgSh6tvHpGT0TwsKTjJJhGxLylk 6dtw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=Lsuc3anD2WgQVgSM4rOtfgUublTpXVxNbolYuN1UlN4=; b=a0wAEdKkvmQ34OuqPLTlu08HC54N8Gfh3hsZY37vFeQAWXhQl3va9wXfh/eXaqs/0e iLYfje8krhOJPt0oG5hkg4ACDtKrHrha/5zL6vkVCmWpgNQHV8V5ObBRnE2ckLpTTHEm zorjIx6ngTDqQ6CwofHrflkxGAPV1VnM3YzuWik8ihh6DF0KTHT8JaSMG8qkQbnhqwC2 9voosl+79D3lXEGPECjzEYSl+N8MPM751f1Tcez3gz9UluIUAXKzkkzwyMjT+xtQTiyl LIImJupaujoRXR9RC9IXojNMn8gPl+09uoSa7YVOxZeqXNzRH7I//WCG67Igm2kAlEmb MUyA== 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 d25si5087876pgd.88.2018.11.11.12.19.05; Sun, 11 Nov 2018 12:19:20 -0800 (PST) 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 S1731804AbeKLGFN (ORCPT + 99 others); Mon, 12 Nov 2018 01:05:13 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:53050 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731042AbeKLGFN (ORCPT ); Mon, 12 Nov 2018 01:05:13 -0500 Received: from [192.168.4.242] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1gLvsx-0000oJ-03; Sun, 11 Nov 2018 19:59:07 +0000 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1gLvsU-0001dj-GD; Sun, 11 Nov 2018 19:58:38 +0000 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Jann Horn" , "Pablo Neira Ayuso" Date: Sun, 11 Nov 2018 19:49:05 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 200/366] netfilter: nf_log: don't hold nf_log_mutex during user access In-Reply-To: X-SA-Exim-Connect-IP: 192.168.4.242 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.61-rc1 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 [bwh: Backported to 3.16: adjust context] Signed-off-by: Ben Hutchings --- 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 @@ -273,15 +273,18 @@ 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 = rcu_dereference_protected(net->nf.nf_loggers[tindex], lockdep_is_held(&nf_log_mutex)); 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;