Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp1211646lqb; Thu, 30 May 2024 03:58:05 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXr6RweoeCfO2VvQ/C3rJPW32QpQk5xfoSXwJSEER4cYxq/UAY0AebtZgCV6/NzGDz9qNlaTnm3ODrX+t6rxCHtf1T6WVs1MmapFAo7Uw== X-Google-Smtp-Source: AGHT+IGzsVm9P24IYq+cPG4XUMdMRebX3yFhS3ArpbO53eoloE9KyTSJ0Q8rSNAf6yT/QbAw90bk X-Received: by 2002:a05:622a:298a:b0:43f:ece8:2b83 with SMTP id d75a77b69052e-43fece82d28mr11039041cf.35.1717066685104; Thu, 30 May 2024 03:58:05 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717066685; cv=pass; d=google.com; s=arc-20160816; b=saV0qhXk4zSbV25C6ShVBfUfz/Ym8NUDqrp1p7HaAgYhIHW/YAIHFeg/BQXTlLjHli YuROQCY6/WMhG5Vrx4zJgvYZwBp27YdVgBGj3yqAURhYbU7nWXGtC0YmwUSJlgZZohoQ Ea2WfXEGzw9+XqSF7iK/7MpIbn16bI5XUwA1vbHPW7875O/Nhdl96ofEHbCDZrz5Jr6U 4MlfvGDBEUIhKVe89oECNy39JSXUNWoOFzjJjYQsMvtI20pREygSj4zhlz14PbXMa00b KKtukhTFYECelqgK2d5O5VsDoVCW1XKSDXBmPQZnIwvURcOwmTYNVv1uAMsICnYvmCAD 8Log== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=HNAz+Hha0bmN2XUtJxDAuc8OhG7Yy7pJmC4MZGBwtNs=; fh=M/R+Cd5xTY5VaEyQPIjUavZyTYFiPJYv9Rbv7ueof+s=; b=1CcqJq4XN9F5dkOhdNefZ0CNEIA9YZT7Hyer/amTAWnZS+h5+CbMjpAJFG1TGmfj9f fKRVI/c0OY/vHGFISVZgKcEx9K+YSTD9XqJENaLEyZJrtehAchIG/R+3zlFx5jK1d7fw h1U9Yfyb4Con4r5DX8To4z/Hw46k5jxJGHMqsKJw+wywJZnVO7GUMNkxu9SuX15rgq47 i7pt6Nb9Mr3vuQXMJivfMEymMjfBQkPA1Y2kfj/TONGRPRPQrUfZ8ny+Mjf5wB4/CRKp VqLFYdw2taBpT/1laBn5YPw/VZTuWoyxdy7i0f/dpdCJEkxY3UbuZdRWD5JyPheB93aL t1ug==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=aZcx3la3; arc=pass (i=1 spf=pass spfdomain=amazon.com dkim=pass dkdomain=amazon.com dmarc=pass fromdomain=amazon.com); spf=pass (google.com: domain of linux-kernel+bounces-195278-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-195278-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id d75a77b69052e-43fb18a6c66si144120181cf.322.2024.05.30.03.58.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 03:58:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-195278-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=aZcx3la3; arc=pass (i=1 spf=pass spfdomain=amazon.com dkim=pass dkdomain=amazon.com dmarc=pass fromdomain=amazon.com); spf=pass (google.com: domain of linux-kernel+bounces-195278-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-195278-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id A8E671C21F9B for ; Thu, 30 May 2024 10:58:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D8FBF17C7DB; Thu, 30 May 2024 10:57:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="aZcx3la3" Received: from smtp-fw-9102.amazon.com (smtp-fw-9102.amazon.com [207.171.184.29]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B80B01078B for ; Thu, 30 May 2024 10:57:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=207.171.184.29 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717066678; cv=none; b=QxMv/RQ9ZE8kV1z08hTFyikZJgxTMaWL3IEel2n7lhJDS7/m2sU2Wxel2nc2bgH8t/+OZ8k5AlsJqbRFQQMjL2rmfRfUNxb8TNiNmZ+wpYKgxrvVgSlyD8CfG179YcryrNo3jeU1ZD63SgI8P7Bn2jwLY+izGCc+mFYo+J2ABK8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717066678; c=relaxed/simple; bh=i+syEPO/mfE9NznXfzWiBqbRQlJzDIO15u7Xl6jZyq8=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=mDjQZ4vKh3JVsrmtf9DwZg1t6qznSLgZyBC3jykhF31FvtgeMhRyJfOJhWxtVyvhwn3M4x2cJbThslQzDAiJpGF0O/WBS8vQNqz2IsMByUe1UsQONY0gSKNVfseXOmCC6P+U5AYJNVZbqQQT7SsypeO7fusp4Hnd/u0gLrrUdig= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com; spf=pass smtp.mailfrom=amazon.com; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b=aZcx3la3; arc=none smtp.client-ip=207.171.184.29 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1717066677; x=1748602677; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=HNAz+Hha0bmN2XUtJxDAuc8OhG7Yy7pJmC4MZGBwtNs=; b=aZcx3la3SdhDBEGduXqDe9U01Zhkyu/MvJW1GZeee4qE5PMhntWplNXy ZhQR+A6j9yu3TpAKHJ1jnkrVDg6ztW9jvoFwYaeifEN0Tj4Di2EPTMzoD OjqZZqz0Ud8Ttve9gSV8R/OVtdgwy2qqxVyNVuziaO3kfEtTo1FWJe2bK s=; X-IronPort-AV: E=Sophos;i="6.08,201,1712620800"; d="scan'208";a="422619734" Received: from pdx4-co-svc-p1-lb2-vlan3.amazon.com (HELO smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev) ([10.25.36.214]) by smtp-border-fw-9102.sea19.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 May 2024 10:57:49 +0000 Received: from EX19MTAEUC002.ant.amazon.com [10.0.10.100:17304] by smtpin.naws.eu-west-1.prod.farcaster.email.amazon.dev [10.0.16.54:2525] with esmtp (Farcaster) id 44dc4b34-d413-4333-8c5d-1be55b7bb1ac; Thu, 30 May 2024 10:57:48 +0000 (UTC) X-Farcaster-Flow-ID: 44dc4b34-d413-4333-8c5d-1be55b7bb1ac Received: from EX19D002EUA003.ant.amazon.com (10.252.50.18) by EX19MTAEUC002.ant.amazon.com (10.252.51.245) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.28; Thu, 30 May 2024 10:57:47 +0000 Received: from EX19MTAUEC001.ant.amazon.com (10.252.135.222) by EX19D002EUA003.ant.amazon.com (10.252.50.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.28; Thu, 30 May 2024 10:57:47 +0000 Received: from dev-dsk-hagarhem-1b-b868d8d5.eu-west-1.amazon.com (10.253.65.58) by mail-relay.amazon.com (10.252.135.200) with Microsoft SMTP Server id 15.2.1258.28 via Frontend Transport; Thu, 30 May 2024 10:57:47 +0000 Received: by dev-dsk-hagarhem-1b-b868d8d5.eu-west-1.amazon.com (Postfix, from userid 23002382) id DFCB820C69; Thu, 30 May 2024 10:57:46 +0000 (UTC) From: Hagar Hemdan To: CC: Maximilian Heyne , Norbert Manthey , Hagar Hemdan , Marc Zyngier , "Thomas Gleixner" , Eric Auger , , Subject: [PATCH] irqchip/gic-v3-its: Fix potential race condition in its_vlpi_prop_update() Date: Thu, 30 May 2024 10:57:13 +0000 Message-ID: <20240530105713.18552-1-hagarhem@amazon.com> X-Mailer: git-send-email 2.40.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain Similar to commit 046b5054f566 ("irqchip/gic-v3-its: Lock VLPI map array before translating it"), its_vlpi_prop_update() calls lpi_write_config() which obtains the mapping information for a VLPI. This should always be done with vlpi_lock for this device held. Otherwise, its_vlpi_prop_update() could race with its_vlpi_unmap(). This bug was discovered and resolved using Coverity Static Analysis Security Testing (SAST) by Synopsys, Inc. Fixes: 015ec0386ab6 ("irqchip/gic-v3-its: Add VLPI configuration handling") Signed-off-by: Hagar Hemdan --- drivers/irqchip/irq-gic-v3-its.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c index 40ebf1726393..ecaad1786345 100644 --- a/drivers/irqchip/irq-gic-v3-its.c +++ b/drivers/irqchip/irq-gic-v3-its.c @@ -1970,9 +1970,13 @@ static int its_vlpi_unmap(struct irq_data *d) static int its_vlpi_prop_update(struct irq_data *d, struct its_cmd_info *info) { struct its_device *its_dev = irq_data_get_irq_chip_data(d); + int ret = 0; - if (!its_dev->event_map.vm || !irqd_is_forwarded_to_vcpu(d)) - return -EINVAL; + raw_spin_lock(&its_dev->event_map.vlpi_lock); + if (!its_dev->event_map.vm || !irqd_is_forwarded_to_vcpu(d)) { + ret = -EINVAL; + goto out; + } if (info->cmd_type == PROP_UPDATE_AND_INV_VLPI) lpi_update_config(d, 0xff, info->config); @@ -1980,7 +1984,9 @@ static int its_vlpi_prop_update(struct irq_data *d, struct its_cmd_info *info) lpi_write_config(d, 0xff, info->config); its_vlpi_set_doorbell(d, !!(info->config & LPI_PROP_ENABLED)); - return 0; +out: + raw_spin_unlock(&its_dev->event_map.vlpi_lock); + return ret; } static int its_irq_set_vcpu_affinity(struct irq_data *d, void *vcpu_info) -- 2.40.1