From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 683623FE660; Thu, 16 Jul 2026 14:16:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784211402; cv=none; b=bcl1u7o29xmezZe8V9qUU365VRrUZPq4TN2rvgOtcqWM/qPLd1pzlD7PUIll36ZrxYE4PUzEM9TwpkFp9rDSPBqeyZJoz91eUZsTNzIHr1ty1zbfPGLxgdNc3OC4aZ1ZrJwhKjd5dnZ7RFvaxs6DrJvSOgOiRI+SfcUC2pB++K4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784211402; c=relaxed/simple; bh=pC6XGcIYIyytXJI5jEC1OaTmnBdjlTNsOkjy84ohQdU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=W1xZuYW6nTMl+vURuSIkgVaF7OumXhzDehLO8EXHaQdAVavFukS7BYLOx7wV2mzg71wUcK9rCz3JnfOM3eGWqQO9RXH1EMo1smcB9c/I2Jk95W5hSPUaiHvYot4Dsddb4UO4xZPiPUL7hkPS2A1ZoJO/T+DZ2YTfuKfBzkCzsZc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=ZkhN26OC; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="ZkhN26OC" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CF0761F000E9; Thu, 16 Jul 2026 14:16:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1784211401; bh=TyKInY1yOwruWIAMslsLvcN0xfJyYpZRK0TviYZeIE4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=ZkhN26OCNUivDwp01kFIeWV9FwuT2mj5DCYS3dyvG6PgaZLFaeLvbsFdZNhG2qQRK GdZGVs+oVH2ZwItNeNbENL822P257jnfv2B955VUkS4q1O/PZl2izxB0EkAK9AVNOd W6kNrb6AIn/Hwtg7/oDywlOF2hooqvjspgqWpMXA= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Nicolin Chen , Pranjal Shrivastava , Kevin Tian , Jason Gunthorpe Subject: [PATCH 6.18 412/480] iommufd: Reject invalid read count in iommufd_veventq_fops_read() Date: Thu, 16 Jul 2026 15:32:39 +0200 Message-ID: <20260716133053.723409450@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260716133044.672218725@linuxfoundation.org> References: <20260716133044.672218725@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Nicolin Chen commit 00203ca8323f9714630408c19a209b52397975e6 upstream. The read count must be large enough to hold a vEVENT header. For a normal vEVENT, it must also hold the trailing data following the header. iommufd_veventq_fops_read() does not validate the count, but returns 0 as if the read had succeeded while leaving the pending event in the queue. Return -EINVAL in both undersize cases. Fixes: e36ba5ab808e ("iommufd: Add IOMMUFD_OBJ_VEVENTQ and IOMMUFD_CMD_VEVENTQ_ALLOC") Link: https://patch.msgid.link/r/e1111adcc8a8882fbfd84accd6674dc846dc5689.1780343944.git.nicolinc@nvidia.com Cc: stable@vger.kernel.org Signed-off-by: Nicolin Chen Reviewed-by: Pranjal Shrivastava Reviewed-by: Kevin Tian Signed-off-by: Jason Gunthorpe Signed-off-by: Greg Kroah-Hartman --- drivers/iommu/iommufd/eventq.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/iommu/iommufd/eventq.c b/drivers/iommu/iommufd/eventq.c index 896f45be0d2e..ac485d010a43 100644 --- a/drivers/iommu/iommufd/eventq.c +++ b/drivers/iommu/iommufd/eventq.c @@ -310,6 +310,9 @@ static ssize_t iommufd_veventq_fops_read(struct file *filep, char __user *buf, if (*ppos) return -ESPIPE; + /* Minimum read count is a vEVENT header */ + if (count < sizeof(*hdr)) + return -EINVAL; while ((cur = iommufd_veventq_deliver_fetch(veventq))) { /* Validate the remaining bytes against the header size */ @@ -323,6 +326,9 @@ static ssize_t iommufd_veventq_fops_read(struct file *filep, char __user *buf, if (!vevent_for_lost_events_header(cur) && sizeof(*hdr) + cur->data_len > count - done) { iommufd_veventq_deliver_restore(veventq, cur); + /* Read count doesn't fit a single normal vEVENT */ + if (done == 0) + rc = -EINVAL; break; } -- 2.55.0