Received: by 10.223.185.111 with SMTP id b44csp906323wrg; Fri, 9 Mar 2018 16:31:43 -0800 (PST) X-Google-Smtp-Source: AG47ELtd0cED5/8dAtnB/9VErYhGXo6+OgjE0rUQHUqqUjTHPi2ibx/YmCWyO4KW51+sBkIpChEX X-Received: by 2002:a17:902:3041:: with SMTP id u59-v6mr329677plb.115.1520641903111; Fri, 09 Mar 2018 16:31:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520641903; cv=none; d=google.com; s=arc-20160816; b=Ld87fCKpOVkBbayaiamgLBL5r9HNxBgb7ecRVFhUaIUVDYM8/W1zsZrypxSpByrpN4 cFpPfOdlMj0Ud1kWFowjhCXcAp+UmkmUnuf9vslDYGt3kYhfmrxXXu40NMYPecoegOws YXRNYd2rXhxt4LVgIQSkt6Dq2B/myFOR7Xzk+rUpQ8kMd8gJ+u4YtndR3rxboX5X5Jr0 CwoYOeZa5kvAM/h98K+VCO6bAeXpFl+hmdMo3jnjB6Ejb6/hrzi25R3Q8udI+sOfY55A MD90kQ6voPMzV9Rbb5WeE/joKj1Yf8KivqfNJBIJx5BEfeZWnTpYHwJTGtS42ilre8QC 3APA== 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=MiH8G+xyT5ULpHbtY4m6IdHgr87CItHot2jnNxA0peU=; b=qgBxyINYrO1ojFLD+qxoWCZm5qcjj917222qpzj/j3HfaTUkNg3zLbpeYYYVi1FuhU G+4a56UFGv5sAPisD8ND5WDMKVfW+gRDzl4YESzEdMbQRJ5P0XVhNw/4d5VGTRHNeT6n tA6TMlIl/BGacESbHoRXg3WH2st5PdpG4Ttq3q6SI3bVbB7wlcKcW4aifTdi3o0lE6+4 GwqQf0azcYl6BBEymyPzhynViIqzzPZhkc2duxV+TfYg6DbVGXmS3vwrO9to7n4CY1+r TtmqqH9NeDndmNqcCKVed807+Klk4j2JdCz5Z+6VGyZQk+wm3JLwAQj4PvXvabnOGqsw ObKw== 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 5-v6si1713035plt.371.2018.03.09.16.31.28; Fri, 09 Mar 2018 16:31:43 -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 S934056AbeCJA3n (ORCPT + 99 others); Fri, 9 Mar 2018 19:29:43 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:40244 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933990AbeCJAWy (ORCPT ); Fri, 9 Mar 2018 19:22:54 -0500 Received: from localhost (unknown [185.236.200.248]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 28BBC1198; Sat, 10 Mar 2018 00:22:54 +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.9 31/65] netlink: put module reference if dump start fails Date: Fri, 9 Mar 2018 16:18:31 -0800 Message-Id: <20180310001827.398247956@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180310001824.927996722@linuxfoundation.org> References: <20180310001824.927996722@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: Jason A. Donenfeld commit b87b6194be631c94785fe93398651e804ed43e28 upstream. 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 @@ -2258,7 +2258,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; @@ -2278,6 +2278,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);