Received: by 2002:a17:90a:1609:0:0:0:0 with SMTP id n9csp848499pja; Wed, 1 Apr 2020 09:47:35 -0700 (PDT) X-Google-Smtp-Source: ADFU+vuBpYxycKckqhm+Ru8xW6lZT+XfNHzXIVdL48IC6XOtK7s8qF05/YR2bkzmac2/XY7jGzfN X-Received: by 2002:a05:6830:18eb:: with SMTP id d11mr17717185otf.243.1585759655079; Wed, 01 Apr 2020 09:47:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585759655; cv=none; d=google.com; s=arc-20160816; b=Iwyc1WPVAW8OTCrYePWpxuoSvtUGBycu2Ij/GjwQUr+grHp0EdYnZOzEElHwVBB59j eHtzzMiRi38q8MEG+LorSZ4QS1HfKp3rOlSA0bplH612MANmBGD1WXDRqK7VvwXVge+X VDM3miBfRO98ncgSBoS80lQrLhMRZE4KazpR1ZeYDHFqDkqjzHgCCf+K6/S1tQ8Ru/0w arsKz7vUtT9ltj/qN/nS2TOarK8RCPtEaLCqlJVoRUpuEpascGNfL7vQ1KjWrnIfape9 eKxk5FfkDy1bkEbwBWEryuPyer+4DRC7LkibZIQnR6yoaFKHEXfYDiIAEJYMpMBEvyKx YV3A== 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=Fho8Aibq2xfA62DWBdU2DBWCcmYeU60gJzhmb2eBySc=; b=vPc+MlfiOdJmqc6vLY3E3zke0vr4ypgyxAqIcRrNx0rFMkwHhGlYDG44EG9NsF3AWd EDubWhHNSTYN5vK21zDPkZJf3AcvxBOHo1QO/+uU0BH7Byl3juSuT/Dy03zp1mShKG8I ogHPQq1JyhzoI6GnflnzIPxpJjPP0RFsHhqyz8UQR8KEMb5oi6shSpKCuWSFaNvgcp0M Zy0bZFXQvHwtpiXbLfjl9BEVMuCcQJhv4026ecRmP7KHQ4+WunF/onJowkLZlV0Us/EC nYyPh7r/E+G5M0qi5BU3n0McCHyU8bQeQ7tczstfoc5WTDxReG0wgnoTebzmBRh+hQgp yPcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=fb871MTD; 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 t11si1081153oig.108.2020.04.01.09.47.22; Wed, 01 Apr 2020 09:47:35 -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=fb871MTD; 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 S2389503AbgDAQpM (ORCPT + 99 others); Wed, 1 Apr 2020 12:45:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:46352 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389823AbgDAQpJ (ORCPT ); Wed, 1 Apr 2020 12:45:09 -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 A964520719; Wed, 1 Apr 2020 16:45:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1585759509; bh=FJpKdcb6Tyjk/stNLsH5eg81JaWGyK3JQadgmibkM2E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fb871MTD9qPWm2m1d9O/UOo92Kk/52gz+3cu5h4R1lqjqXnEcYYJ4UwxFVWUD7J1/ dcQ7KIFrbbtyhGz7NvOLXZSVSNcPndUvZM8IHdP8SYGMJZl0gzGw/NApKM7pyiS+qh y1G2XOXDNdNpFffbSyL1bUraNf79TNEI7hq7g23M= 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.14 102/148] genirq: Fix reference leaks on irq affinity notifiers Date: Wed, 1 Apr 2020 18:18:14 +0200 Message-Id: <20200401161602.552704822@linuxfoundation.org> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200401161552.245876366@linuxfoundation.org> References: <20200401161552.245876366@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 @@ -224,7 +224,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); @@ -324,7 +328,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); }