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 3B3E743E9DF; Thu, 30 Jul 2026 15:54:59 +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=1785426900; cv=none; b=YJIKuH7kBN/sWVJ7amT+xfMUEYz3LPWqiQKcVny/DwKDvZxzkHThroAaf7NvYHttDHgugl33Rs8pzmbSMFrx/WlnmbqRx2OjCGk7CDqs55QwZw1hbjNrUS32UcvSuwHykFwk/60l/BNqw0sgciOrGIyFLN7/JNb5tPylnDw4uGo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785426900; c=relaxed/simple; bh=XOrteqVpRz6j7IOW5Tih7LDmCkfr6QIn9SIwmaYFdFQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rdpubiiC88Cwc983+YQsLmzoFT4TkTssrJ9WqnmmPQ5raqFdQdZ1d7b0//gMaNzf6G72K2R9pmxbupbhxmniSjK44A7Uo6JDUq9PnZTMQwBv2YmPqztI077nYliQI2dsmEabtaQMUTxroLNJseX45/gIuDbOjn16Q5z9N0AxMiw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=SGO/S+aI; 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="SGO/S+aI" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8E93C1F000E9; Thu, 30 Jul 2026 15:54:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1785426899; bh=2jbmJqoGbOMwAiO87BbvJ7dMZJlHzUjKyj/OkKeQ88s=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=SGO/S+aIscKRBqNrp9Qmuemk9+pltcHeEsLTguUvH40fC831UOzZ7yZld6HRxz0aF eBl+TPTT12+V+cfVEOAub7Kz3daAMlgubAkc+FpS+P23eIDgBqSF1DXK0CqSz+A5qY t97wON7vOoTaWC+Q/ugqN9h+ViV+ULB5giGUsWWE= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Wentao Liang , Corey Minyard , Sasha Levin Subject: [PATCH 6.12 564/602] ipmi: fix refcount leak in i_ipmi_request() Date: Thu, 30 Jul 2026 16:15:56 +0200 Message-ID: <20260730141447.897877623@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260730141435.976815864@linuxfoundation.org> References: <20260730141435.976815864@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.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Wentao Liang [ Upstream commit a3f3859cecacb64f18fd446271ece9a3b3f2d4de ] When a caller provides a `supplied_recv` message to i_ipmi_request(), the function increments the user's `nr_msgs` reference count. If an error occurs later, the out_err cleanup path only frees the recv_msg if the function allocated it itself (i.e., !supplied_recv). In the supplied_recv case the cleanup is skipped, leaving the reference count elevated. The caller ipmi_request_supply_msgs() does not release the supplied_recv on error, so the reference is permanently leaked. Fix this by explicitly reverting the reference count operations when a supplied recv_msg with a valid user pointer is present in the error path: decrement nr_msgs and drop the user's kref. Cc: stable@vger.kernel.org Fixes: b52da4054ee0 ("ipmi: Rework user message limit handling") Signed-off-by: Wentao Liang Message-ID: <20260603120634.3758747-1-vulab@iscas.ac.cn> Signed-off-by: Corey Minyard [ changed `free_ipmi_user` to `free_user` in the two added `kref_put()` calls ] Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/char/ipmi/ipmi_msghandler.c | 8 ++++++++ 1 file changed, 8 insertions(+) --- a/drivers/char/ipmi/ipmi_msghandler.c +++ b/drivers/char/ipmi/ipmi_msghandler.c @@ -2331,6 +2331,10 @@ static int i_ipmi_request(struct ipmi_us if (smi_msg == NULL) { if (!supplied_recv) ipmi_free_recv_msg(recv_msg); + else if (recv_msg->user) { + atomic_dec(&recv_msg->user->nr_msgs); + kref_put(&recv_msg->user->refcount, free_user); + } return -ENOMEM; } } @@ -2373,6 +2377,10 @@ out_err: ipmi_free_smi_msg(smi_msg); if (!supplied_recv) ipmi_free_recv_msg(recv_msg); + else if (recv_msg->user) { + atomic_dec(&recv_msg->user->nr_msgs); + kref_put(&recv_msg->user->refcount, free_user); + } } else { dev_dbg(intf->si_dev, "Send: %*ph\n", smi_msg->data_size, smi_msg->data);