From nobody Tue Apr 28 03:55:20 2026 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 7189FC433EF for ; Mon, 6 Jun 2022 18:48:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232007AbiFFSsB (ORCPT ); Mon, 6 Jun 2022 14:48:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48460 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232013AbiFFSry (ORCPT ); Mon, 6 Jun 2022 14:47:54 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46D341B184E; Mon, 6 Jun 2022 11:47:52 -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 ams.source.kernel.org (Postfix) with ESMTPS id D739AB81AE6; Mon, 6 Jun 2022 18:47:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3E610C385A9; Mon, 6 Jun 2022 18:47:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1654541269; bh=gQpvTJizsykqpbNvB/Wa1n2xAu4qKYCH5GGTeAUbDw8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=huU2+Ev8sAyp3RIVPzLwLLiAN4DMAFTxQN2EQHOmNp/KGbqPNUPP3HhupCT0abTsN n3mNyT2biiSMRfgDrOndXRvWy90GYFw12WPDiQGRUVR2QvdTmkk5SrY7nrPzSYB1Dx ueMwHBodpHsQ8TCEv1dE6TN58hHk+Fhg92F2UO3/kRaqsFNnAE2xega26qUK1lSdcB nMcoSWmrM9mMehIN1Yf3uiQo63P7+2WsDExs0LpJ3p8PZMKL7MwSofLuLdP6tpisGc svte9vm4ziBmiSY2MPHNeufR6qb/NjizF6/xrnh18FngfNGe07BVF1cCR69cIKzq2P sh3G+1JlDDZ/w== From: Jiri Olsa To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: Song Liu , netdev@vger.kernel.org, bpf@vger.kernel.org, lkml , Martin KaFai Lau , Yonghong Song , John Fastabend , KP Singh , Steven Rostedt , Masami Hiramatsu Subject: [PATCHv2 bpf 1/3] selftests/bpf: Shuffle cookies symbols in kprobe multi test Date: Mon, 6 Jun 2022 20:47:29 +0200 Message-Id: <20220606184731.437300-2-jolsa@kernel.org> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220606184731.437300-1-jolsa@kernel.org> References: <20220606184731.437300-1-jolsa@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" There's a kernel bug that causes cookies to be misplaced and the reason we did not catch this with this test is that we provide bpf_fentry_test* functions already sorted by name. Shuffling function bpf_fentry_test2 deeper in the list and keeping the current cookie values as before will trigger the bug. The kernel fix is coming in following changes. Acked-by: Song Liu Signed-off-by: Jiri Olsa --- .../selftests/bpf/prog_tests/bpf_cookie.c | 78 +++++++++---------- .../selftests/bpf/progs/kprobe_multi.c | 24 +++--- 2 files changed, 51 insertions(+), 51 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/bpf_cookie.c b/tools/te= sting/selftests/bpf/prog_tests/bpf_cookie.c index 83ef55e3caa4..2974b44f80fa 100644 --- a/tools/testing/selftests/bpf/prog_tests/bpf_cookie.c +++ b/tools/testing/selftests/bpf/prog_tests/bpf_cookie.c @@ -121,24 +121,24 @@ static void kprobe_multi_link_api_subtest(void) }) =20 GET_ADDR("bpf_fentry_test1", addrs[0]); - GET_ADDR("bpf_fentry_test2", addrs[1]); - GET_ADDR("bpf_fentry_test3", addrs[2]); - GET_ADDR("bpf_fentry_test4", addrs[3]); - GET_ADDR("bpf_fentry_test5", addrs[4]); - GET_ADDR("bpf_fentry_test6", addrs[5]); - GET_ADDR("bpf_fentry_test7", addrs[6]); + GET_ADDR("bpf_fentry_test3", addrs[1]); + GET_ADDR("bpf_fentry_test4", addrs[2]); + GET_ADDR("bpf_fentry_test5", addrs[3]); + GET_ADDR("bpf_fentry_test6", addrs[4]); + GET_ADDR("bpf_fentry_test7", addrs[5]); + GET_ADDR("bpf_fentry_test2", addrs[6]); GET_ADDR("bpf_fentry_test8", addrs[7]); =20 #undef GET_ADDR =20 - cookies[0] =3D 1; - cookies[1] =3D 2; - cookies[2] =3D 3; - cookies[3] =3D 4; - cookies[4] =3D 5; - cookies[5] =3D 6; - cookies[6] =3D 7; - cookies[7] =3D 8; + cookies[0] =3D 1; /* bpf_fentry_test1 */ + cookies[1] =3D 2; /* bpf_fentry_test3 */ + cookies[2] =3D 3; /* bpf_fentry_test4 */ + cookies[3] =3D 4; /* bpf_fentry_test5 */ + cookies[4] =3D 5; /* bpf_fentry_test6 */ + cookies[5] =3D 6; /* bpf_fentry_test7 */ + cookies[6] =3D 7; /* bpf_fentry_test2 */ + cookies[7] =3D 8; /* bpf_fentry_test8 */ =20 opts.kprobe_multi.addrs =3D (const unsigned long *) &addrs; opts.kprobe_multi.cnt =3D ARRAY_SIZE(addrs); @@ -149,14 +149,14 @@ static void kprobe_multi_link_api_subtest(void) if (!ASSERT_GE(link1_fd, 0, "link1_fd")) goto cleanup; =20 - cookies[0] =3D 8; - cookies[1] =3D 7; - cookies[2] =3D 6; - cookies[3] =3D 5; - cookies[4] =3D 4; - cookies[5] =3D 3; - cookies[6] =3D 2; - cookies[7] =3D 1; + cookies[0] =3D 8; /* bpf_fentry_test1 */ + cookies[1] =3D 7; /* bpf_fentry_test3 */ + cookies[2] =3D 6; /* bpf_fentry_test4 */ + cookies[3] =3D 5; /* bpf_fentry_test5 */ + cookies[4] =3D 4; /* bpf_fentry_test6 */ + cookies[5] =3D 3; /* bpf_fentry_test7 */ + cookies[6] =3D 2; /* bpf_fentry_test2 */ + cookies[7] =3D 1; /* bpf_fentry_test8 */ =20 opts.kprobe_multi.flags =3D BPF_F_KPROBE_MULTI_RETURN; prog_fd =3D bpf_program__fd(skel->progs.test_kretprobe); @@ -181,12 +181,12 @@ static void kprobe_multi_attach_api_subtest(void) struct kprobe_multi *skel =3D NULL; const char *syms[8] =3D { "bpf_fentry_test1", - "bpf_fentry_test2", "bpf_fentry_test3", "bpf_fentry_test4", "bpf_fentry_test5", "bpf_fentry_test6", "bpf_fentry_test7", + "bpf_fentry_test2", "bpf_fentry_test8", }; __u64 cookies[8]; @@ -198,14 +198,14 @@ static void kprobe_multi_attach_api_subtest(void) skel->bss->pid =3D getpid(); skel->bss->test_cookie =3D true; =20 - cookies[0] =3D 1; - cookies[1] =3D 2; - cookies[2] =3D 3; - cookies[3] =3D 4; - cookies[4] =3D 5; - cookies[5] =3D 6; - cookies[6] =3D 7; - cookies[7] =3D 8; + cookies[0] =3D 1; /* bpf_fentry_test1 */ + cookies[1] =3D 2; /* bpf_fentry_test3 */ + cookies[2] =3D 3; /* bpf_fentry_test4 */ + cookies[3] =3D 4; /* bpf_fentry_test5 */ + cookies[4] =3D 5; /* bpf_fentry_test6 */ + cookies[5] =3D 6; /* bpf_fentry_test7 */ + cookies[6] =3D 7; /* bpf_fentry_test2 */ + cookies[7] =3D 8; /* bpf_fentry_test8 */ =20 opts.syms =3D syms; opts.cnt =3D ARRAY_SIZE(syms); @@ -216,14 +216,14 @@ static void kprobe_multi_attach_api_subtest(void) if (!ASSERT_OK_PTR(link1, "bpf_program__attach_kprobe_multi_opts")) goto cleanup; =20 - cookies[0] =3D 8; - cookies[1] =3D 7; - cookies[2] =3D 6; - cookies[3] =3D 5; - cookies[4] =3D 4; - cookies[5] =3D 3; - cookies[6] =3D 2; - cookies[7] =3D 1; + cookies[0] =3D 8; /* bpf_fentry_test1 */ + cookies[1] =3D 7; /* bpf_fentry_test3 */ + cookies[2] =3D 6; /* bpf_fentry_test4 */ + cookies[3] =3D 5; /* bpf_fentry_test5 */ + cookies[4] =3D 4; /* bpf_fentry_test6 */ + cookies[5] =3D 3; /* bpf_fentry_test7 */ + cookies[6] =3D 2; /* bpf_fentry_test2 */ + cookies[7] =3D 1; /* bpf_fentry_test8 */ =20 opts.retprobe =3D true; =20 diff --git a/tools/testing/selftests/bpf/progs/kprobe_multi.c b/tools/testi= ng/selftests/bpf/progs/kprobe_multi.c index 93510f4f0f3a..08f95a8155d1 100644 --- a/tools/testing/selftests/bpf/progs/kprobe_multi.c +++ b/tools/testing/selftests/bpf/progs/kprobe_multi.c @@ -54,21 +54,21 @@ static void kprobe_multi_check(void *ctx, bool is_retur= n) =20 if (is_return) { SET(kretprobe_test1_result, &bpf_fentry_test1, 8); - SET(kretprobe_test2_result, &bpf_fentry_test2, 7); - SET(kretprobe_test3_result, &bpf_fentry_test3, 6); - SET(kretprobe_test4_result, &bpf_fentry_test4, 5); - SET(kretprobe_test5_result, &bpf_fentry_test5, 4); - SET(kretprobe_test6_result, &bpf_fentry_test6, 3); - SET(kretprobe_test7_result, &bpf_fentry_test7, 2); + SET(kretprobe_test2_result, &bpf_fentry_test2, 2); + SET(kretprobe_test3_result, &bpf_fentry_test3, 7); + SET(kretprobe_test4_result, &bpf_fentry_test4, 6); + SET(kretprobe_test5_result, &bpf_fentry_test5, 5); + SET(kretprobe_test6_result, &bpf_fentry_test6, 4); + SET(kretprobe_test7_result, &bpf_fentry_test7, 3); SET(kretprobe_test8_result, &bpf_fentry_test8, 1); } else { SET(kprobe_test1_result, &bpf_fentry_test1, 1); - SET(kprobe_test2_result, &bpf_fentry_test2, 2); - SET(kprobe_test3_result, &bpf_fentry_test3, 3); - SET(kprobe_test4_result, &bpf_fentry_test4, 4); - SET(kprobe_test5_result, &bpf_fentry_test5, 5); - SET(kprobe_test6_result, &bpf_fentry_test6, 6); - SET(kprobe_test7_result, &bpf_fentry_test7, 7); + SET(kprobe_test2_result, &bpf_fentry_test2, 7); + SET(kprobe_test3_result, &bpf_fentry_test3, 2); + SET(kprobe_test4_result, &bpf_fentry_test4, 3); + SET(kprobe_test5_result, &bpf_fentry_test5, 4); + SET(kprobe_test6_result, &bpf_fentry_test6, 5); + SET(kprobe_test7_result, &bpf_fentry_test7, 6); SET(kprobe_test8_result, &bpf_fentry_test8, 8); } =20 --=20 2.35.3 From nobody Tue Apr 28 03:55:20 2026 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 89F80C43334 for ; Mon, 6 Jun 2022 18:48:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232011AbiFFSs2 (ORCPT ); Mon, 6 Jun 2022 14:48:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50416 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231971AbiFFSsO (ORCPT ); Mon, 6 Jun 2022 14:48:14 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 542EA1B4363; Mon, 6 Jun 2022 11:48:02 -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 5EE4061423; Mon, 6 Jun 2022 18:48:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6B6A9C385A9; Mon, 6 Jun 2022 18:47:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1654541280; bh=oenzZKBwu+yYvuKRKzmfDgx5zIbYMMw/HD87fYbkTCM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Q8nZoxtGviHxv1D34flnChvIGDNF0DgmOxsB1sxtkcQ1wrnkOuj8sRWqhGs2FC3t1 RbOSREKzxDPELadYHijNxeMGkQCQ8hC425AA5usH4LkHxYxZLxCzPfQ8pvimjWOHy5 zvojYImseHB4VxQi1JPOvczGIXzkZlklHSG9DPUzkFbs2ckI6K86JXWY81e1M1ywmm 4BG0uWjVfs7Yssp0Pghe7vtRYWyj9Ays9kkrge0bAFuYwPPLJ3zFUK9E1ipLah+Bqz fGZZiolhPwZyp2eOIsCsBdxymAxKnX/sj1UZR/ZvhLXLNvb/+07Tjs6pxQlvDjndcG k95nUpfk3RauA== From: Jiri Olsa To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: Song Liu , Steven Rostedt , netdev@vger.kernel.org, bpf@vger.kernel.org, lkml , Martin KaFai Lau , Yonghong Song , John Fastabend , KP Singh , Masami Hiramatsu Subject: [PATCHv2 bpf 2/3] ftrace: Keep address offset in ftrace_lookup_symbols Date: Mon, 6 Jun 2022 20:47:30 +0200 Message-Id: <20220606184731.437300-3-jolsa@kernel.org> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220606184731.437300-1-jolsa@kernel.org> References: <20220606184731.437300-1-jolsa@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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. Acked-by: Song Liu Acked-by: Steven Rostedt (Google) 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..ee9260ee0b80 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 =3D data; + const char **sym; + int idx; =20 - if (!bsearch(&name, args->syms, args->cnt, sizeof(*args->syms), symbols_c= mp)) + sym =3D bsearch(&name, args->syms, args->cnt, sizeof(*args->syms), symbol= s_cmp); + if (!sym) + return 0; + + idx =3D sym - args->syms; + if (args->addrs[idx]) return 0; =20 addr =3D ftrace_location(addr); if (!addr) return 0; =20 - args->addrs[args->found++] =3D addr; + args->addrs[idx] =3D addr; + args->found++; return args->found =3D=3D args->cnt ? 1 : 0; } =20 @@ -8017,6 +8025,7 @@ int ftrace_lookup_symbols(const char **sorted_syms, s= ize_t cnt, unsigned long *a struct kallsyms_data args; int err; =20 + memset(addrs, 0, sizeof(*addrs) * cnt); args.addrs =3D addrs; args.syms =3D sorted_syms; args.cnt =3D cnt; --=20 2.35.3 From nobody Tue Apr 28 03:55:20 2026 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 ABF25C43334 for ; Mon, 6 Jun 2022 18:48:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231980AbiFFSsY (ORCPT ); Mon, 6 Jun 2022 14:48:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50546 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232096AbiFFSsR (ORCPT ); Mon, 6 Jun 2022 14:48:17 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1150B1B1F4A; Mon, 6 Jun 2022 11:48:15 -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 ams.source.kernel.org (Postfix) with ESMTPS id B2EF3B8196F; Mon, 6 Jun 2022 18:48:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0EC5EC385A9; Mon, 6 Jun 2022 18:48:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1654541292; bh=cJTxSqeBvt+JJkPbIdLUDtBvVOBvVbK0lR/sV13qNIs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GRKN/8AH9HNDrDxwWrnGuLA3SOqdtWudDbP5pTiolM3YGg4DZFP+oB6XQBMDegOll alpiOtbgQrwcW9RgSkK0SUvNDThYMP4qLH7su7odR9WyqYgPBVAULKkoEJ16BDNAoq p0YHAl6kVUiwlW5a2J/DO60Wc90cclm5Ty3YhKve5b/sp7/g8c4ied7RyDlZhWOCYr DVNsNN4ml773i/dmZcMun5Fw7lcv4kNoTln4mGhjStDRhtNcVOwXDpgQkdm9twzQO0 f5vL1kZspL9Vexioct4LMFOaoVqba0tQBdwMDMQHnJTiy1v23AWg3TmACai1I3p9uc Jg3PTIHNeapYQ== 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: [PATCHv2 bpf 3/3] bpf: Force cookies array to follow symbols sorting Date: Mon, 6 Jun 2022 20:47:31 +0200 Message-Id: <20220606184731.437300-4-jolsa@kernel.org> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220606184731.437300-1-jolsa@kernel.org> References: <20220606184731.437300-1-jolsa@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" When user specifies symbols and cookies for kprobe_multi link interface it's very likely the cookies will be misplaced and returned to wrong functions (via get_attach_cookie helper). The reason is that to resolve the provided functions we sort them before passing them to ftrace_lookup_symbols, but we do not do the same sort on the cookie values. Fixing this by using sort_r function with custom swap callback that swaps cookie values as well. Fixes: 0236fec57a15 ("bpf: Resolve symbols with ftrace_lookup_symbols for k= probe multi link") Signed-off-by: Jiri Olsa --- kernel/trace/bpf_trace.c | 60 ++++++++++++++++++++++++++++++---------- 1 file changed, 45 insertions(+), 15 deletions(-) diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c index 7a13e6ac6327..88589d74a892 100644 --- a/kernel/trace/bpf_trace.c +++ b/kernel/trace/bpf_trace.c @@ -2423,7 +2423,7 @@ kprobe_multi_link_handler(struct fprobe *fp, unsigned= long entry_ip, kprobe_multi_link_prog_run(link, entry_ip, regs); } =20 -static int symbols_cmp(const void *a, const void *b) +static int symbols_cmp_r(const void *a, const void *b, const void *priv) { const char **str_a =3D (const char **) a; const char **str_b =3D (const char **) b; @@ -2431,6 +2431,28 @@ static int symbols_cmp(const void *a, const void *b) return strcmp(*str_a, *str_b); } =20 +struct multi_symbols_sort { + const char **funcs; + u64 *cookies; +}; + +static void symbols_swap_r(void *a, void *b, int size, const void *priv) +{ + const struct multi_symbols_sort *data =3D priv; + const char **name_a =3D a, **name_b =3D b; + + swap(*name_a, *name_b); + + /* If defined, swap also related cookies. */ + if (data->cookies) { + u64 *cookie_a, *cookie_b; + + cookie_a =3D data->cookies + (name_a - data->funcs); + cookie_b =3D data->cookies + (name_b - data->funcs); + swap(*cookie_a, *cookie_b); + } +} + int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_pr= og *prog) { struct bpf_kprobe_multi_link *link =3D NULL; @@ -2468,38 +2490,46 @@ int bpf_kprobe_multi_link_attach(const union bpf_at= tr *attr, struct bpf_prog *pr if (!addrs) return -ENOMEM; =20 + ucookies =3D u64_to_user_ptr(attr->link_create.kprobe_multi.cookies); + if (ucookies) { + cookies =3D kvmalloc_array(cnt, sizeof(*addrs), GFP_KERNEL); + if (!cookies) { + err =3D -ENOMEM; + goto error; + } + if (copy_from_user(cookies, ucookies, size)) { + err =3D -EFAULT; + goto error; + } + } + if (uaddrs) { if (copy_from_user(addrs, uaddrs, size)) { err =3D -EFAULT; goto error; } } else { + struct multi_symbols_sort data =3D { + .cookies =3D cookies, + }; struct user_syms us; =20 err =3D copy_user_syms(&us, usyms, cnt); if (err) goto error; =20 - sort(us.syms, cnt, sizeof(*us.syms), symbols_cmp, NULL); + if (cookies) + data.funcs =3D us.syms; + + sort_r(us.syms, cnt, sizeof(*us.syms), symbols_cmp_r, + symbols_swap_r, &data); + err =3D ftrace_lookup_symbols(us.syms, cnt, addrs); free_user_syms(&us); if (err) goto error; } =20 - ucookies =3D u64_to_user_ptr(attr->link_create.kprobe_multi.cookies); - if (ucookies) { - cookies =3D kvmalloc_array(cnt, sizeof(*addrs), GFP_KERNEL); - if (!cookies) { - err =3D -ENOMEM; - goto error; - } - if (copy_from_user(cookies, ucookies, size)) { - err =3D -EFAULT; - goto error; - } - } - link =3D kzalloc(sizeof(*link), GFP_KERNEL); if (!link) { err =3D -ENOMEM; --=20 2.35.3