Received: by 10.223.185.116 with SMTP id b49csp5454858wrg; Wed, 7 Mar 2018 12:03:15 -0800 (PST) X-Google-Smtp-Source: AG47ELvBPygCm7kyeMxUcqD0DHX558dVAXRiERRNGj6Oa1HRg+X6qfitMDRQfxH+Dpogc93JkjzC X-Received: by 10.98.76.26 with SMTP id z26mr24021376pfa.220.1520452995865; Wed, 07 Mar 2018 12:03:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520452995; cv=none; d=google.com; s=arc-20160816; b=wW9IcbWQ8NNb14CrC1JDgYgyEP4u6wcN7VWkqsyXRIHcKgrdLR97Qx82MAdb9MUgNu 1/Lo8KHemupmQfLBKLd/NM8Y/77+rDKJ22fu0ilEt121Y8ZAjHgoKjY8KDFspA4Y8ndd CV0/J9i7Hhv7YtyGvHwUC4pu/YgQa63lph2Yjj1RGgNPW3INFqjopMJLHiMQxrxJSuSA iyw8aNY+IL2VkDCH4A3YSD+EkNBCvlHbUCMwDfAi3w4M0yEn8nKoz5Q/Gkb3irMJpGJ+ WNbZgUUWxbfgo5aoUxPDhRCkmA5S3b++oBdYLD6ZSeN7IuWJ+cH5yy1rXgIROF8pvzYP +yyg== 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=RbiYitNPdIPTtrEGn8Cgs6Ks1hNYhuXBYwNf4ZKXzlg=; b=jR+avO+bgyr1V3PfMtYgjTuUOzBNec2/DjTT5Y6fIaMRjWx5QRmi0gvPGYD3RMyzCR xu9G0cb14Ro+fOl6Lzdwq9CvgbU6wgu2XoApMFmJFL4Io5wSKbCVfzSxaH28XS8gASAh s0DiKg4kSLnQkwG1t3sEnpdp22mj1O+kvWbqLxnDxrnas2OFc/BeHk2s5TnD727cce1L SiJJWhjOHEK8Lz7dvi43ZmFiEc3xVORhS3T58ynZdp50qkwhnhpnFaCjqo9QyN7SJm5L exJQjXSblcQ0ZqFZdYf5TDHis+MEMXWECx6zLh6p7Fdm53esjj9K9LjWbpLcrEGQLuwg 4Jiw== 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 u13-v6si13169308plq.823.2018.03.07.12.03.00; Wed, 07 Mar 2018 12:03:15 -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 S965704AbeCGUCB (ORCPT + 99 others); Wed, 7 Mar 2018 15:02:01 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:44768 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965611AbeCGTqs (ORCPT ); Wed, 7 Mar 2018 14:46:48 -0500 Received: from localhost (unknown [185.236.200.248]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id BC87610BF; Wed, 7 Mar 2018 19:46:47 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Jason A. Donenfeld" , "David S. Miller" Subject: [PATCH 4.14 070/110] netlink: put module reference if dump start fails Date: Wed, 7 Mar 2018 11:38:53 -0800 Message-Id: <20180307191048.587694479@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180307191039.748351103@linuxfoundation.org> References: <20180307191039.748351103@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.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: "Jason A. Donenfeld" [ Upstream commit b87b6194be631c94785fe93398651e804ed43e28 ] Before, if cb->start() failed, the module reference would never be put, because cb->cb_running is intentionally false at this point. Users are generally annoyed by this because they can no longer unload modules that leak references. Also, it may be possible to tediously wrap a reference counter back to zero, especially since module.c still uses atomic_inc instead of refcount_inc. This patch expands the error path to simply call module_put if cb->start() fails. Fixes: 41c87425a1ac ("netlink: do not set cb_running if dump's start() errs") Signed-off-by: Jason A. Donenfeld Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/netlink/af_netlink.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) --- a/net/netlink/af_netlink.c +++ b/net/netlink/af_netlink.c @@ -2276,7 +2276,7 @@ int __netlink_dump_start(struct sock *ss if (cb->start) { ret = cb->start(cb); if (ret) - goto error_unlock; + goto error_put; } nlk->cb_running = true; @@ -2296,6 +2296,8 @@ int __netlink_dump_start(struct sock *ss */ return -EINTR; +error_put: + module_put(control->module); error_unlock: sock_put(sk); mutex_unlock(nlk->cb_mutex);