Received: by 2002:ab2:2997:0:b0:1ec:cbc4:63fb with SMTP id n23csp363122lqb; Thu, 29 Feb 2024 03:22:55 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVyw0BfCNHO4t4EuI2CMVPXw0pfaI2olSN0ftJNPKybvr9FagKLBwpqGsnzzxs8z7MA4gOGZBx3sYER828c9kzj3cBAfGN71jqZHLE4Dw== X-Google-Smtp-Source: AGHT+IEB42WmvGvtcAIFycjTLUcSR71eHIHfHy3GfxGlhV6Ev+f2+HFbjNVjnl64Ssa8w+UyY++3 X-Received: by 2002:a05:6a20:a51d:b0:19e:a45e:3b7e with SMTP id bd29-20020a056a20a51d00b0019ea45e3b7emr1715341pzb.53.1709205775120; Thu, 29 Feb 2024 03:22:55 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709205775; cv=pass; d=google.com; s=arc-20160816; b=z8NqIrP03pKcpVY6541AM92YFYTqjONoVP2NF5vL8iRL1xe1SWMOT9RQaLtecHbrsY fQtzMj8+q4EcpyfHCkwEIN0XO5VhU9XQDBM0xzSI8JAjLQFK7BSkDs2y+aZftNbuwzWg WMOng1IMtdAUgpwEoVeMDwMBEZvhiUzz/d4NaE/lb6yfCyRTZJpXwFcCNI2rl+Y+FGu8 H/LBm2ddxAtS1PrcJQuGcqkFztZjO55HVy7G3mTq/gwk2dCOSMSiDsjnf+exDhLyg4F1 RIkG309nfK9M43y5hc0rA2KK7OzfIfDuj3nGSxhxYgISzKNlwD9aMQX5VI28eTEiLPSW 1Uog== 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:user-agent:message-id:date :subject:cc:to:from:dkim-signature; bh=bp3+kk/2dMqk6L+/d/M3ncXHgcQbhV+vhcNPLSirnso=; fh=L7zrBYEqteD9/2a71tvMGKQ4sxyV1Z2iD8BbsJx87+A=; b=NaeTHs7wAtp3pQuXdkeFeETaEQf28PQqqlBnsifcNS4I2DVJODAOexXfQ7rUqz3HMa qxGL/0QfQrALauB3ZwVVfZGLgjdalQKlXmDvexoGpDTEetZ1lb0AhEh8aA8ZZpdWPJMr /NAaU/0cThRs1xqgLQpLlJeLC2N5DarzhhOy2KQy8Glj9CKburXSXasUQP3p60p/KDea n+LTaPu4a+aJGhIEMcSgAVPimK4JBD7TzsyKOTuawupjh89N61krErBMb2lrQfvxSiJJ 4zOBoSnEqz3BgkfayV319q7OKSVPDffSXhIV9n/vyeRaCP0BMiD0n/FF323Y/BSv1Ssd a6TA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=X2iUH+Fk; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-86624-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-86624-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 r37-20020a632065000000b005cf588da70fsi1174145pgm.643.2024.02.29.03.22.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 03:22:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-86624-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=X2iUH+Fk; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-86624-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-86624-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 7E8EE2830D2 for ; Thu, 29 Feb 2024 11:22:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 875E17B3F7; Thu, 29 Feb 2024 11:22:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="X2iUH+Fk" 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 A7F6A5645B; Thu, 29 Feb 2024 11:22:51 +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=1709205771; cv=none; b=rRIUpi3bQi2rNNPTXfCg9pXowPijF3ls3hQbyY3khoiQg5z1iLsKNTd4T+qKUB9Yo88oNpUMuGqqq0e7K+2FBGyO6uhnhzLXfXDisbZrvT2XQ+H9yMP6dWjvEOZ/f+WdF1nE/tkAXOmFjH6MXnNtKjDyWGa9rZOOjYURyFS/TnU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709205771; c=relaxed/simple; bh=+uuNbdv0lJbIvrDlmMr2gaI2mL9O4H2xUXrrYNBtcrg=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Content-Type; b=iomR2dB9+YxB2X5TSXQqZM5yT6/B+orGeZgqgQueZFlpyOOkBfhzXUmHRhvogK0ZNBR/Rnn24JqJbb1rmeOGnm9r8cm9eIqUySv1yNAEEQnzrip8tx3xEs12l2Ct9rOADx5BkuV78FA5+eFkN6iVjBhH/BxMlFcB3zUM69mVtEE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=X2iUH+Fk; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0C68AC433C7; Thu, 29 Feb 2024 11:22:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709205771; bh=+uuNbdv0lJbIvrDlmMr2gaI2mL9O4H2xUXrrYNBtcrg=; h=From:To:Cc:Subject:Date:From; b=X2iUH+Fk6aUrIE/zool+oaGs39saCKlIpbnrWIbUXX7r2XzjSqpoHdc8obAmJnILk lJJ+8G+TNHhgmpKJfDP7hxhEiWsW7V6tppMfEvlQYFt71hu2UTppk6zKuQ90e8SCaI mV8BX9vFpY3Z+mGAhUS8GOBJWOGpmwELxc+VcxVWwqeijrQBj5SlGuF/BpVBltbVR7 d/mQ1nH2uef2p1xy2KWOlew3zae5TwymaaqJM5XV2U4Xz8ABwyYcAAbhIiWbAR3dvc e72Yktvf3uc2v7PY+rsTLc0c7hisx78AnTEM0c77j0eJ8sK8h5wT60ru1CradJtQsD ccPMmLQ+d56xg== From: "Masami Hiramatsu (Google)" To: Steven Rostedt , linux-trace-kernel@vger.kernel.org Cc: Jiri Olsa , linux-kernel@vger.kernel.org Subject: [PATCH] fprobe: Fix to allocate entry_data_size buffer with rethook instances Date: Thu, 29 Feb 2024 20:22:47 +0900 Message-Id: <170920576727.107552.638161246679734051.stgit@devnote2> X-Mailer: git-send-email 2.34.1 User-Agent: StGit/0.19 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="utf-8" Content-Transfer-Encoding: 8bit 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 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);