Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp7274181ybh; Thu, 8 Aug 2019 12:57:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqwI18BAVw/bnA1tWkAcoKbHO6mSy8n0VO4fTyMGEZ0DDioOPl1I/CGtQeLZFjgRYHD7WGx8 X-Received: by 2002:a62:107:: with SMTP id 7mr17512833pfb.4.1565294230708; Thu, 08 Aug 2019 12:57:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565294230; cv=none; d=google.com; s=arc-20160816; b=Ev5tSSPTU9l5/55uYSe/jX4q73Pe7noEv0jCiB9J0agna/OM6KtaMfCrSlJzBlPJF9 9N+OyOBn6aJC5qvrLgGwTFzruns3aB6/lVXGtObNqcIc7fDSVd59mMmSoz+O/7mrNYAG CozM+Vks+FiAi+PWzbT8xBmOkkTavStefYLlPoCn71tHDIW8GATezkPaR4HRdc76smE1 nCS0Aors3Qw7EauOvkan8GUNl/KznP4FdG3hPSLdOFeiC5mwYcbJ0zKE3qaXEgkMBQio Nu6SMj2fN+1xB/riwjebhChtNRR8Wp/YY2+0BrXWEpvfjcbvEPwspjyITzCXO3meEfiT E1Gg== 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 :message-id:in-reply-to:subject:cc:to:from:date; bh=rSZ04y1ePflseqG0olI3qEtv/gGUAVyHyiwnsQwYUtY=; b=XsujXeDKj5RA3J7uwOIo9/w8AqrHw9OdLsktFogwpHJ9XyWSLYhCIfOtJM/6Ayx5Fj fqr6yF0t1+F3QZfrsDrVHezvoATEtYIaCdoHBE8IN6vge97ePrbB8RqXQ1lv77ua3xva oOt8PtJb/OpBjbP8rKMyTtgiP3JniD3NVp4DOY6a2osLt9j7zgifxhTigDpxDSM36JeE bgDn5gZSfD2etzh9zVUbRdR9s/PvuypTFZhvo53455roZDl6Mwkm5Xl9KPuxWO18ZLdN zqm3iuuAyHWuXHToQ/SFNa3xbbAxFBOMzkRgcSHoz0hPtnLkezOztnjHspIl80JcEW4t 38sA== 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 k73si49460968pge.353.2019.08.08.12.56.55; Thu, 08 Aug 2019 12:57:10 -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; 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 S2404241AbfHHT4W (ORCPT + 99 others); Thu, 8 Aug 2019 15:56:22 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:54081 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390201AbfHHT4W (ORCPT ); Thu, 8 Aug 2019 15:56:22 -0400 Received: from p200300ddd71876597e7a91fffec98e25.dip0.t-ipconnect.de ([2003:dd:d718:7659:7e7a:91ff:fec9:8e25]) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1hvoWJ-00079W-LP; Thu, 08 Aug 2019 21:56:19 +0200 Date: Thu, 8 Aug 2019 21:56:14 +0200 (CEST) From: Thomas Gleixner To: Ben Luo cc: alex.williamson@redhat.com, linux-kernel@vger.kernel.org, tao.ma@linux.alibaba.com, gerry@linux.alibaba.com Subject: Re: [PATCH 1/2] genirq: introduce update_irq_devid() In-Reply-To: <39a5009c77d07c3ce42ef784465c05e36d5f684d.1565263723.git.luoben@linux.alibaba.com> Message-ID: References: <39a5009c77d07c3ce42ef784465c05e36d5f684d.1565263723.git.luoben@linux.alibaba.com> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 8 Aug 2019, Ben Luo wrote: > +int update_irq_devid(unsigned int irq, void *dev_id, void *new_dev_id) > +{ > + struct irq_desc *desc = irq_to_desc(irq); > + struct irqaction *action, **action_ptr; > + unsigned long flags; > + > + WARN(in_interrupt(), > + "Trying to update IRQ %d from IRQ context!\n", irq); This is broken. The function needs to return on that condition. Actually it cannot even be called from non-preemptible code. What's worse is that if the interrupt in question is handled concurrently, then it will either see the old or the new dev_id and because the interrupt handler loop runs with desc->lock dropped even more crap can happen because dev_id can be subject to load and store tearing. Staring at that, I see that there is the same issue in setup_irq() and free_irq(). It's actually worse there. I'll have a look. > + /* > + * There can be multiple actions per IRQ descriptor, find the right > + * one based on the dev_id: > + */ > + action_ptr = &desc->action; > + for (;;) { > + action = *action_ptr; > + > + if (!action) { > + WARN(1, "Trying to update already-free IRQ %d\n", irq); That's wrong in two aspects: 1) The warn should be outside of the locked region. 2) Just having the irq number is not useful for debugging either when the interrupt is shared. > + raw_spin_unlock_irqrestore(&desc->lock, flags); > + chip_bus_sync_unlock(desc); > + return -ENXIO; > + } > + > + if (action->dev_id == dev_id) { > + action->dev_id = new_dev_id; > + break; > + } > + action_ptr = &action->next; > + } > + > + raw_spin_unlock_irqrestore(&desc->lock, flags); > + chip_bus_sync_unlock(desc); > + > + /* > + * Make sure it's not being used on another CPU: > + * There is a risk of UAF for old *dev_id, if it is > + * freed in a short time after this func returns > + */ > + synchronize_irq(irq); > + > + return 0; > +} > +EXPORT_SYMBOL(update_irq_devid); EXPORT_SYMBOL_GPL() please. Thanks, tglx