From patchwork Thu Feb 29 11:22:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 208312 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2097:b0:108:e6aa:91d0 with SMTP id gs23csp323214dyb; Thu, 29 Feb 2024 03:23:02 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUgwQ6pBgkBv3n0IrslnU94MDGqqbKPkFvmkRamUTs3WDpJYPPaAJSS7RwL4jbMmBqDdQDOKMx1LcfTissnJp+Dnkvoow== X-Google-Smtp-Source: AGHT+IGfKKPcFcbcNwZuQhLW2wAklN6RJftOt6xkSUcw+5O5bL1lcB378UJiBeUGqYoT3oNFOzuy X-Received: by 2002:a17:906:298c:b0:a43:f267:789f with SMTP id x12-20020a170906298c00b00a43f267789fmr1216943eje.41.1709205782741; Thu, 29 Feb 2024 03:23:02 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709205782; cv=pass; d=google.com; s=arc-20160816; b=KrW60wlQQHX0fNK7egouhIkh/3bTGOCE9rnTheXHA7lKdwUrNDPVlXzE+HRfVePH6f Zh7N3kV9LsPdU43LE22wIFeNQrOHevzKrHi4XjNkN3g15Pa9C4c57RHfUsUGc1KFFZL5 G/wmBpfSaW7FZt71GnVXZDD/N+MqO2o1RkCXVx0YGNbG+4BWD1u3GXBrlYkROFI1qaxh g6TUUrAD7B+ktc5P/yOF9c/voAknZi0ao2wLQha8PuY018wMKsaVuTUeWjhx9+IIhrqh h1qYY/R7L8Ckak/iUSncXj0JtWDr9ZUiz2ft1iIFoh28uwoxL+s4upomxsMgWrqx0Wve Wwaw== 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-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-86624-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id d8-20020a1709064c4800b00a4425f89409si486359ejw.821.2024.02.29.03.23.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 03:23:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-86624-ouuuleilei=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=X2iUH+Fk; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-86624-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-86624-ouuuleilei=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 575DA1F24642 for ; Thu, 29 Feb 2024 11:23:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5893B7BB13; Thu, 29 Feb 2024 11:22:54 +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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792232162795806163 X-GMAIL-MSGID: 1792232162795806163 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) Tested-by: Jiri Olsa --- 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);