Received: by 2002:ab2:3b09:0:b0:1ed:14ea:9113 with SMTP id b9csp199299lqc; Thu, 29 Feb 2024 14:50:22 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCX+1p1MGtY8Ppb95elrednnS+jwGSOz0BNxA5vERfPT/K0BZ9AhyPfuJZHNue9eSW3580dpS335ylTPJh+3bJd3FBVv0qzFvKwlc4myqg== X-Google-Smtp-Source: AGHT+IFY0G75FCbZcSqV5tq2jGBbQ32xttEMcSDfWZUe1waraEtSOZMWpJ/WVBgunYZPGTG6NueS X-Received: by 2002:a05:6402:2317:b0:566:43ab:8b78 with SMTP id l23-20020a056402231700b0056643ab8b78mr23258eda.30.1709247022724; Thu, 29 Feb 2024 14:50:22 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709247022; cv=pass; d=google.com; s=arc-20160816; b=IAQkkDTlWzb7s5LApRjIPQsyjOHnuFRXrOLxy4EIhTE62oKUIuhD3a32MozNmPiLz2 VtRr3DljelVQfApnYbMqUGr1eexAaA5N0Aq8bJshO03COc8ncWV4ws/SHFM2Nxw7Nuq4 XA6dypAi6VC74gDfvBTihyNe67nGTFVC4My3VEDSBUJsiny8V3ERzYDb5BvHFCRj37N/ 49qMyPiEk30eaLtNUZmxWCJP23iga2NT9AU2nbM2nnspBHVnh6Gm6GmwZAzuspnjZ6l9 GzfploYds2wZZD7WMmUDcP0UGm0wuClnBeKG81UGQfMLN/qAHw+cbjpmB5BgXwwBuyui bavw== 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=LygN4IZoo1tjfhspMCbLv9uucBJnoB2p5y9VLrn7OOk=; fh=vGzgr5lIkB5bDKRmu0HaHHqyBafSRO+xofI6n7xUrrI=; b=LWLCEhSizZ9EC+M6UE9Iv5HP2sxlWGVoi5gFViA41jJA8OnjSMbrYCJQAoPGx8+rAU NIW84S04EI4NnUIhTbN2asAziCLTJJreTqJCk6c+IV9k0uzVHUU3ukFiFDvnY+teoZWz aFYGJQ8JolPxetAmTdZD2BeaiBW7OCtGUEFtdfWfUuVPNB7QA3popHf/HawUBW9r06cq 1iMnjiJHQ2jcb3LGQe9IasNGadPb+4RUVX8N3OWF227iaJAT1rnMPFoQrexlM+70nXUW oAz+fsiWnPFaudqMdJT1Q4S381F15VGjoC5YV9MelIgn5vt2CXhyGIoP21DyiT9puswD p4iQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=KEVfPUel; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-87654-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-87654-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id d29-20020a50cd5d000000b00564902f5ebcsi938631edj.184.2024.02.29.14.50.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 14:50:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-87654-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=KEVfPUel; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-87654-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-87654-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 70D7B1F23DA4 for ; Thu, 29 Feb 2024 22:50:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9E7DB481B1; Thu, 29 Feb 2024 22:50:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="KEVfPUel" 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 C019944362; Thu, 29 Feb 2024 22:50:14 +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=1709247014; cv=none; b=hZcwhClC14mEe0kcEPs3IX5aAbEXFloMNRbOQZZwbZYRjEXc+PS2/vHZoer2wH2tR2YTOWCZcK7kkDf9xq8FB+9BEPSwSgnvJhmNTueT3+9/O5/QFy4/HEGO2yBaEmBPAaAxN8orbUl2u2L+1Z9vxx475T7Xb2JacB/IZmt4Hkg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709247014; c=relaxed/simple; bh=ekfbDf15yCY6P//fpG4nQw5ky8qNnNsLRyFC6XWeW24=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=WANn5RsC+UeA74Pxc3o2Zwz4Tti7WdG9FGL9bqJ58oaYpYru2wdPVdbzhjrIFZyu2g/bCK2gqFYLySsL0yX+Hkuz86VAR+YlHsACFTu7QdNGlH+5Lx1No5TDaf+dCXDKDSo6QRNGmPP/wANRfEBhFnKAsbViQ8j5Bfy3cSm4+qc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KEVfPUel; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id F2EECC433F1; Thu, 29 Feb 2024 22:50:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709247014; bh=ekfbDf15yCY6P//fpG4nQw5ky8qNnNsLRyFC6XWeW24=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=KEVfPUeldaXF3E1IEwQP9f527BXlLSYs5cR6lTWBiFCOLJbEjt6TinoMDEmiXxaBg tyoUxDnjI1fydNJM7j2Jq1RxNgjxX0joSdYDA0OXih74XKzIQ5kQy1XLwhTH9MUJFI AtHjZM8cLiuwVBnIjgEi+FsS8vA8UyQb9y2SYS/f/eabUTqL5Qb2tlR6+DapGsrDmX nQpMs0rzXUElKE1OxLrJPPMx/21vuW0ItcybFxJD2+7LeKJ4SQUSReWo/4WsGJ+tDW bYpaEFh8QpfUXX2eUVRKq+wrhGcGlkc0XJLBTeWvEwEvTkLZIXtZ1Nw9qXjcJMu9X2 FYzEluqaAoYdw== Date: Fri, 1 Mar 2024 07:50:10 +0900 From: Masami Hiramatsu (Google) To: Jiri Olsa Cc: Steven Rostedt , linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] fprobe: Fix to allocate entry_data_size buffer with rethook instances Message-Id: <20240301075010.6125d953f6e109fe71cf9ffe@kernel.org> In-Reply-To: References: <170920576727.107552.638161246679734051.stgit@devnote2> 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 On Thu, 29 Feb 2024 22:58:54 +0100 Jiri Olsa wrote: > On Thu, Feb 29, 2024 at 08:22:47PM +0900, Masami Hiramatsu (Google) wrote: > > From: Masami Hiramatsu (Google) > > > > Fix to allocate fprobe::entry_data_size buffer with rethook instances. > > If fprobe doesn't allocate entry_data_size buffer for each rethook instance, > > fprobe entry handler can cause a buffer overrun when storing entry data in > > entry handler. > > > > Reported-by: Jiri Olsa > > Tested-by: Jiri Olsa Thanks for testing! Let me pick this to probe/fixes. Thank you, > > thanks, > jirka > > > Fixes: 4bbd93455659 ("kprobes: kretprobe scalability improvement") > > Cc: stable@vger.kernel.org > > Signed-off-by: Masami Hiramatsu (Google) > > --- > > kernel/trace/fprobe.c | 14 ++++++-------- > > 1 file changed, 6 insertions(+), 8 deletions(-) > > > > diff --git a/kernel/trace/fprobe.c b/kernel/trace/fprobe.c > > index 6cd2a4e3afb8..9ff018245840 100644 > > --- a/kernel/trace/fprobe.c > > +++ b/kernel/trace/fprobe.c > > @@ -189,9 +189,6 @@ static int fprobe_init_rethook(struct fprobe *fp, int num) > > { > > int size; > > > > - if (num <= 0) > > - return -EINVAL; > > - > > if (!fp->exit_handler) { > > fp->rethook = NULL; > > return 0; > > @@ -199,15 +196,16 @@ static int fprobe_init_rethook(struct fprobe *fp, int num) > > > > /* Initialize rethook if needed */ > > if (fp->nr_maxactive) > > - size = fp->nr_maxactive; > > + num = fp->nr_maxactive; > > else > > - size = num * num_possible_cpus() * 2; > > - if (size <= 0) > > + num *= num_possible_cpus() * 2; > > + if (num <= 0) > > return -EINVAL; > > > > + size = sizeof(struct fprobe_rethook_node) + fp->entry_data_size; > > + > > /* Initialize rethook */ > > - fp->rethook = rethook_alloc((void *)fp, fprobe_exit_handler, > > - sizeof(struct fprobe_rethook_node), size); > > + fp->rethook = rethook_alloc((void *)fp, fprobe_exit_handler, size, num); > > if (IS_ERR(fp->rethook)) > > return PTR_ERR(fp->rethook); > > > > -- Masami Hiramatsu (Google)