Received: by 2002:a05:6358:f14:b0:e5:3b68:ec04 with SMTP id b20csp1533544rwj; Sun, 18 Dec 2022 10:02:32 -0800 (PST) X-Google-Smtp-Source: AA0mqf7xRlcBZRhigWMNoKuU9sRmsNiZH4lVgu6x+iy/Yd9C03v4x41heaNU3SiC4Nx6yNEXO39V X-Received: by 2002:a17:90a:fb88:b0:219:e2f3:f2d2 with SMTP id cp8-20020a17090afb8800b00219e2f3f2d2mr40506157pjb.37.1671386552509; Sun, 18 Dec 2022 10:02:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671386552; cv=none; d=google.com; s=arc-20160816; b=y7zegIQZaCInDc0Vo/I+XSt3HVDK9MbuXRbXlpV/TI2B/667R6HHggMOl8x/w0Joce bT74bg5fIVo7C0UMiAJb0GMBFeMhgFNMlNJWKqsTpXaR9kkMxLygLF4aRCanLzz8QUHS fz5aEAi8T67cnpJWuKs82GZaPDWOSJk+wf5vIJKljwj4hZSRyh+eBG3owKTF/3ChV1rf gH6cnB9zUVTfLuCplAZnDDz2dSald4siuNVjjj0Uy+2Qg2bP34tN//oaN9dJMQfO7j18 Q+wfel2mrkiGAbi0x3m5yhJ4RnCeo7YAbM495PipQoqYPrljpiJrJoUNb47GQQIIYdxj s8BQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=93QQjhgc8OzRPgu/Q+hXi9eKqvI7U8X6D080YziI84k=; b=DQVGs4djr8e2+aGPPnWse/5exhnOi5Rvg7k3EImzIQHce7eiNdGBIxH3dz3UTecPV+ yHcSt/TGgQv1sdILf7wYh/tuoqXMyJge8lHEl2KtQ3P60HaOoZhPcTISaKwR3i4T7CwZ UuiIIO8vlYcqs6PmP27QU2EubkkPmHBOcrq8LbehNYbj+YMV2VMy2EIF9tIVJLEJf6TK +bwYueA0+O8pwbePt4T6JkeM6r8WoSZ8PZun1/M09MJBbXXyUEFYQh1NygXOGSRdd3vq DIedHm87KBnp0b2dz3C691To6v0ITO7qaYfQ4tyYvgac6yebgMh/bgMkg6+flIsvq4cc Gm8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=mXWNygHr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j70-20020a638b49000000b00478c3840710si8733255pge.25.2022.12.18.10.02.23; Sun, 18 Dec 2022 10:02:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=mXWNygHr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232122AbiLRQhs (ORCPT + 70 others); Sun, 18 Dec 2022 11:37:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33794 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232020AbiLRQgk (ORCPT ); Sun, 18 Dec 2022 11:36:40 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D5335175BE; Sun, 18 Dec 2022 08:13:13 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 403FAB803F1; Sun, 18 Dec 2022 16:13:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 36AAAC433D2; Sun, 18 Dec 2022 16:13:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1671379987; bh=pW/2+44E4DquXjYBO68pLmaOVVQcLKHNIyJzasyyPX4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mXWNygHrO+orDQLBGQHiRN51FPGyYJViyIzifFg8697+wcPh0+yK/qf+eu4ELnBdH A4vqvNNiyIxr+WNAoO5K3QrfDfqDXiBxMyA7Pg+Tq7JEkyy+Yv38bJAT7HPBxVK13a bW30HzMr0qqLqlGpIWPP4nMcBJSfjH/EIO3jWBuONhRUM5qUsGWpk2xVbTTsrpsiQd 2y2eBfgDDx0spSKYL4ThU5zo12p5KZBHAu3odRddEkxpqYLyv9YFqsr3y3DOpRztzS nU1CkVJrq9soq583nZVnx5o0U4jrGBpGDQu/OVFhIePmkqx8vFawAML/ZOb2+lYFB3 rR2LwHMaD9REw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Zhang Yuchen , Corey Minyard , Sasha Levin , openipmi-developer@lists.sourceforge.net Subject: [PATCH AUTOSEL 5.15 07/46] ipmi: fix memleak when unload ipmi driver Date: Sun, 18 Dec 2022 11:12:05 -0500 Message-Id: <20221218161244.930785-7-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221218161244.930785-1-sashal@kernel.org> References: <20221218161244.930785-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Zhang Yuchen [ Upstream commit 36992eb6b9b83f7f9cdc8e74fb5799d7b52e83e9 ] After the IPMI disconnect problem, the memory kept rising and we tried to unload the driver to free the memory. However, only part of the free memory is recovered after the driver is uninstalled. Using ebpf to hook free functions, we find that neither ipmi_user nor ipmi_smi_msg is free, only ipmi_recv_msg is free. We find that the deliver_smi_err_response call in clean_smi_msgs does the destroy processing on each message from the xmit_msg queue without checking the return value and free ipmi_smi_msg. deliver_smi_err_response is called only at this location. Adding the free handling has no effect. To verify, try using ebpf to trace the free function. $ bpftrace -e 'kretprobe:ipmi_alloc_recv_msg {printf("alloc rcv %p\n",retval);} kprobe:free_recv_msg {printf("free recv %p\n", arg0)} kretprobe:ipmi_alloc_smi_msg {printf("alloc smi %p\n", retval);} kprobe:free_smi_msg {printf("free smi %p\n",arg0)}' Signed-off-by: Zhang Yuchen Message-Id: <20221007092617.87597-4-zhangyuchen.lcr@bytedance.com> [Fixed the comment above handle_one_recv_msg().] Signed-off-by: Corey Minyard Signed-off-by: Sasha Levin --- drivers/char/ipmi/ipmi_msghandler.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c index 2badf36d4816..8dbc349a2edd 100644 --- a/drivers/char/ipmi/ipmi_msghandler.c +++ b/drivers/char/ipmi/ipmi_msghandler.c @@ -3527,12 +3527,16 @@ static void deliver_smi_err_response(struct ipmi_smi *intf, struct ipmi_smi_msg *msg, unsigned char err) { + int rv; msg->rsp[0] = msg->data[0] | 4; msg->rsp[1] = msg->data[1]; msg->rsp[2] = err; msg->rsp_size = 3; - /* It's an error, so it will never requeue, no need to check return. */ - handle_one_recv_msg(intf, msg); + + /* This will never requeue, but it may ask us to free the message. */ + rv = handle_one_recv_msg(intf, msg); + if (rv == 0) + ipmi_free_smi_msg(msg); } static void cleanup_smi_msgs(struct ipmi_smi *intf) -- 2.35.1