Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp2439402ioo; Sat, 28 May 2022 13:45:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy3A6MZZgJ8sS02lPbFpLGkNPSu98vq5LimJZmxW93Rm0cZaXqdLHUvOaB/tMH/5gk36f2W X-Received: by 2002:a17:902:aa4b:b0:15f:b2c:73c7 with SMTP id c11-20020a170902aa4b00b0015f0b2c73c7mr48760934plr.164.1653770707327; Sat, 28 May 2022 13:45:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653770707; cv=none; d=google.com; s=arc-20160816; b=iv2qd5PPlTbhCG0BcItmZnJeUPWhtRsraU3pc5zTqKS07AfeQidSMMr97cBTYMvPEC 8zbZcS7V1jafI0Vu7bJpilsIewkylJ9TRKnzqcKt+vX/u4PsQWTAY2gyb7hMO6AMWO63 dAbABHPejCsUQS+uaEZIeg2A0be8wkqftrwliFFQuxpPQLFk4Yc0BR1ajWWGi5FTh4pA WGRyIV/tF2p998IkNpiqKM1a1+4IfUnnuqfH+5kbUDDPNZP2C+RuIW2Ym5ZrlSNLatbt fVRJB10CgmP2qtklYZALYmNzFqx1UTFo1eEOAVqsysPAqBxl8wVeXRlUFGd+nmDBVRem dLtg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=4h3tXOGiY36YATcPdK+ElNYo3azC6b3KXMcZ7NDPHIc=; b=klARZPd28z+iXhlHe7Z6JZCCGZSlJX6RisPTjZ6LMmXOoiWF7GT0xDEyaWBxfv/OG1 kbxOLK4nYSyKSmeqPOEiPGwECG/0/gi+0ExGts9eEHDegcb5bWOiHQpxstvkuBsPf8hu hJB0nejvjBQEhNDnBkRvzCnsNN1QFikn39rCsxoIOdCIu260Gn/0aa7OZzhWL7TWjNmv 3mrwwuvang9ppCPZi+SB0UrScYIChZrvwNqmxFbbKP22bb0D1ohpmdz3p3tW9T4LlC2/ NhHeHQyFIo+IoUBKhFLvJl9xgrRPAOl3zTn8g+6b0/kLLXTrOpniv38Y4xUijZBP79c/ kGGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=WBcLT8nl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id c34-20020a634e22000000b003f6456673acsi10769719pgb.20.2022.05.28.13.45.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 May 2022 13:45:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=WBcLT8nl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A351F65436; Sat, 28 May 2022 12:44:33 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354667AbiE0U4y (ORCPT + 99 others); Fri, 27 May 2022 16:56:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354683AbiE0U4u (ORCPT ); Fri, 27 May 2022 16:56:50 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A432E1157DE; Fri, 27 May 2022 13:56:46 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id ECDBD61ECC; Fri, 27 May 2022 20:56:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8E11BC385A9; Fri, 27 May 2022 20:56:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1653685005; bh=DLrBz8l/IovLpHyna3M9d/g4KiCI0WlAZfJ/FMILEVQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WBcLT8nls24IWn6bjrYkVJMkOWvFCxsxX4RNc9geGvjBn+QWmSGqpcpMApxOFVJA2 vDjuXqF84gKuMJlkVnFR1AfPI6QGK1H71IEaHb7psBivbrtwt6V+Zl2dvFWxHcQ/y2 R4hXbn0fUbDE84FXSgWe7k6PCkCKL+eNNzsdw8u7okZ6a6TWjaaMIRyfCCCNvEwaLu q/+yqYBdhciFhULZkKyCGCZGNOF2d/fX+knqC7NezooY1kq7FD5td2bzKhkJpjKg1+ uAOMn32gy9lOOJpW113pjJKhd8tNU7J5wrY1/wx67Eom7pMbgdGAhH0hyvYZ3mXBaF Jw/xUFnxmoO5Q== From: Jiri Olsa To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: netdev@vger.kernel.org, bpf@vger.kernel.org, lkml , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Steven Rostedt , Masami Hiramatsu Subject: [PATCH bpf-next 2/3] ftrace: Keep address offset in ftrace_lookup_symbols Date: Fri, 27 May 2022 22:56:10 +0200 Message-Id: <20220527205611.655282-3-jolsa@kernel.org> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220527205611.655282-1-jolsa@kernel.org> References: <20220527205611.655282-1-jolsa@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We want to store the resolved address on the same index as the symbol string, because that's the user (bpf kprobe link) code assumption. Also making sure we don't store duplicates that might be present in kallsyms. Fixes: bed0d9a50dac ("ftrace: Add ftrace_lookup_symbols function") Signed-off-by: Jiri Olsa --- kernel/trace/ftrace.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index 674add0aafb3..00d0ba6397ed 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -7984,15 +7984,23 @@ static int kallsyms_callback(void *data, const char *name, struct module *mod, unsigned long addr) { struct kallsyms_data *args = data; + const char **sym; + int idx; - if (!bsearch(&name, args->syms, args->cnt, sizeof(*args->syms), symbols_cmp)) + sym = bsearch(&name, args->syms, args->cnt, sizeof(*args->syms), symbols_cmp); + if (!sym) + return 0; + + idx = sym - args->syms; + if (args->addrs[idx]) return 0; addr = ftrace_location(addr); if (!addr) return 0; - args->addrs[args->found++] = addr; + args->addrs[idx] = addr; + args->found++; return args->found == args->cnt ? 1 : 0; } @@ -8017,6 +8025,7 @@ int ftrace_lookup_symbols(const char **sorted_syms, size_t cnt, unsigned long *a struct kallsyms_data args; int err; + memset(addrs, 0x0, sizeof(*addrs) * cnt); args.addrs = addrs; args.syms = sorted_syms; args.cnt = cnt; -- 2.35.3