Received: by 2002:a25:d783:0:0:0:0:0 with SMTP id o125csp335979ybg; Thu, 19 Mar 2020 00:16:08 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtdqpWXZ7Ggsdiry2NYG+LTn3E2fFmQGrQvHii2+2hv4qnJv2NO8YdCNupTzGpqrgoki21U X-Received: by 2002:a05:6830:193:: with SMTP id q19mr1161069ota.164.1584602167952; Thu, 19 Mar 2020 00:16:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584602167; cv=none; d=google.com; s=arc-20160816; b=cM0ZOQm/wPKzaNB7uTEczfTYBh12OKRwci9wyQ0xjx8CxUDQAnK3ALalDuau1gaHgM B/ia3S4Wy2lYdEcyoOTYwr0uN9UsPZTIUiS/BFDwkObvNaz2OCpjaPz50NhpsigG2e8F Lgrum8IJY6ZEMbN6Ajttjpmy/Z0AgTCHPpyoTpOaeFyTpQ8Dx48r297Eh3mL2XndsT/8 dSF0UPI7YoUl3/Icgw4jKZlyhWHgNADOlq8KFOCdNdVztv6yMw9ar/ppm0R8+PtYd463 vKi0hQR70R0eEch52EMJVkrq8Sl60XInsY81091DZzbyQ+1dAH4ILnScOOIfO7oFFcOS SzFw== 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 :message-id:date:subject:cc:to:from; bh=8FlYCBB+J8LgTf70LCzTtZb68r4Gl/D8RumnbDGAuHU=; b=schzeCcLUBsZ1oAjcltQJ9RV7rXsbGmg0tc8pN1w53l4eC42zDgTMyUy5HukcxxaFn aLd/Jzr5uhJkxKXowIV9AiNqi09GV6H8IOu9J6g/zXKKU3OqSU5o0HVr0tnaFl16VRZ9 +M3nZZB+NEZDI0RkmMLNH/+bhEsiVVHStd8g3pbbcRWN1M8e35McRShhlxeM2Q8L6Pow Argw8Qluy3r26wnAFTDMcmDyJMDyGnQvxrcOlxRcPnuhQG5EiekAP3gcuO05BY2qNf/2 5W21TBiD9c7dzdwRTSSKYNP2MwKYFHlIX8/nHdPKuli+mqX+aQR2zdBhUcotTYg0JWSs EvAw== 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 2si611096ois.104.2020.03.19.00.15.55; Thu, 19 Mar 2020 00:16:07 -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 S1727236AbgCSHOi (ORCPT + 99 others); Thu, 19 Mar 2020 03:14:38 -0400 Received: from mx2.suse.de ([195.135.220.15]:52010 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725787AbgCSHOi (ORCPT ); Thu, 19 Mar 2020 03:14:38 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de 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) From: Juergen Gross To: xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org Cc: Juergen Gross , Boris Ostrovsky , Stefano Stabellini , =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= , stable@vger.kernel.org Subject: [PATCH] xen/events: avoid NULL pointer dereference in evtchn_from_irq() 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 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 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órecki Cc: stable@vger.kernel.org Reported-by: Marek Marczykowski-Górecki 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_base.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 *info) */ unsigned int evtchn_from_irq(unsigned irq) { + struct irq_info *info; + if (WARN(irq >= nr_irqs, "Invalid irq %d!\n", irq)) return 0; - return info_for_irq(irq)->evtchn; + info = info_for_irq(irq); + if (info == NULL) + return 0; + + return info->evtchn; } unsigned irq_from_evtchn(unsigned int evtchn) @@ -436,7 +442,7 @@ static void xen_free_irq(unsigned irq) WARN_ON(info->refcnt > 0); - kfree(info); + kfree_rcu(info, rcu); /* 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/events_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__ +#include + /* Interrupt types. */ enum xen_irq_type { IRQT_UNBOUND = 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; -- 2.16.4