From nobody Tue Apr 16 15:02:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1584602137; cv=none; d=zohomail.com; s=zohoarc; b=My+2jdyUQS1MOb4hgnIDKtNY76QEJj64dov5xfnr/Qh4O+f9PXGteAcF/fP9q4kyvTTy6YRRCJdHy+ASc5UKUGc4dF7A0z2R8VNKNMt1ZkKTPfrx5DogXzfypO9FDsRZrAS2UX5OxSUy7EN52Kw+DU4iIjunvpnuDm0Cmk85asI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584602137; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=09x1c+MnH6EvuZC0AQwmh1MZtJhPS4WGOwDzwehXQMw=; b=OgZNNfVdAv/oW+fORdBA7mi94P7rN//rLrqk8xjUWqoefg/Apo4yapnJIuWLgELACLjmd8++y/+4tg4X7pzqZ86u+64u67VFCK9ORReGXh6vAnrOg3Ie0vIVbUjCAOTrF0N4mxTlmYUYjLEJj75tFvsj3WYrnnmqB3WBsEJ0SGM= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1584602137610219.0709994857259; Thu, 19 Mar 2020 00:15:37 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jEpO4-0002W0-Ad; Thu, 19 Mar 2020 07:14:40 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jEpO2-0002Vq-Fn for xen-devel@lists.xenproject.org; Thu, 19 Mar 2020 07:14:38 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 4a7cc0e4-69b1-11ea-bec1-bc764e2007e4; Thu, 19 Mar 2020 07:14:37 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 01FE1ABDC; Thu, 19 Mar 2020 07:14:35 +0000 (UTC) X-Inumbo-ID: 4a7cc0e4-69b1-11ea-bec1-bc764e2007e4 X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Juergen Gross To: xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org Date: Thu, 19 Mar 2020 08:14:28 +0100 Message-Id: <20200319071428.12115-1-jgross@suse.com> X-Mailer: git-send-email 2.16.4 MIME-Version: 1.0 Subject: [Xen-devel] [PATCH] xen/events: avoid NULL pointer dereference in evtchn_from_irq() X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Juergen Gross , Boris Ostrovsky , Stefano Stabellini , =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= , stable@vger.kernel.org Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" There have been reports of races in evtchn_from_irq() where the info pointer has been NULL. Avoid that case by testing info before dereferencing it. In order to avoid accessing a just freed info structure do the kfree() via kfree_rcu(). Cc: Marek Marczykowski-G=C3=B3recki Cc: stable@vger.kernel.org Reported-by: Marek Marczykowski-G=C3=B3recki Signed-off-by: Juergen Gross --- drivers/xen/events/events_base.c | 10 ++++++++-- drivers/xen/events/events_internal.h | 3 +++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/xen/events/events_base.c b/drivers/xen/events/events_b= ase.c index 499eff7d3f65..838762fe3d6e 100644 --- a/drivers/xen/events/events_base.c +++ b/drivers/xen/events/events_base.c @@ -247,10 +247,16 @@ static void xen_irq_info_cleanup(struct irq_info *inf= o) */ unsigned int evtchn_from_irq(unsigned irq) { + struct irq_info *info; + if (WARN(irq >=3D nr_irqs, "Invalid irq %d!\n", irq)) return 0; =20 - return info_for_irq(irq)->evtchn; + info =3D info_for_irq(irq); + if (info =3D=3D NULL) + return 0; + + return info->evtchn; } =20 unsigned irq_from_evtchn(unsigned int evtchn) @@ -436,7 +442,7 @@ static void xen_free_irq(unsigned irq) =20 WARN_ON(info->refcnt > 0); =20 - kfree(info); + kfree_rcu(info, rcu); =20 /* Legacy IRQ descriptors are managed by the arch. */ if (irq < nr_legacy_irqs()) diff --git a/drivers/xen/events/events_internal.h b/drivers/xen/events/even= ts_internal.h index 82938cff6c7a..c421055843c8 100644 --- a/drivers/xen/events/events_internal.h +++ b/drivers/xen/events/events_internal.h @@ -7,6 +7,8 @@ #ifndef __EVENTS_INTERNAL_H__ #define __EVENTS_INTERNAL_H__ =20 +#include + /* Interrupt types. */ enum xen_irq_type { IRQT_UNBOUND =3D 0, @@ -30,6 +32,7 @@ enum xen_irq_type { */ struct irq_info { struct list_head list; + struct rcu_head rcu; int refcnt; enum xen_irq_type type; /* type */ unsigned irq; --=20 2.16.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel