From patchwork Mon Mar 4 03:40:06 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: 209368 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:fa17:b0:10a:f01:a869 with SMTP id ju23csp1200505dyc; Sun, 3 Mar 2024 19:40:32 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW/hUKBjTR1HGRTWHBOPtX7ONGn3f+TxwawBb0GMM4BfbTG6TUMBr5yfZM2uJn2nNmCkzlWJCLw6V1C1UOobaJHsoDVoA== X-Google-Smtp-Source: AGHT+IEYee+4ywhgOkzDQ5XvBu18MFjZ86FRlcPHd32yluiHXOri/tkZmePzArFjhKgilkuHAxRB X-Received: by 2002:a05:6214:11b1:b0:68f:2b35:5edf with SMTP id u17-20020a05621411b100b0068f2b355edfmr9374605qvv.13.1709523631981; Sun, 03 Mar 2024 19:40:31 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709523631; cv=pass; d=google.com; s=arc-20160816; b=mTPoQPQWstztZVM4Zplg8lruCQ5eEZXvfrFisALI5fCPg3xML47K0cr3Ltq1iD01kv ZsO/LGLquwGpTS30nuNlgH8rTFzPUKZF/Lde9gtBwLswfMjBGHVgC97mSE1+pSzAdg95 gCt6vw32VMAYfIyEDx7IQPnEN6GYyGx8GOU9YcpaITf8DD4t19wZwE+7zibQ9KGIF2V0 j4Ee9SEtrjDWqBrtFLKYGcle1mRMOSMeLQdF1eCBBkhxF7FE9OBiBOc+dB9dpja6d1A3 th3791XcTYD1I1PIPe3POxzI4AfZfy4Fgg3M2PqXy29BPzfChQ2BALPsdRjyeSX6iWTk OrGQ== 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:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=pQiqdxJSsXjk2K24IpNGVSc7INniEvPFX2F0k2u2Hz4=; fh=+uEoxECwu+GZPXA+yzsV/ZJCsf7WyFzcH+9RxOmv8OU=; b=fZenPUOeX7jxXXYu57H+YWgtTuJCJfey5NC60N1tnwYCA87VGa2EiF757RWf+/nxij SjNojzgRnyBbxP1iFU/vFiLBOkW9WK5hrzljExSDlPpf0pJPd3xvK63RyKiHmEx/0L9S 1gD/m/RxkjCS24XkeRIyi7m4+6d5uZ54U6l/hlJAXMrgY3iGytspT80Op7VGnxqlRPE6 qw3vEsOvrAlvxLv1v0L9Vm5YEYuneaBKwkLWvor761WsFxcLGF724V3jgX5WxRTqzRaH NR2HkaVh7moCgeRmFzx6wllkSphE+rNaUuCfyHz1NYPW3xMLbLH7nstJAVwnXFgin6Ui xSdw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=NacBqozn; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-90019-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-90019-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id j5-20020a05621419c500b0068fcc76644bsi8978101qvc.99.2024.03.03.19.40.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Mar 2024 19:40:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-90019-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=NacBqozn; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-90019-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-90019-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id C2E211C2098E for ; Mon, 4 Mar 2024 03:40:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8D5D66FDC; Mon, 4 Mar 2024 03:40:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="NacBqozn" 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 005346ABF; Mon, 4 Mar 2024 03:40:10 +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=1709523611; cv=none; b=SglWrATUccwsld1cnE998xkQK2AtRTuLd4LfqW1lguhag7HTUn7yNWCnvVfXmZTaoA0/7O2DyJq83h29N9+QWO8RI87f1Hl8eg+ZfYs1cxuM14Gogb/L0dSAhrLYxQtF8PTg8VEz8e9+Pl4ocpDCr/NWHEPHC+2OiZi1SaZ8n5Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709523611; c=relaxed/simple; bh=S57LBagA5sfS5PxIPRcS7nfl3DEhORZYcIUUZT8qPdc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=tvY3NgJHHDo84RKB8mZhz/nGHgQE4QCdqAOLZzQliVvHAxOazLd2opmLI0/bi07LsGH6yU4/0d3oc0DR76BBLpJFN8bNZnr1HYnlgJH8tMocZdtU17IxbS8ozibz+o4edtH2MpngrpRioQignfseu4Omqk6tfFP+JqztPLvjycU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NacBqozn; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2A2D8C433F1; Mon, 4 Mar 2024 03:40:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709523610; bh=S57LBagA5sfS5PxIPRcS7nfl3DEhORZYcIUUZT8qPdc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NacBqoznCzzfaWEgzeK4cvGYokk7JfPd7hZI2y1k3H9t5eH8As1V1XnB/k5PW8iIA LHiFLnzBTQ4dfIsZTn7REGHpP+GdHprxLw50GHsRIgjC6fJyU7DFGF/I7rJzQ7JcdK XuyJMdgX9pPMbh10GuKq2QWoupVs4QhdOdgDJULEMQinHfHPrBwOaW+A+IF1uzzYcD tvTBbnDwx6g21Phai5nKIh0L++9ZZcVdcgqqRiV/01leBSzP28ZK3/5fB7GYlUF3J+ KSzCYCRKKb2yNHSLn368v5CR0iqK45rFyAFoNXQUJTOl3gtc4AoCYIZRw0bv6Oi/S/ S6Wr1vQUJCfuw== From: "Masami Hiramatsu (Google)" To: Steven Rostedt , Jiri Olsa Cc: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, mhiramat@kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v3 1/8] fprobe: Fix to allocate entry_data_size buffer with rethook instances Date: Mon, 4 Mar 2024 12:40:06 +0900 Message-Id: <170952360657.229804.345771440723430834.stgit@devnote2> X-Mailer: git-send-email 2.34.1 In-Reply-To: <170952359657.229804.14867636035660590574.stgit@devnote2> References: <170952359657.229804.14867636035660590574.stgit@devnote2> 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: 1792565451651165051 X-GMAIL-MSGID: 1792565451651165051 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. Link: https://lore.kernel.org/all/170920576727.107552.638161246679734051.stgit@devnote2/ Reported-by: Jiri Olsa Closes: https://lore.kernel.org/all/Zd9eBn2FTQzYyg7L@krava/ Fixes: 4bbd93455659 ("kprobes: kretprobe scalability improvement") Cc: stable@vger.kernel.org Tested-by: Jiri Olsa 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);