Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=198.175.65.11 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796068424; b=H5ILEJMEl94pxnkAOWMy0in2VBRZCP+RZQHpcLUldYhCDP9+9wITF3mcooUG9KbQy2v8 lb+YxgOJP4ooL1SDA1vdzlvLA3w+zXoMrexmTFTqfG6XUlM7sr8l6OChwdSwFBW0HFrgj FNJBu5ACpUq7PIBRNumKR72w9tF8/+Xc1R4vSItgpgRAgRbu9IsDT5vll2YV9myY8GK9i z+MS5qDgX18SlsjHwCZrGb0o0RRg81D0LZSrs/bZS8cNKkFiAoBMNrBvK+9HzHqp8uK35 azj95e/oz10QSa20bk/baHJtgZjjy2PHsD4dC3vfEaIZ3tB7uVm2FPDgfc20AAPGZXw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796068424; h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID: X-IronPort-AV:X-IronPort-AV:Received:X-CSE-ConnectionGUID: X-CSE-MsgGUID:X-ExtLoop1:X-IronPort-AV:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=JDJ6NEI10yeRMBIrFezw6vRYuiuEi0DMjxVNXGa9SAQ=; b=iUvo7cNDEw/KI9VhyEcgAp1MpUgbGPlKkaZ4yfCcxZObvGFW7ymaqgEIpaPOWnMnK7Qn x6Bg1ThncI0qQCs+HCha26bvU2UUdk9uJbqxk1gnQ7ktUYT0Tlk7slmMOd7CaQNKEDQtB jukb/pPvlWw9z7f3LB4z/LczYCGpnsUi9hlkkj+5/wI/caxkU9k9p8LDunx5l95XnQXyh l2mJjTRsPZ7J3DPoQWX7EEUSZKrlC2yrwKPSBvXUq/kHCh9+gQWrBGSQTy2mFDaXnQk+D qtP0haimbI8yzPKbkR9esMGw3/NToktE2c6hBiptXQK5RTbFKVlMdCcVLNcNG23pq+A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=Xk6A57+r; arc=none smtp.remote-ip=198.175.65.11 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6318A606A6B0; Mon, 30 Nov 2026 19:53:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6318A606A6B0 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=Xk6A57+r DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796068425; x=1827604425; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=JDJ6NEI10yeRMBIrFezw6vRYuiuEi0DMjxVNXGa9SAQ=; b=Xk6A57+rVTeEv3UTi6FMT6wKejx2P2MhmYGOcoPOMQbECQIsYscs0po1 oeAmn8y6KTGwkRho/uNvLxD0oBLj29aDBLuvMsO5paqgmsUVUY5vn8acn KUvs5x4BVvqi17wQPb3K0DI/SUl66Nwz5RcspIPn7eli7oUZjt5HmYGHy XwKIy6K8BKCHId86s273U6uX316HX1fv/1Oojvp9Oq+pXRK/YCMDXe3zk xyLKRddySlSjcEhee8/H9W+gEljUH7dxzO2bWI63azFc3yfHPeYwbJouM gqe3R7w92QX+QL8aV3TYAU7NlRACvAJn1M4vopGCuazuKbfyfKCgTWugR Q==; X-CSE-ConnectionGUID: HHNa5l2MRn6vCIk6goUOkw== X-CSE-MsgGUID: Fw/FC1YDRzmoXtcAmoIA+Q== X-IronPort-AV: E=McAfee;i="6800,10657,11982"; a="4805777" X-IronPort-AV: E=Sophos;i="6.27,243,1787036400"; d="scan'208";a="4805777" Received: from orviesa002.jf.intel.com ([10.64.159.142]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2026 11:53:41 -0800 X-CSE-ConnectionGUID: 1a0jM3haRqSPWbDjr9vgyg== X-CSE-MsgGUID: UKPddTszTL+yZ+378N01Aw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,243,1787036400"; d="scan'208";a="13036632" Received: from jf5300-15a101203tc.jf.intel.com (HELO meta-crater2c.jf.intel.com) ([10.54.113.49]) by orviesa002.jf.intel.com with ESMTP; 30 Nov 2026 11:53:40 -0800 From: Daniel Byrne To: Vinod Koul , dmaengine@vger.kernel.org Cc: Vinicius Costa Gomes , Dave Jiang , Frank Li , Fenghua Yu , Dan Williams , linux-kernel@vger.kernel.org, Daniel Byrne , stable@vger.kernel.org Subject: [PATCH v2 08/10] dmaengine: idxd: read the event log size under its lock in the setup Date: Mon, 30 Nov 2026 11:47:19 -0800 Message-ID: <20261130194721.1900266-9-daniel1.byrne@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261130194721.1900266-1-daniel1.byrne@intel.com> References: <20261130194721.1900266-1-daniel1.byrne@intel.com> X-Mailing-List: dmaengine@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit idxd_device_evl_setup() allocates the event log and its bitmap by evl_size(), which it reads before it takes the event log lock, and then gives the device evl->size, read again under the lock. event_log_size can be written until the device is enabled, which comes after the setup, and the store takes no lock. A write between the two reads gives the device a log larger than the memory behind it, which it writes past once it has logged more entries than the old size holds. A write after the setup changes the size by which the log is walked. Take the lock before the size is read and hold it to the end of the setup, write the size under the same lock, and refuse the write with -EBUSY once there is a log. The log keeps the size it was allocated with until idxd_device_evl_free() takes it away. Fixes: 244da66cda35 ("dmaengine: idxd: setup event log configuration") Cc: stable@vger.kernel.org # 6.4+ Signed-off-by: Daniel Byrne --- New in v2. drivers/dma/idxd/device.c | 8 +++++++- drivers/dma/idxd/sysfs.c | 10 ++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/drivers/dma/idxd/device.c b/drivers/dma/idxd/device.c index 83665f7d8d6f..d1a8ccc14bb4 100644 --- a/drivers/dma/idxd/device.c +++ b/drivers/dma/idxd/device.c @@ -773,6 +773,12 @@ static int idxd_device_evl_setup(struct idxd_device *idxd) if (!evl) return 0; + /* + * event_log_size_store() writes the size under this lock, and only + * while there is no log. So the size read here is the one the log + * is allocated by and the one the device is given. + */ + mutex_lock(&evl->lock); size = evl_size(idxd); bmap = bitmap_zalloc(size, GFP_KERNEL); @@ -791,7 +797,6 @@ static int idxd_device_evl_setup(struct idxd_device *idxd) goto err_alloc; } - mutex_lock(&evl->lock); evl->log = addr; evl->dma = dma_addr; evl->log_size = size; @@ -818,6 +823,7 @@ static int idxd_device_evl_setup(struct idxd_device *idxd) err_alloc: bitmap_free(bmap); err_bmap: + mutex_unlock(&evl->lock); return rc; } diff --git a/drivers/dma/idxd/sysfs.c b/drivers/dma/idxd/sysfs.c index 6d251095c350..bcd74b1d948e 100644 --- a/drivers/dma/idxd/sysfs.c +++ b/drivers/dma/idxd/sysfs.c @@ -1708,7 +1708,17 @@ static ssize_t event_log_size_store(struct device *dev, (val * evl_ent_size(idxd) > ULONG_MAX - idxd->evl->dma)) return -EINVAL; + /* + * idxd_device_evl_setup() reads the size under this lock. Once a + * log is set up it keeps the size it was allocated with. + */ + mutex_lock(&idxd->evl->lock); + if (idxd->evl->log) { + mutex_unlock(&idxd->evl->lock); + return -EBUSY; + } idxd->evl->size = val; + mutex_unlock(&idxd->evl->lock); return count; } static DEVICE_ATTR_RW(event_log_size); -- 2.43.0