From patchwork Sun Jul 9 02:56:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 13305741 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 596B1EB64DC for ; Sun, 9 Jul 2023 02:56:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229710AbjGIC4w (ORCPT ); Sat, 8 Jul 2023 22:56:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229458AbjGIC4v (ORCPT ); Sat, 8 Jul 2023 22:56:51 -0400 Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B97EE46; Sat, 8 Jul 2023 19:56:50 -0700 (PDT) Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-666eef03ebdso1437992b3a.1; Sat, 08 Jul 2023 19:56:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1688871410; x=1691463410; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=VuX1Oey0L/NEX0/2PFEsrmGZ26pzBt0sRqMiZlxNdvM=; b=iHgDWAMnzwd+k0xbl8Okq9Wounrr51goxhCZHyxdXcAaDoKSKjVMrwLwECo+oArKph m7JDqA4FdVzQ7dBG0LACK4BfJ4NpoeHqWRvkgqCn6kWR7jGnHCYaHt/Ni1dnUV40aONu V+CNdYKztIbzcE5KkK7ibjM09hB/v6hTvWqACkhGeAJjbcz3pgkO3RKBar/rqtPq83eB a/BWsAbzsa9cFSeDR8Kx4So7ImR8zaoC5TvX/skPUgtWRDT8zJ2KtxsvFckQIMyLAmi5 Q68A1mhMt/gxZHS7kQBGlWtPzjxDIdQ7OKSw+sx7S36KAf+n/wAlIPOOIjdm5oMT31Eo 9+iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688871410; x=1691463410; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VuX1Oey0L/NEX0/2PFEsrmGZ26pzBt0sRqMiZlxNdvM=; b=V8ifbj8E53bm7MbbdZuCm33jQ3q94oCD8SJlwJ8kgQmRIxNIY+FqQ6MCUB0iq0wQ9y hbrWDf2eY5Sjxwx01OfyU7XllUxnKe+dOAebG8WDSJenuyu0DuCWw7RR/efQBGq6shwu f6fJHtfacNZTOFPJXV3O7K9DsJ9Tu49CT22JgVPZIo6r0uDjpal0UgXXC4X3oOv3UUL6 sa3szfzakBUmuAAeFa/7IELu7gD8R+6D8mhb56IufpMyFNkxQNQfqZus97S1r0a6L28H lUTknRvDzbUCoHCIHLHDOopkUxWY6zi2fJPYV2FDHG3THYkw+yC+Y/gODd3vxuxsj9gU kX7A== X-Gm-Message-State: ABy/qLZ2Dgodfonou0Oaq6LyxVZEGWIWG7maqs+Vj0uZEJRToTI9EyCT yMSpoBPXan/aF8iw/OgCT2o= X-Google-Smtp-Source: APBJJlFnksx8/ZuiwKN9h/J7cSZ4seVEXhQAv9HGBVT29+OmDyeEqJnzwrmf86va5K0twuPKozCuAA== X-Received: by 2002:a05:6a00:80a:b0:666:a46b:63c9 with SMTP id m10-20020a056a00080a00b00666a46b63c9mr8172172pfk.11.1688871409813; Sat, 08 Jul 2023 19:56:49 -0700 (PDT) Received: from vultr.guest ([2001:19f0:ac01:14bb:5400:4ff:fe80:41df]) by smtp.gmail.com with ESMTPSA id e9-20020aa78249000000b00682ad247e5fsm5043421pfn.179.2023.07.08.19.56.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Jul 2023 19:56:49 -0700 (PDT) From: Yafang Shao To: ast@kernel.org, daniel@iogearbox.net, john.fastabend@gmail.com, andrii@kernel.org, martin.lau@linux.dev, song@kernel.org, yhs@fb.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, quentin@isovalent.com, rostedt@goodmis.org, mhiramat@kernel.org Cc: bpf@vger.kernel.org, linux-trace-kernel@vger.kernel.org, Yafang Shao Subject: [PATCH v7 bpf-next 04/10] bpf: Protect probed address based on kptr_restrict setting Date: Sun, 9 Jul 2023 02:56:24 +0000 Message-Id: <20230709025630.3735-5-laoar.shao@gmail.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20230709025630.3735-1-laoar.shao@gmail.com> References: <20230709025630.3735-1-laoar.shao@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-kernel@vger.kernel.org The probed address can be accessed by userspace through querying the task file descriptor (fd). However, it is crucial to adhere to the kptr_restrict setting and refrain from exposing the address if it is not permitted. Signed-off-by: Yafang Shao Acked-by: Jiri Olsa --- kernel/trace/trace_kprobe.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c index 1b3fa7b854aa..249eb14d0f7a 100644 --- a/kernel/trace/trace_kprobe.c +++ b/kernel/trace/trace_kprobe.c @@ -1551,7 +1551,10 @@ int bpf_get_kprobe_info(const struct perf_event *event, u32 *fd_type, } else { *symbol = NULL; *probe_offset = 0; - *probe_addr = (unsigned long)tk->rp.kp.addr; + if (kallsyms_show_value(current_cred())) + *probe_addr = (unsigned long)tk->rp.kp.addr; + else + *probe_addr = 0; } return 0; }