From mboxrd@z Thu Jan 1 00:00:00 1970 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 93515C021B3 for ; Fri, 21 Feb 2025 18:27:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1173F280022; Fri, 21 Feb 2025 13:27:07 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0A1A7280021; Fri, 21 Feb 2025 13:27:07 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E36D0280022; Fri, 21 Feb 2025 13:27:06 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id BD9BB280021 for ; Fri, 21 Feb 2025 13:27:06 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 7AA56B234E for ; Fri, 21 Feb 2025 18:27:06 +0000 (UTC) X-FDA: 83144783652.13.59F6818 Received: from mail-pj1-f47.google.com (mail-pj1-f47.google.com [209.85.216.47]) by imf25.hostedemail.com (Postfix) with ESMTP id 860F4A0009 for ; Fri, 21 Feb 2025 18:27:04 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=kBGh5kal; spf=pass (imf25.hostedemail.com: domain of andrii.nakryiko@gmail.com designates 209.85.216.47 as permitted sender) smtp.mailfrom=andrii.nakryiko@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1740162424; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=2Eu5biRJR0BUSiaN/w9KxdjNHWyMVIS8FF0rxdSpGMA=; b=dlhQW3x7cz0eBqjsqyU4rq1JpbggmZ/0mAFEwcuM0hD2ZdyN4iJZJD1K3QkywClw/K2q0D MOLEkSJ+Xct1ZwHTWfM9OnAmnpeKKCU28bOHgf4nW52Dn3FbbQE98WOSQD2CqIxi2c0hwe wyiIMNeOfZ1ev62cwKeLdN+mFJwWIyU= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=kBGh5kal; spf=pass (imf25.hostedemail.com: domain of andrii.nakryiko@gmail.com designates 209.85.216.47 as permitted sender) smtp.mailfrom=andrii.nakryiko@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1740162424; a=rsa-sha256; cv=none; b=FX5BEPfzORhHymco5UTkKGJGaE9AxK3uEPXaYNwNx/JWYg+pmHnbptapblivjvcZ0yM0h6 voMcpLTml5PgqMqddZKY2qpUBqP8CSGfA0B2hIU3shk3prNuPhRmZY9sw62bUAz4wGf6Sv FkpzPWtV/hB3fGX5kP3CQMGTdGGnxII= Received: by mail-pj1-f47.google.com with SMTP id 98e67ed59e1d1-2fbf77b2b64so4951080a91.2 for ; Fri, 21 Feb 2025 10:27:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1740162423; x=1740767223; darn=kvack.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=2Eu5biRJR0BUSiaN/w9KxdjNHWyMVIS8FF0rxdSpGMA=; b=kBGh5kalwNM/hTKKdLcoo/67h8Tlhk5qBelB+UE7rTtNmhfh92O+e36ZNG2mWu4B+l AuIHQAFXJN9DsZmpaW7HgDAyOcO7EMBW/n9WjnQzjJGl5qQqmOQfBnc7g1Hq7PqulXXw kJzu8NaSqDV5ZXUqHICzMo3icR5FqBKNTYzKW3k5mrIBsU1oR/BWp3zAW4tFiVH9mukD 46NiLLLoYZWBErvJycdb0Vz2NS6trV4KMZTce2ilrezUpS767ujUgMkHlO/z6J4aikJu jNIEBuMEzckkGE5yiGBlYi+F6xi0A6yP1s6DYC/YfW3oB+dozSSNopLR9mYnnDw6/uav 1U7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740162423; x=1740767223; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2Eu5biRJR0BUSiaN/w9KxdjNHWyMVIS8FF0rxdSpGMA=; b=tj4+/zq8hbmidUD4Qi3akAYfHTLWziq72zgwPwAeRnwMoSh8FDemwLjrp2d4+F3ntG wSzu1Dly/al7KojM8qRcCnYs/LtYywXCpO/3jJfaeCkQxrVmWFadGlfvnfXsO9dsY1HQ w0P6CJzBMUbV8FFJDZS9FmEaluSQuiQpbbAQN9LGENN0QdC+p2lBChFqmMe4qbvuCXrB RML6FC758IZfQ8EWBgp8IU+7TT291ePQdMXrv0Cf2i6ygY1uXwFBAw/DSgC4fjBtfRNn DT7oGDVMnTjrR84mAwjcehpHGbxnM+yxPj9uGElxYOfzC3wpqmDed4LZBnpuwQizU3ch 77vg== X-Forwarded-Encrypted: i=1; AJvYcCWPgWQYrGWZwlW66etUsGaUBqaFKMkz2oSRF6KBdB4Cj0Ni4l6ODb0UJ9wDfPo30kx4/e25N1jX8A==@kvack.org X-Gm-Message-State: AOJu0Yyek6PoeQWbOMqfO1CHc92wdd2YmgVWYd3RYbS37rmUEGvtOk8g fSQJQT8rF6ZMuFpodxI4bfDzQDzQvXZ7PN+EAKanxE1AZXng3GwmA243Z1kNJ3SqiJZ3AQqdziA gvuna4tW4vxXiTGyMNmK8mKaPtdc= X-Gm-Gg: ASbGncthMVE58Msgyd6JQ3hZTyvNlMQJK6VxNnA4Lih/dW/5OZcxST/1+aLjIocuq2Y jft9Egh5VK2UFZ4n+dO+h34rPSozBjs5MmwttGX0zmnHnZe8sI7GRtbw7gzENDsH1i2r9wm0BTB Q3ZLM/oA== X-Google-Smtp-Source: AGHT+IEAd4mHa1pi52o3TepVtLEXnmXHvzYVIVVKAwI1S1DEpPKIRcIGu7S/Gjpx9FWENRxkzKo+1jbWzHeoVPyG+0E= X-Received: by 2002:a17:90b:4b01:b0:2ee:45fd:34f2 with SMTP id 98e67ed59e1d1-2fce77a01b4mr6407242a91.6.1740162421754; Fri, 21 Feb 2025 10:27:01 -0800 (PST) MIME-Version: 1.0 References: <20250213152125.1837400-1-linux@jordanrome.com> <20250213152125.1837400-3-linux@jordanrome.com> <386d3514-1822-45a2-a2c5-1567a0d599a5@hetzner-cloud.de> In-Reply-To: <386d3514-1822-45a2-a2c5-1567a0d599a5@hetzner-cloud.de> From: Andrii Nakryiko Date: Fri, 21 Feb 2025 10:26:48 -0800 X-Gm-Features: AWEUYZlGFBwkHU-DR7eROtUFykQhDaWOD5EhsO_wokFRHicQsSKin9GSzYrAUN8 Message-ID: Subject: Re: [bpf-next v8 3/3] selftests/bpf: Add tests for bpf_copy_from_user_task_str To: Marcus Wichelmann Cc: Jordan Rome , bpf@vger.kernel.org, linux-mm@kvack.org, Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Kernel Team , Andrew Morton , Shakeel Butt , Alexander Potapenko Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspam-User: X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: 860F4A0009 X-Stat-Signature: hfrtnqy9ezg49t1njdcujcxg6uwkr93w X-HE-Tag: 1740162424-326375 X-HE-Meta: U2FsdGVkX1/SKgbpzI0yClv2Wl0RQXHE99hN2Hmk7gGhcBNZam5ECJJP0dcPhF1unoE+PTQE8zNNsOxs3fjPQDNTVq5AMKSpm+HbUGI1wNfDy4Y77oDIJ8mur9ZMjkc74Y97ZhbqPS+hubpgDr9U3HNvBffffaGPPC89iz3+/gCsvWjiQoIp1LChVEM+L35YoTW+jlPSkXfwxyPXCs+sbn9ItRwX2TT9hZqycZBbVTrJeV4dhgMgUjfrojCoLxJxzbMZWKy0egMl8FVjDEOgD3RRj3EpE3dR/vYifRq+3OjGKWQeF1wjuV91pVitK3pFmB231+Ak5A3F4LUQi6+Y1y6waWi+VJgZKuHnEhi8OpIpHyEOCG1RXT40z5uO/3hKELjQWHtzBlIdgYs4W+KBmJRVZrtMdoYvl40Iksa4BA1gz4REFJLwU51P6iPCgJr4ZlPMqIsjQvRF6z6CSPBM1QX97BTL19XbKJ/AGAZdNe1MwNECR7H5Dtnuj265fQlKHE1vXCfu6RWgqC46REl70f2uXkr356E/tVvlMxBYiNHtvSrdGytjM0ZKK8mVJdmntcSldCQXux7zpxEXz4y1Zcquj/wglE8+ftHvd30Ew4x3PG5XP5x9kBDJ3il/tAPo6srwxFvuYYFkNIBNO70k3k6XhnPipHIhtwtyes1d0QouQ6SvpWoYDhQFe6lU56zxMSO7JrSeF82H0Z99F3N/J/zXJYp9tcl7n3xtlyG9SNNlBarR9amJk9GQ6ggPG8lzw2/7Xyb4ccRMtUfe38allSzi5CdwoUrfivk/HP70a/lgk82TAkLYZ2w8u/skcGyVYbK+UYNDkRsa/M+r+0GfAgK7THwWI92KFTz+IWmoRTYEctb9BsQCi3HjK0mL6v+ZkwEZDEGdqrHl2eWVp/2Y0oMLOm4BHST84S6DwZBS43NpNXFvU/P4hYPV8g8rxmFkpVZsMiC0qVmqX7ULJPB 2Djt9/cN eHwoiImB9e6l0dY2PJV1/8GfEQODWSskVozXMywfD2yw29Z8SAPs9vYtQFHzz5WgUmLT3PQPotNvXhT3Lurfan2p1yRoBqj23OAT9yVB5C8q7Eglaafy9PT7+6QX1hPB3VuUqzSnl9wo5V84R9VHhautjeSmfO56vooeIiy88TU/hYNPxsZxRnLt2OobNO3pdjWQF88WXAg7vw5uyePL9TcmpxfNgyFYzf/+qij4IctEpeEU5mZDWK3UzhBtwhsrjFhno0siEyI7edOIs03OtsiUfD5vp91/1LcMvJ2gipC4fRa54hhzxZsK05MQJT4VB5LP+v5I0D79NXFlik3s121jt6I8zc4bqXDiDbYjK3MFNYZRvue6wagJijGNczlC9T/aYDK0vtpUfBCbPDv466J13duR9V59IwMIII+b8jo+ixuwToxhByocrA4IEtV2ag18ZrWpmLSJVSx1ivZPFtxsOfWiwcZExiGANaV03XSPXXbSXPLwUdwCdGNcH6vQRdTfxOW30qJS7g0w= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Fri, Feb 21, 2025 at 7:01=E2=80=AFAM Marcus Wichelmann wrote: > > Hi, > > I'm not sure what I'm doing wrong, but after rebasing on latest bpf-next > which includes this patch, I'm no longer able to build the bpf selftests: > > # pushd tools/testing/selftests/bpf/ > # make -j80 > [...] > GEN-SKEL [test_progs] bpf_iter_task_vmas.skel.h > CLNG-BPF [test_progs] bpf_iter_tasks.bpf.o > progs/bpf_iter_tasks.c:98:8: error: call to undeclared function 'bpf_copy= _from_user_task_str'; ISO C99 and later do not support implicit function de= clarations [-Wimplicit-function-declaration] > 98 | ret =3D bpf_copy_from_user_task_str((char *)task_str1, s= izeof(task_str1), ptr, task, 0); > | ^ > 1 error generated. > make: *** [Makefile:733: /root/linux/tools/testing/selftests/bpf/bpf_iter= _tasks.bpf.o] Error 1 > > I suppose the function definition should be in the vmlinux.h? > Yes, it should be in vmlinux.h, and if you don't have it, then you must have a bit too old pahole. $ git tag --contains ce4d0bc0200e3 v1.27 v1.28 > # grep bpf_copy tools/include/vmlinux.h > typedef u64 (*btf_bpf_copy_from_user)(void *, u32, const void *); > typedef u64 (*btf_bpf_copy_from_user_task)(void *, u32, const void *, str= uct task_struct *, u64); > > The kernel built from this revision is booted while trying to compile > the selftests. I can also see that the kfunc is there when dumping withou= t "format c": > > # bpftool btf dump file /sys/kernel/btf/vmlinux | grep bpf_copy_from_user= _task_str > [116060] FUNC 'bpf_copy_from_user_task_str' type_id=3D116059 linkage=3Dst= atic > > But when dumping the vmlinux headers with "format c", I cannot see the kf= unc. > I'm not sure if this is normal: > > # bpftool btf dump file /sys/kernel/btf/vmlinux format c | grep bpf_copy_= from_user_task_str > # > > CONFIG_BPF SYSCALL is enabled. Are there other config options that > have to be enabled that I may be missing? > > I'm trying this on a aarch64 system. I also tried to fully clean > my working tree using `git clean -d -x -f`, which didn't help > either. > > Thanks! > Marcus > > > Am 13.02.25 um 16:21 schrieb Jordan Rome: > > This adds tests for both the happy path and the > > error path (with and without the BPF_F_PAD_ZEROS flag). > > > > Signed-off-by: Jordan Rome > > --- > > .../selftests/bpf/prog_tests/bpf_iter.c | 68 +++++++++++ > > .../selftests/bpf/prog_tests/read_vsyscall.c | 1 + > > .../selftests/bpf/progs/bpf_iter_tasks.c | 110 +++++++++++++++++= + > > .../selftests/bpf/progs/read_vsyscall.c | 11 +- > > 4 files changed, 188 insertions(+), 2 deletions(-) > > > > diff --git a/tools/testing/selftests/bpf/prog_tests/bpf_iter.c b/tools/= testing/selftests/bpf/prog_tests/bpf_iter.c > > index 6f1bfacd7375..add4a18c33bd 100644 > > --- a/tools/testing/selftests/bpf/prog_tests/bpf_iter.c > > +++ b/tools/testing/selftests/bpf/prog_tests/bpf_iter.c > > @@ -323,19 +323,87 @@ static void test_task_pidfd(void) > > static void test_task_sleepable(void) > > { > > struct bpf_iter_tasks *skel; > > + int pid, status, err, data_pipe[2], finish_pipe[2], c; > > + char *test_data =3D NULL; > > + char *test_data_long =3D NULL; > > + char *data[2]; > > + > > + if (!ASSERT_OK(pipe(data_pipe), "data_pipe") || > > + !ASSERT_OK(pipe(finish_pipe), "finish_pipe")) > > + return; > > > > skel =3D bpf_iter_tasks__open_and_load(); > > if (!ASSERT_OK_PTR(skel, "bpf_iter_tasks__open_and_load")) > > return; > > > > + pid =3D fork(); > > + if (!ASSERT_GE(pid, 0, "fork")) > > + return; > > + > > + if (pid =3D=3D 0) { > > + /* child */ > > + close(data_pipe[0]); > > + close(finish_pipe[1]); > > + > > + test_data =3D malloc(sizeof(char) * 10); > > + strncpy(test_data, "test_data", 10); > > + test_data[9] =3D '\0'; > > + > > + test_data_long =3D malloc(sizeof(char) * 5000); > > + for (int i =3D 0; i < 5000; ++i) { > > + if (i % 2 =3D=3D 0) > > + test_data_long[i] =3D 'b'; > > + else > > + test_data_long[i] =3D 'a'; > > + } > > + test_data_long[4999] =3D '\0'; > > + > > + data[0] =3D test_data; > > + data[1] =3D test_data_long; > > + > > + write(data_pipe[1], &data, sizeof(data)); > > + > > + /* keep child alive until after the test */ > > + err =3D read(finish_pipe[0], &c, 1); > > + if (err !=3D 1) > > + exit(-1); > > + > > + close(data_pipe[1]); > > + close(finish_pipe[0]); > > + _exit(0); > > + } > > + > > + /* parent */ > > + close(data_pipe[1]); > > + close(finish_pipe[0]); > > + > > + err =3D read(data_pipe[0], &data, sizeof(data)); > > + ASSERT_EQ(err, sizeof(data), "read_check"); > > + > > + skel->bss->user_ptr =3D data[0]; > > + skel->bss->user_ptr_long =3D data[1]; > > + skel->bss->pid =3D pid; > > + > > do_dummy_read(skel->progs.dump_task_sleepable); > > > > ASSERT_GT(skel->bss->num_expected_failure_copy_from_user_task, 0, > > "num_expected_failure_copy_from_user_task"); > > ASSERT_GT(skel->bss->num_success_copy_from_user_task, 0, > > "num_success_copy_from_user_task"); > > + ASSERT_GT(skel->bss->num_expected_failure_copy_from_user_task_str= , 0, > > + "num_expected_failure_copy_from_user_task_str"); > > + ASSERT_GT(skel->bss->num_success_copy_from_user_task_str, 0, > > + "num_success_copy_from_user_task_str"); > > > > bpf_iter_tasks__destroy(skel); > > + > > + write(finish_pipe[1], &c, 1); > > + err =3D waitpid(pid, &status, 0); > > + ASSERT_EQ(err, pid, "waitpid"); > > + ASSERT_EQ(status, 0, "zero_child_exit"); > > + > > + close(data_pipe[0]); > > + close(finish_pipe[1]); > > } > > > > static void test_task_stack(void) > > diff --git a/tools/testing/selftests/bpf/prog_tests/read_vsyscall.c b/t= ools/testing/selftests/bpf/prog_tests/read_vsyscall.c > > index c7b9ba8b1d06..a8d1eaa67020 100644 > > --- a/tools/testing/selftests/bpf/prog_tests/read_vsyscall.c > > +++ b/tools/testing/selftests/bpf/prog_tests/read_vsyscall.c > > @@ -24,6 +24,7 @@ struct read_ret_desc { > > { .name =3D "copy_from_user", .ret =3D -EFAULT }, > > { .name =3D "copy_from_user_task", .ret =3D -EFAULT }, > > { .name =3D "copy_from_user_str", .ret =3D -EFAULT }, > > + { .name =3D "copy_from_user_task_str", .ret =3D -EFAULT }, > > }; > > > > void test_read_vsyscall(void) > > diff --git a/tools/testing/selftests/bpf/progs/bpf_iter_tasks.c b/tools= /testing/selftests/bpf/progs/bpf_iter_tasks.c > > index bc10c4e4b4fa..966ee5a7b066 100644 > > --- a/tools/testing/selftests/bpf/progs/bpf_iter_tasks.c > > +++ b/tools/testing/selftests/bpf/progs/bpf_iter_tasks.c > > @@ -9,6 +9,13 @@ char _license[] SEC("license") =3D "GPL"; > > uint32_t tid =3D 0; > > int num_unknown_tid =3D 0; > > int num_known_tid =3D 0; > > +void *user_ptr =3D 0; > > +void *user_ptr_long =3D 0; > > +uint32_t pid =3D 0; > > + > > +static char big_str1[5000]; > > +static char big_str2[5005]; > > +static char big_str3[4996]; > > > > SEC("iter/task") > > int dump_task(struct bpf_iter__task *ctx) > > @@ -35,7 +42,9 @@ int dump_task(struct bpf_iter__task *ctx) > > } > > > > int num_expected_failure_copy_from_user_task =3D 0; > > +int num_expected_failure_copy_from_user_task_str =3D 0; > > int num_success_copy_from_user_task =3D 0; > > +int num_success_copy_from_user_task_str =3D 0; > > > > SEC("iter.s/task") > > int dump_task_sleepable(struct bpf_iter__task *ctx) > > @@ -44,6 +53,9 @@ int dump_task_sleepable(struct bpf_iter__task *ctx) > > struct task_struct *task =3D ctx->task; > > static const char info[] =3D " =3D=3D=3D END =3D=3D=3D"; > > struct pt_regs *regs; > > + char task_str1[10] =3D "aaaaaaaaaa"; > > + char task_str2[10], task_str3[10]; > > + char task_str4[20] =3D "aaaaaaaaaaaaaaaaaaaa"; > > void *ptr; > > uint32_t user_data =3D 0; > > int ret; > > @@ -78,8 +90,106 @@ int dump_task_sleepable(struct bpf_iter__task *ctx) > > BPF_SEQ_PRINTF(seq, "%s\n", info); > > return 0; > > } > > + > > ++num_success_copy_from_user_task; > > > > + /* Read an invalid pointer and ensure we get an error */ > > + ptr =3D NULL; > > + ret =3D bpf_copy_from_user_task_str((char *)task_str1, sizeof(tas= k_str1), ptr, task, 0); > > + if (ret >=3D 0 || task_str1[9] !=3D 'a' || task_str1[0] !=3D '\0'= ) { > > + BPF_SEQ_PRINTF(seq, "%s\n", info); > > + return 0; > > + } > > + > > + /* Read an invalid pointer and ensure we get error with pad zeros= flag */ > > + ptr =3D NULL; > > + ret =3D bpf_copy_from_user_task_str((char *)task_str1, sizeof(tas= k_str1), > > + ptr, task, BPF_F_PAD_ZEROS); > > + if (ret >=3D 0 || task_str1[9] !=3D '\0' || task_str1[0] !=3D '\0= ') { > > + BPF_SEQ_PRINTF(seq, "%s\n", info); > > + return 0; > > + } > > + > > + ++num_expected_failure_copy_from_user_task_str; > > + > > + /* Same length as the string */ > > + ret =3D bpf_copy_from_user_task_str((char *)task_str2, 10, user_p= tr, task, 0); > > + /* only need to do the task pid check once */ > > + if (bpf_strncmp(task_str2, 10, "test_data\0") !=3D 0 || ret !=3D = 10 || task->tgid !=3D pid) { > > + BPF_SEQ_PRINTF(seq, "%s\n", info); > > + return 0; > > + } > > + > > + /* Shorter length than the string */ > > + ret =3D bpf_copy_from_user_task_str((char *)task_str3, 2, user_pt= r, task, 0); > > + if (bpf_strncmp(task_str3, 2, "t\0") !=3D 0 || ret !=3D 2) { > > + BPF_SEQ_PRINTF(seq, "%s\n", info); > > + return 0; > > + } > > + > > + /* Longer length than the string */ > > + ret =3D bpf_copy_from_user_task_str((char *)task_str4, 20, user_p= tr, task, 0); > > + if (bpf_strncmp(task_str4, 10, "test_data\0") !=3D 0 || ret !=3D = 10 > > + || task_str4[sizeof(task_str4) - 1] !=3D 'a') { > > + BPF_SEQ_PRINTF(seq, "%s\n", info); > > + return 0; > > + } > > + > > + /* Longer length than the string with pad zeros flag */ > > + ret =3D bpf_copy_from_user_task_str((char *)task_str4, 20, user_p= tr, task, BPF_F_PAD_ZEROS); > > + if (bpf_strncmp(task_str4, 10, "test_data\0") !=3D 0 || ret !=3D = 10 > > + || task_str4[sizeof(task_str4) - 1] !=3D '\0') { > > + BPF_SEQ_PRINTF(seq, "%s\n", info); > > + return 0; > > + } > > + > > + /* Longer length than the string past a page boundary */ > > + ret =3D bpf_copy_from_user_task_str(big_str1, 5000, user_ptr, tas= k, 0); > > + if (bpf_strncmp(big_str1, 10, "test_data\0") !=3D 0 || ret !=3D 1= 0) { > > + BPF_SEQ_PRINTF(seq, "%s\n", info); > > + return 0; > > + } > > + > > + /* String that crosses a page boundary */ > > + ret =3D bpf_copy_from_user_task_str(big_str1, 5000, user_ptr_long= , task, BPF_F_PAD_ZEROS); > > + if (bpf_strncmp(big_str1, 4, "baba") !=3D 0 || ret !=3D 5000 > > + || bpf_strncmp(big_str1 + 4996, 4, "bab\0") !=3D 0) { > > + BPF_SEQ_PRINTF(seq, "%s\n", info); > > + return 0; > > + } > > + > > + for (int i =3D 0; i < 4999; ++i) { > > + if (i % 2 =3D=3D 0) { > > + if (big_str1[i] !=3D 'b') { > > + BPF_SEQ_PRINTF(seq, "%s\n", info); > > + return 0; > > + } > > + } else { > > + if (big_str1[i] !=3D 'a') { > > + BPF_SEQ_PRINTF(seq, "%s\n", info); > > + return 0; > > + } > > + } > > + } > > + > > + /* Longer length than the string that crosses a page boundary */ > > + ret =3D bpf_copy_from_user_task_str(big_str2, 5005, user_ptr_long= , task, BPF_F_PAD_ZEROS); > > + if (bpf_strncmp(big_str2, 4, "baba") !=3D 0 || ret !=3D 5000 > > + || bpf_strncmp(big_str2 + 4996, 5, "bab\0\0") !=3D 0) { > > + BPF_SEQ_PRINTF(seq, "%s\n", info); > > + return 0; > > + } > > + > > + /* Shorter length than the string that crosses a page boundary */ > > + ret =3D bpf_copy_from_user_task_str(big_str3, 4996, user_ptr_long= , task, 0); > > + if (bpf_strncmp(big_str3, 4, "baba") !=3D 0 || ret !=3D 4996 > > + || bpf_strncmp(big_str3 + 4992, 4, "bab\0") !=3D 0) { > > + BPF_SEQ_PRINTF(seq, "%s\n", info); > > + return 0; > > + } > > + > > + ++num_success_copy_from_user_task_str; > > + > > if (ctx->meta->seq_num =3D=3D 0) > > BPF_SEQ_PRINTF(seq, " tgid gid data\n"); > > > > diff --git a/tools/testing/selftests/bpf/progs/read_vsyscall.c b/tools/= testing/selftests/bpf/progs/read_vsyscall.c > > index 39ebef430059..395591374d4f 100644 > > --- a/tools/testing/selftests/bpf/progs/read_vsyscall.c > > +++ b/tools/testing/selftests/bpf/progs/read_vsyscall.c > > @@ -8,14 +8,16 @@ > > > > int target_pid =3D 0; > > void *user_ptr =3D 0; > > -int read_ret[9]; > > +int read_ret[10]; > > > > char _license[] SEC("license") =3D "GPL"; > > > > /* > > - * This is the only kfunc, the others are helpers > > + * These are the kfuncs, the others are helpers > > */ > > int bpf_copy_from_user_str(void *dst, u32, const void *, u64) __weak = __ksym; > > +int bpf_copy_from_user_task_str(void *dst, u32, const void *, > > + struct task_struct *, u64) __weak __ksym; > > > > SEC("fentry/" SYS_PREFIX "sys_nanosleep") > > int do_probe_read(void *ctx) > > @@ -47,6 +49,11 @@ int do_copy_from_user(void *ctx) > > read_ret[7] =3D bpf_copy_from_user_task(buf, sizeof(buf), user_pt= r, > > bpf_get_current_task_btf(),= 0); > > read_ret[8] =3D bpf_copy_from_user_str((char *)buf, sizeof(buf), = user_ptr, 0); > > + read_ret[9] =3D bpf_copy_from_user_task_str((char *)buf, > > + sizeof(buf), > > + user_ptr, > > + bpf_get_current_task_bt= f(), > > + 0); > > > > return 0; > > } > > -- > > 2.43.5 > > > > > > -- > Best regards, > Marcus Wichelmann > Linux Networking Specialist > Team SDN > > ______________________________ > > Hetzner Cloud GmbH > Feringastra=C3=9Fe 12A > 85774 Unterf=C3=B6hring > Germany > > Phone: +49 89 381690 150 > E-Mail: marcus.wichelmann@hetzner-cloud.de > > Handelsregister M=C3=BCnchen HRB 226782 > Gesch=C3=A4ftsf=C3=BChrer: Sebastian F=C3=A4rber, Markus Kalmuk > > ------------------ > For information on the processing of your personal > data in the context of this contact, please see > https://hetzner-cloud.de/datenschutz > ------------------ >