Received: by 2002:a17:90a:1609:0:0:0:0 with SMTP id n9csp853138pja; Wed, 1 Apr 2020 09:52:23 -0700 (PDT) X-Google-Smtp-Source: APiQypIbVEt1uWzVUbEFpCK8Qv6GHwlxj4NKiou1GVWGF+cRDArob9PrUV76YRoMm2kJcSBHymvz X-Received: by 2002:a54:4094:: with SMTP id i20mr3286910oii.141.1585759943709; Wed, 01 Apr 2020 09:52:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585759943; cv=none; d=google.com; s=arc-20160816; b=or6uh3cVxoLHfc/6yE+mJcTUVJxD29GYFdK7eOj8yNahvCp+QEvIQ1sAlZ0YosLVXr EwTCD1Bu3p3Cf7Nlaqd4N1NniuQvbrWGZwqu39vOWxDV4LeNtpSbEtLRht0KfKoZi2rj vYUd2lC6Dvd8qv5kYDeSj3DS0KU2elzHJGuCzbahlG7Uzg5Uqln7T0fqpilTjx/GvBqP dbgtM6TpqC+/7pgwbAmpuyHj0rFKs801HxIE4IH43GFUYerc4yGZrnAkV6ERqYaf5e/3 D4wFyJ3YFcSCEv44reIQYoKmJS7qpyPlel/qCj6rX31grxJzaeljNVK6mmWtBH4IK0aB XSdw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=QqZkKrEGH8df0yahdINvbm0XsF4QJt8fWfJbknoG4wY=; b=EwaHsP0JBhHk8VwZ3UkOuja61/2vOfNM15clYu2+WovIoTL9SoXNLBBOKkfH+BBGOp YlF+Rhk5cu4b5yAccAmEeXesExqst7M3N+jZhtdfK+WX7RfwE+wRNPL3tFFC3EPRnRhQ QZZtsa2ZqlR/i9XoskwUnoTLBXCv4XB2d179HltGF/OX9HJikz50iZtl0eBJu6kdLgdj 8A82sYKDBR3QD3e8g8cYxjkE91utJrz4FECHvR0A8Q/s2LdMPwBfwud9m7UDbTXNKODG 0FUEu4X2KkOryde26K07ssIuOHtDjrQTkOoDxp/U65vdKrA3Wnt1QgtA4BESEu9qXX9m FV+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=XT1ofjTE; 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 z62si1116984oiz.23.2020.04.01.09.52.11; Wed, 01 Apr 2020 09:52:23 -0700 (PDT) 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=@kernel.org header.s=default header.b=XT1ofjTE; 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 S2389007AbgDAQhq (ORCPT + 99 others); Wed, 1 Apr 2020 12:37:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:36928 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388988AbgDAQhl (ORCPT ); Wed, 1 Apr 2020 12:37:41 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7B3D220772; Wed, 1 Apr 2020 16:37:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1585759060; bh=hftGqCuUIIoAdqQDcd+Mev2Z/qHi/EBRpyd3Yv4Zl9M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XT1ofjTExs5KYZPemBI1T65vie3JJrKi74rxDjb+83gYLY92TcKtPy+1RSwpQ80rD X0dfTpTz2eMrFtXscU+IMft2/GuO5qTg79Vikt9bqmI5UmnGd6IW466a1iU3bI76xF jdraH111yOG2nl+mxKbt45fLTygt3CrvSVgCceho= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Edward Cree , Thomas Gleixner , Ben Hutchings Subject: [PATCH 4.9 064/102] genirq: Fix reference leaks on irq affinity notifiers Date: Wed, 1 Apr 2020 18:18:07 +0200 Message-Id: <20200401161543.662169807@linuxfoundation.org> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200401161530.451355388@linuxfoundation.org> References: <20200401161530.451355388@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Edward Cree commit df81dfcfd6991d547653d46c051bac195cd182c1 upstream. The handling of notify->work did not properly maintain notify->kref in two cases: 1) where the work was already scheduled, another irq_set_affinity_locked() would get the ref and (no-op-ly) schedule the work. Thus when irq_affinity_notify() ran, it would drop the original ref but not the additional one. 2) when cancelling the (old) work in irq_set_affinity_notifier(), if there was outstanding work a ref had been got for it but was never put. Fix both by checking the return values of the work handling functions (schedule_work() for (1) and cancel_work_sync() for (2)) and put the extra ref if the return value indicates preexisting work. Fixes: cd7eab44e994 ("genirq: Add IRQ affinity notifiers") Fixes: 59c39840f5ab ("genirq: Prevent use-after-free and work list corruption") Signed-off-by: Edward Cree Signed-off-by: Thomas Gleixner Acked-by: Ben Hutchings Link: https://lkml.kernel.org/r/24f5983f-2ab5-e83a-44ee-a45b5f9300f5@solarflare.com Signed-off-by: Greg Kroah-Hartman --- kernel/irq/manage.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) --- a/kernel/irq/manage.c +++ b/kernel/irq/manage.c @@ -233,7 +233,11 @@ int irq_set_affinity_locked(struct irq_d if (desc->affinity_notify) { kref_get(&desc->affinity_notify->kref); - schedule_work(&desc->affinity_notify->work); + if (!schedule_work(&desc->affinity_notify->work)) { + /* Work was already scheduled, drop our extra ref */ + kref_put(&desc->affinity_notify->kref, + desc->affinity_notify->release); + } } irqd_set(data, IRQD_AFFINITY_SET); @@ -333,7 +337,10 @@ irq_set_affinity_notifier(unsigned int i raw_spin_unlock_irqrestore(&desc->lock, flags); if (old_notify) { - cancel_work_sync(&old_notify->work); + if (cancel_work_sync(&old_notify->work)) { + /* Pending work had a ref, put that one too */ + kref_put(&old_notify->kref, old_notify->release); + } kref_put(&old_notify->kref, old_notify->release); }