Received: by 10.223.185.116 with SMTP id b49csp221725wrg; Tue, 20 Feb 2018 19:43:02 -0800 (PST) X-Google-Smtp-Source: AH8x225jdNN+7KSl78BsuSeqyQVJS01X53bmqejAf+xKyzoyTemPTD7Dz+dD1T7nNu88+yo/rd3N X-Received: by 2002:a17:902:bcc1:: with SMTP id o1-v6mr1824337pls.218.1519184582648; Tue, 20 Feb 2018 19:43:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519184582; cv=none; d=google.com; s=arc-20160816; b=y8HF7SxxyYghHuT5LwdOU//96XtAIFkhVkGQrGQYUawgkBBf1rOfU0qESly64q4MMf HX8787Z6LNLwua5vpApj5f6LLTKVJp+rc2y7/A/ZG+YZ84FQ7GPzoi0mf79LEMVM8TxI XBt3rGz8SwfNksiONdfYzs3HScoAYDPEgs3oZ9sNCoAbSx+1ob7wi4r1RVW9/MBl8xFJ xFTufB7seedeyXB4mFXPfXO2IaWg+Gn0q945YXupKeWUuWpg5iwB3hSFAiQ5bC5PBF5b O7ghd5jCVYSC/IGVdQ5rxak3haMkljVXJ4BAQWQBISOeR8CMeUqc/PfB63Lcs4eMKnpn L/eg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=1OIFE1DNQfIuTv+wB0cIlGL2LUl0oqZRE2/b62hQZyA=; b=C7hz7imHE3Y6WmT2V++ZssErEDGpDIhrvmt8GoaXuWRKw1JCrwZjRw3CeT259f2moV i0L98bjssXqniboUP1jtWpZYrHvgXZ4sS/Y/3ONsuik8vqjlHxy8YFSlhmULMW0mGfso 0e/0TmwQ7YLadrFscw4GhQNZPhRnISx9aHGI/b3agTqwzywgFS4gm/LTga4RGRB9M6ZD EtvRrsdxUhgQD/6ZXGRSbPPxodJmZUjiri7aqpWrJLUgKsjhIRRe3ZJifT/k2JUxb51p 17bqp9a7CshI/1gP3ctTdNOMG9lAIpxaBQEAuwJY4xLH6vcLZa50/2Fzh0p52Y8b7uqP /Q+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@zx2c4.com header.s=mail header.b=l7Z1eRZZ; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zx2c4.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 89-v6si795681ple.640.2018.02.20.19.42.47; Tue, 20 Feb 2018 19:43:02 -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; dkim=pass header.i=@zx2c4.com header.s=mail header.b=l7Z1eRZZ; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zx2c4.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751340AbeBUDmK (ORCPT + 99 others); Tue, 20 Feb 2018 22:42:10 -0500 Received: from frisell.zx2c4.com ([192.95.5.64]:51897 "EHLO frisell.zx2c4.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751135AbeBUDmJ (ORCPT ); Tue, 20 Feb 2018 22:42:09 -0500 Received: by frisell.zx2c4.com (ZX2C4 Mail Server) with ESMTP id 5f1d81b7; Wed, 21 Feb 2018 03:25:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=zx2c4.com; h=from:to:cc :subject:date:message-id; s=mail; bh=yk2njD8T4LjowkmoaZO7H/Ta7no =; b=l7Z1eRZZZ/nEziWaBY/70QLwc46eOWnsFtSptu61PdtHYVGAmxwMpsy5vIk 7p2hOyE8ABt4SxWayFSyNZHxg5O4I1pAofZLxXKr6TZpbl+aHRXg3kArY47P3jq1 QzUDrqMUItZch+i/43VTCNviWfkqTCQLcQLtNgdXADCw5/ErH5omaVc0NRTaDT5L JF2VoW8OtLCSFpnfLuEw3rJOcUtQV6/5PsJwLbOfgOtnw8853Radc6bxZFMm82QL eJYUaqcSAeFD4twETZ7nCjTyhgleRY4bjjQSB4QeIyvKznwx4pL52FRJoOHZnqur 6RLfo9z0G4g25fscuuBa1+BSFCg== Received: by frisell.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id 47a7ed61 (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256:NO); Wed, 21 Feb 2018 03:25:35 +0000 (UTC) From: "Jason A. Donenfeld" To: davem@davemloft.net, johannes.berg@intel.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: "Jason A. Donenfeld" Subject: [PATCH] netlink: put module reference if dump start fails Date: Wed, 21 Feb 2018 04:41:59 +0100 Message-Id: <20180221034159.14685-1-Jason@zx2c4.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Signed-off-by: Jason A. Donenfeld --- This probably should be queued up for stable. net/netlink/af_netlink.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c index 2ad445c1d27c..07e8478068f0 100644 --- a/net/netlink/af_netlink.c +++ b/net/netlink/af_netlink.c @@ -2308,7 +2308,7 @@ int __netlink_dump_start(struct sock *ssk, struct sk_buff *skb, if (cb->start) { ret = cb->start(cb); if (ret) - goto error_unlock; + goto error_put; } nlk->cb_running = true; @@ -2328,6 +2328,8 @@ int __netlink_dump_start(struct sock *ssk, struct sk_buff *skb, */ return -EINTR; +error_put: + module_put(control->module); error_unlock: sock_put(sk); mutex_unlock(nlk->cb_mutex); -- 2.16.1