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 BE1CE309F08; Sat, 12 Sep 2026 15:24:04 +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=1789226645; cv=none; b=QK9+ZAKj6dGhayTGyDWOsFMqJcDe/TYGiX/CkoQlkf2kxNy5EzksKTc3+1zVynytJe5OEfB3EKUWsnOEwVaN+xg5UaTiVJf1v5NFYphiwhGmGrltdOafh8ZGMEjsNFLtbQo/Tq2XFvhX6gKJj+wVf6sKzN6toc2Yi5aOJcouUEk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789226645; c=relaxed/simple; bh=xv7yoXPCgCL5dozO/FRrrqb9wqdMmuzvjrpndONu5mE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UqUOWvMkRqbPpOpiCMsOKS1JcszcaFtvqo/R8W6YsyGFZEGmqfYAGArh/GBqLEJhu/BP/4pT0OyPqEnWFthN3/cfH+A4C2vMCol0CzTK6Or0PTdZIUbBxTYp+V7j4YSN4v/oFOUXezEbcCihG/3mgdce+crpBzTn1lyvdkuk6Tc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=YKBE9+6z; 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="YKBE9+6z" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C2A381F000FF; Sat, 12 Sep 2026 15:24:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1789226644; bh=0OdM0PoHslGxeGA7npcmjkSFZ3t2Ze6rAPT+3A3SFBQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=YKBE9+6zC5GfZLakfAGDTvc7nCLzY3M+lUJoHM4S7Au7FEnZHf4xqrEgNjeiGCnr3 mhdwUZd8WpLgXFgAGnPm6ErRq2HebdoWJO9w/sbR3rbyXwKkDvJ2ByWZxtWay9EWZ5 ak8Vj2j1iHOz8r4XGkt68cBFWAsqYYc2XcdXCK3k= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, James Kim , Dan Carpenter , Alexandre Bounine , Matt Porter , Andrew Morton Subject: [PATCH 6.1 0020/1191] rapidio: mport_cdev: fix use-after-free in dma_req_free() Date: Sat, 12 Sep 2026 08:45:48 +0200 Message-ID: <20260912065548.567718736@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260912065548.086904252@linuxfoundation.org> References: <20260912065548.086904252@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.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: James Kim commit 5cbef379a94b161726c5f504598bf4791d45cedc upstream. dma_req_free() acquires buf_mutex through req->map, drops the mapping reference with kref_put(), and then dereferences req->map again to unlock the mutex. If kref_put() drops the last reference, mport_release_mapping() frees the mapping, and the subsequent mutex_unlock() dereferences a freed object. This is a use-after-free. Fix this by caching map and md before kref_put(), clearing req->map while holding buf_mutex, and using the cached md for mutex unlocking. The bug is reachable from userspace via the RapidIO mport character device interface. Link: https://lore.kernel.org/20260723235220.588424-1-james010kim@gmail.com Fixes: e8de370188d0 ("rapidio: add mport char device driver") Signed-off-by: James Kim Reviewed-by: Dan Carpenter Cc: Alexandre Bounine Cc: Greg Kroah-Hartman Cc: Matt Porter Cc: Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman --- drivers/rapidio/devices/rio_mport_cdev.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) --- a/drivers/rapidio/devices/rio_mport_cdev.c +++ b/drivers/rapidio/devices/rio_mport_cdev.c @@ -582,9 +582,13 @@ static void dma_req_free(struct kref *re } if (req->map) { - mutex_lock(&req->map->md->buf_mutex); - kref_put(&req->map->ref, mport_release_mapping); - mutex_unlock(&req->map->md->buf_mutex); + struct rio_mport_mapping *map = req->map; + struct mport_dev *md = map->md; + + mutex_lock(&md->buf_mutex); + req->map = NULL; + kref_put(&map->ref, mport_release_mapping); + mutex_unlock(&md->buf_mutex); } kref_put(&priv->dma_ref, mport_release_dma);