Received: by 2002:ab2:2997:0:b0:1ec:cbc4:63fb with SMTP id n23csp365455lqb; Thu, 29 Feb 2024 03:28:27 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVaKICGctT5o1Y4Ed2nQkEgbfYR06zayqhZ7dQkMrVuZOcm8KDlUXqMcxraaQn5OvwmJ6RScYWBUJpQNGLkmtBuHI9g3M4+bdbRlpP7WQ== X-Google-Smtp-Source: AGHT+IHmXMYIFZsoS2Tqt+G2iJ4SqPRpxXdiX33HQEVfPU3Bq5tg3SJT8+k7rvof2mnwPt3+TFNB X-Received: by 2002:a05:6a20:d807:b0:1a1:e4b:f396 with SMTP id iv7-20020a056a20d80700b001a10e4bf396mr2603295pzb.0.1709206106604; Thu, 29 Feb 2024 03:28:26 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709206106; cv=pass; d=google.com; s=arc-20160816; b=WkyvX3VdL4ZVjoEojFl449Au7RaPqSqiPxTPNSILX5f13R6NpAezk8pJU4/zxxySkt egj0TjAgVsBOOUnO/aClOo2XVf6GiLfRwCxriUDnxNfzXIn+GuNaSncWyh1fRHqtT8Cg hfdpj6TCjlbY4E8VtMzbFL2VPjwKkhY0uab96L0PiiOebUFRzIiM+YPjuvW6bErEY1Os T9SONbEKZNOXRoW93vmRWFkkqQhfl/oTFuN+dr+uZ+w3vRy1WVn4QAsIqYIrUmqyvxdi QQVrHcULbJj/UMxIRjjgZ0OMN81h7KalGJTK/WvRbB+wc84UyfmprLB4dCm7R28JM30q BrYA== 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=QgHyb8Z4Dqt7dpt2RnPOQ7d2hRh/U4vbnmy9ulsGjcM=; fh=xDgAbOzyWwG9Bz2T/YB2PnAKVGHnoNMoDIaGiczEyL8=; b=kBBG9ndDeKeX89Jync1ClWvEUH5aTjoZrUHPYXFa+Q/iaBgPV5P4Qudt5GbrxIMm6X HQ288ijc3YOdjl7/oWzEePBZx+Y3NnLlgnbFqJbj5/F4XMyw6XuEvthMO+wmnNtH65vN tXHUAHuenc4chn2j4vQ1tP9OhmtdlwrlOtQmgTBOjhslu8JjwFDMRJDN5hgXKLfGiezl 2y/3iVNlu7xpmxbI08DmyXudT41Kx7sdRTNW79Yhkwb2RsLALFslMGUEhTAciSm5i3CJ xS81elCOOnEml8dQ/lbk8cVlkp3g2TdYOZMEfL6cOJJNkJjC5zWr95QkR6MKqO8VjVrP DgRQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=HFKX78E9; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-86629-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-86629-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id o11-20020a63e34b000000b005d8b57bc704si1202091pgj.389.2024.02.29.03.28.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 03:28:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-86629-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=HFKX78E9; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-86629-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-86629-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 41ACB285977 for ; Thu, 29 Feb 2024 11:28:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 33FB77BAF0; Thu, 29 Feb 2024 11:28:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="HFKX78E9" 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 594457AE4D; Thu, 29 Feb 2024 11:28:19 +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=1709206100; cv=none; b=mM26/TDO4+QTg3z5GytkDwPu5EvWHXiKgj8p0taNz61GVy+84EFFuv930Cm/IHQKd29FKCis9QLOLI6SJWivxpwhHKpfeWXJKk87BTWQm9JmD02lr5o+Kq6m4IbKLv74iyMBafhLzkT7sr0L6eGHf2EQQedxkFN7eP3XuxiD3GQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709206100; c=relaxed/simple; bh=K/dQdNCw8tgzoiIBAXZRdigwTtDv7ZgnD6yJd6kn6T4=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=Og96IFKyIzngZ5mg5uBdFSvdaaCYCCXjsDrvRKpwgkyF4Al0mWw6YwkyujJg+O39Ue8K+JKrM/hDFkWPlfXuMnyj3zpv1yK7bFa7HKzB21Qvvd/Ei/Z84JvBeQBQgE5of5I3MTCucQ9IpqQxBvBb23msyxr8OP1mGpfn5pOsU24= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=HFKX78E9; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4C89AC433C7; Thu, 29 Feb 2024 11:28:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709206099; bh=K/dQdNCw8tgzoiIBAXZRdigwTtDv7ZgnD6yJd6kn6T4=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=HFKX78E9g6n8aiCYYQIDDPOkPvPHYoHF4Txx/dZH+ekO5Xo856L7IGX3WdzNHMpcf /D9nRnPSfXrFrs1vJ/m6J/BpIHCgW9zlHZWawfRjwv9OsV9hi5NfSlPtSTnIBQI7+s U7tE+iIVKOwpD8u4MtBBduz3qOLicukz3UzXDyP+X1wX/ZNexJ4P7Huxj+GMMrsfBG eRV4LwSkahPc4Ixsq+if6l2g8XOlfNRiVBhUvmp3Fp9FqrJf4W8BVXLV4xF0eTdQst R/AbZmq1ukNIwRB/kftsxka+F6uSGyTiGK2JdzGLhrDoMmE/pm41wvmaYRgsBYofTu rOf25IE35/o5Q== Date: Thu, 29 Feb 2024 20:28:14 +0900 From: Masami Hiramatsu (Google) To: "Masami Hiramatsu (Google)" Cc: Steven Rostedt , linux-trace-kernel@vger.kernel.org, Jiri Olsa , linux-kernel@vger.kernel.org Subject: Re: [PATCH] fprobe: Fix to allocate entry_data_size buffer with rethook instances Message-Id: <20240229202814.3ee3568bda16099e41c94569@kernel.org> In-Reply-To: <170920576727.107552.638161246679734051.stgit@devnote2> 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 20:22:47 +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. > Oops, missed a URL. > Reported-by: Jiri Olsa Closes: https://lore.kernel.org/all/Zd9eBn2FTQzYyg7L@krava/ Thanks, > 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)