Received: by 2002:ab2:1c04:0:b0:1f7:53ba:1ebe with SMTP id f4csp47040lqg; Fri, 26 Apr 2024 08:23:43 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVeZ8jFT1mOqNsBDqwmRr/3csrMi98mowBJu0ul33OlDvqM9fNaVzA+Ty8HYenlDqHPFE3QocQUOf40ATYEKryCPVf7wM66WD+6bt8/og== X-Google-Smtp-Source: AGHT+IGk+lTVjI/PXA9C4+TTFRTQUiOoo3ny67FpLvbbU8hHZsuGt5vR2bvNmEP/2INMMUyNmuXK X-Received: by 2002:a05:6871:5b02:b0:239:4a86:bbcd with SMTP id op2-20020a0568715b0200b002394a86bbcdmr3509480oac.3.1714145022917; Fri, 26 Apr 2024 08:23:42 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714145022; cv=pass; d=google.com; s=arc-20160816; b=S6R2aCxckBqXp85xPGgkBmbOcujjYJGKmuzKjfiA7PWrKfQ/F1tHf1og6OH/Mdvp1B p6l1EpCTW0bIKCi7i/LzRl5iSo0cR6kexAw9Wqh936r8IR5boZ/Iz7wGD1Wps0M6GP8/ vifBV1yfwJt90Cw80BPo6n1uyREEiZ4LGJiyadjrSS53KBSNaVSVMhbLnm4gy0dp6IoO QJ1E2EV4QJaEqK6pEIr+RE/MGy3XJR0cDqPlwzF8y2ZE2p5umojx2UQ1HciMfWvh6hTB oLv8T+qYMhPgsOdJULE93FxJrnny1haLRCW0/tRdmsTY9sywtRTnjak2NC6gSPXqtQXO xq7w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=Fo+CmOkzCZrjGdAA/ssF2Z41NXr4IRmVujUKxVYHL1w=; fh=pFngClF18SKgxR4gmNB6uQY0xf4jW3FK5XDOplS8Koc=; b=V78Su1ty0NeY10zB5jH+UdOvtzdz3/xqyl0jrhFXvtjql4RK5Zaj5VyUii6SKzV7V6 J+5LTSnz/CXxGvWcGKC1+xTKjpZtLWJi8C6EqBwrn7sGwz6QWGf25p4IUSqBtnqZhZmn li8sLDIPhX2Ai7TSIks5PEx0UO7It+Y/8C1/nYegTtL2ShuSyI4Wr0n1RVtM2Tleq/H2 uNo54KaTCXcdg/Oo3jxiz6T/Q7VIb7Wr37RO0bmIZxA2gW4kQt90poAse2xVa5U0K8RK GqNVDrbqznDjaW7wLCvivto0TW7itt8HWZ9enfOn4QQNiep7ISlQkk78JxdUGqqzq2C8 DHGQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=mNSqnhOC; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-160271-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-160271-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id d15-20020ac85d8f000000b004399a0d5844si13344505qtx.444.2024.04.26.08.23.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Apr 2024 08:23:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-160271-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=mNSqnhOC; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-160271-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-160271-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id AAFBF1C24953 for ; Fri, 26 Apr 2024 15:22:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 06284159585; Fri, 26 Apr 2024 15:18:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="mNSqnhOC" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 30BB6158D93; Fri, 26 Apr 2024 15:18:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714144728; cv=none; b=IOxGYtk/r7jaVaixKz47+5rtP5GKrcHp2DFBtqzKwLezB2Hn9TyyIoQwVtqNQLjgX9kTSuQxe5pQVgnZ3pBDPIF+efKLD0w+cykSNbAn7QwJynCTpGQDNTPl+neWxzSalLuafyTlvCMTbz6HeL+jFeVy14FiNJqD22NVGnZK3ig= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714144728; c=relaxed/simple; bh=1UnZiC3comG4gnEVIiUSo4RJz2Uq3SHSFq173Rv99mU=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=sGB3K8KXCnlVDbdPjrq1sVsRlmGhBAsTR4CjVAgmemt6qEm3EZzNK4wBx5WwUdKApS8Y3yjb8o4S1l38I17iHa0hCX3rWzZc5hOhwFPpnlQL0wMAxIidhgwlimF3WnrWCVrL0VGIIDmqMs0OUL0NZI+zg4EOdlpIrPwCZX1tGng= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mNSqnhOC; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id D63A7C2BD11; Fri, 26 Apr 2024 15:18:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714144727; bh=1UnZiC3comG4gnEVIiUSo4RJz2Uq3SHSFq173Rv99mU=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=mNSqnhOCvVS96laJVrGaGieiyUBAaw7BIIZlQfWJmTtK+o3CRYgilXqax2Q6jFiHb Tkr6khA10hRkujz93BoR88ndIAwlrA0cIr29DtMM/oUSb4BbCWO2xFtmfLxyizgcCi 4gZ/C5jQlPnsiBL0F0F4yvbOiva3OAJdCblKfHnnwiVKprBKA7nzRmDRSSlwlLtu64 LN2KpL7Hy+MAZWbwNyKe863P9JI9g21F/w3YZn3KuPgVo0JCuXYwi5a9ah53d1KoFk t8qQpCyYncg1/PuC40GaaWT23jN9CdLc0JCAYfZzRsVwf+n9QaHNFcS74kWGCAaFff HgV2PKKVeTjpg== Date: Sat, 27 Apr 2024 00:18:43 +0900 From: Masami Hiramatsu (Google) To: lumingyindetect@126.com Cc: linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org, rostedt@goodmis.org, mhiramat@kernel.org, mathieu.desnoyers@efficios.com, LuMingYin <11570291+yin-luming@user.noreply.gitee.com> Subject: Re: [PATCH] kernel/trace/trace_probe:Fixed memory leak issues in trace_probe.c. Message-Id: <20240427001843.84a3d367d3654b624c09defe@kernel.org> In-Reply-To: <20240426091343.1222770-1-lumingyindetect@126.com> References: <20240426091343.1222770-1-lumingyindetect@126.com> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Hi LuMingYin, Thanks for finding the problem! But please make a commit message following Documentation/process/submitting-patches.rst On Fri, 26 Apr 2024 10:13:43 +0100 lumingyindetect@126.com wrote: > From: LuMingYin <11570291+yin-luming@user.noreply.gitee.com> > > At line 1408 of the file /linux/kernel/trace/trace_probe.c, pointer variables named code and tmp are defined. At line 1437, a new dynamic memory area is allocated using the function kcalloc. When the if statement at line 1467 evaluates to true, the program jumps to the out label at line 1469. Within this function, there are two labels: out and fail. The difference between these two labels is that fail additionally frees the dynamic memory area pointed to by the variable code. Therefore, the program should jump to the fail label instead of the out label. This commit fixes this bug. > For example, you must line break after about 70 characters. Also, please don't use the line number because the line number is easily changed (function name is OK). Since this bug is very clear mistake, so you can just explain that as following. ---- If traceprobe_parse_probe_arg_body() fails to allocate 'parg->fmt', it jumps to 'out' instead of 'fail' by mistake. In the result, in this case the 'tmp' buffer is not freed and leaks its memory. Fix it by jumping to 'fail' in that case. ---- The first paragraph explains what happens, and second one to exaplain how to fix it. Also, please add this Fixes tag. Fixes: 032330abd08b ("tracing/probes: Cleanup probe argument parser") You can easily find this commit number with git blame. Thank you, > Signed-off-by: LuMingYin <11570291+yin-luming@user.noreply.gitee.com> > --- > kernel/trace/trace_probe.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/kernel/trace/trace_probe.c b/kernel/trace/trace_probe.c > index dfe3ee6035ec..42bc0f362226 100644 > --- a/kernel/trace/trace_probe.c > +++ b/kernel/trace/trace_probe.c > @@ -1466,7 +1466,7 @@ static int traceprobe_parse_probe_arg_body(const char *argv, ssize_t *size, > parg->fmt = kmalloc(len, GFP_KERNEL); > if (!parg->fmt) { > ret = -ENOMEM; > - goto out; > + goto fail; > } > snprintf(parg->fmt, len, "%s[%d]", parg->type->fmttype, > parg->count); > -- > 2.25.1 > -- Masami Hiramatsu (Google)