Received: by 10.223.176.5 with SMTP id f5csp3355622wra; Mon, 29 Jan 2018 12:07:39 -0800 (PST) X-Google-Smtp-Source: AH8x226OHyxgT8LnLtT9QXeKyEF2sEJSt8v20cIQUS4Z4MhMGrwR3/oxGq60+b9PtZ46VYxsfnIs X-Received: by 10.101.96.198 with SMTP id r6mr22330407pgv.420.1517256459361; Mon, 29 Jan 2018 12:07:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517256459; cv=none; d=google.com; s=arc-20160816; b=Lzb5CJrYAVhgiiqfUXqAZXKeTQSXzozRlJvMHNL/5hMKUhCmaxAlJUKAcr9UnL7HuC XQFhBBRt7qidmMYcXjgBk5NIQ7gWqBDR5wnvsu+I9+d3KOOdWbRirJ2P0S8cjPHXxDkh ifJTGVdMex9f3+HsvCNUIETxPg9vBaFx7coEP5ElmWoHQuIaxfCSZjTcWC7fhX2AAHEk 4fMUzeuAtHbwc4Lygi+7e+zpAInpH65lR1a6fvtQqd8IMjar3eWcBiVEhsr9xeN63hzo cXtr0CWBoXKxRsQYtAbvtFGI/9WGI6DHpgBQtPGai9BqWzWjWgnkuYIjjhLBloidTd5W k8VA== 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=F6uD+N686pQO2Y+F5Opc43hekYrquC/J1upu7JKfBmo=; b=HYscFtGCCdSixbcVypo8NH4z9OqL+WkzkT/8gFg6eq31uGICU3PkU1nwdwt5MnEuPG aknpFEw+PIifzJgeYfqa7w5kX8hFsmwy/SZNQHVqU8h/x1JXBcGB5swA6rv5HIV0sDBF zGYvlYNV23fzhgMWasGO+wxPorZdseStpbcFnJsAycfEgViYpEeOedYf/g+yZ5/Gx1eL yYzHw/aKvRVvTyNhb06Da9bkmQMmBWIdz8pYvrhlb3fZvqElKuODqpdC3pE/ZYphkuMz oEGu9iCrKNiWCh1UzEYxH08p8Gao11aCqSCT3TulM7/iwWrynDXqCGC6jJM2gTZVkHi6 CkSA== 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 v11-v6si10052142plg.491.2018.01.29.12.07.25; Mon, 29 Jan 2018 12:07:39 -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 S1752763AbeA2UGi (ORCPT + 99 others); Mon, 29 Jan 2018 15:06:38 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:48578 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752723AbeA2UGf (ORCPT ); Mon, 29 Jan 2018 15:06:35 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id A19EB2FA1; Mon, 29 Jan 2018 13:06:17 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Guillaume Nault , "David S. Miller" Subject: [PATCH 4.9 49/66] ppp: unlock all_ppp_mutex before registering device Date: Mon, 29 Jan 2018 13:57:13 +0100 Message-Id: <20180129123842.470749789@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180129123839.842860149@linuxfoundation.org> References: <20180129123839.842860149@linuxfoundation.org> User-Agent: quilt/0.65 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: Guillaume Nault [ Upstream commit 0171c41835591e9aa2e384b703ef9a6ae367c610 ] ppp_dev_uninit(), which is the .ndo_uninit() handler of PPP devices, needs to lock pn->all_ppp_mutex. Therefore we mustn't call register_netdevice() with pn->all_ppp_mutex already locked, or we'd deadlock in case register_netdevice() fails and calls .ndo_uninit(). Fortunately, we can unlock pn->all_ppp_mutex before calling register_netdevice(). This lock protects pn->units_idr, which isn't used in the device registration process. However, keeping pn->all_ppp_mutex locked during device registration did ensure that no device in transient state would be published in pn->units_idr. In practice, unlocking it before calling register_netdevice() doesn't change this property: ppp_unit_register() is called with 'ppp_mutex' locked and all searches done in pn->units_idr hold this lock too. Fixes: 8cb775bc0a34 ("ppp: fix device unregistration upon netns deletion") Reported-and-tested-by: syzbot+367889b9c9e279219175@syzkaller.appspotmail.com Signed-off-by: Guillaume Nault Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- drivers/net/ppp/ppp_generic.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) --- a/drivers/net/ppp/ppp_generic.c +++ b/drivers/net/ppp/ppp_generic.c @@ -1002,17 +1002,18 @@ static int ppp_unit_register(struct ppp if (!ifname_is_set) snprintf(ppp->dev->name, IFNAMSIZ, "ppp%i", ppp->file.index); + mutex_unlock(&pn->all_ppp_mutex); + ret = register_netdevice(ppp->dev); if (ret < 0) goto err_unit; atomic_inc(&ppp_unit_count); - mutex_unlock(&pn->all_ppp_mutex); - return 0; err_unit: + mutex_lock(&pn->all_ppp_mutex); unit_put(&pn->units_idr, ppp->file.index); err: mutex_unlock(&pn->all_ppp_mutex);