linux-security-module.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Song Liu <song@kernel.org>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: bpf <bpf@vger.kernel.org>,
	LSM List <linux-security-module@vger.kernel.org>,
	 Linux-Fsdevel <linux-fsdevel@vger.kernel.org>,
	fsverity@lists.linux.dev,  Eric Biggers <ebiggers@kernel.org>,
	Alexei Starovoitov <ast@kernel.org>,
	 Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>,
	 Martin KaFai Lau <martin.lau@linux.dev>,
	Christian Brauner <brauner@kernel.org>,
	 Alexander Viro <viro@zeniv.linux.org.uk>,
	Casey Schaufler <casey@schaufler-ca.com>,
	 Amir Goldstein <amir73il@gmail.com>,
	KP Singh <kpsingh@kernel.org>,
	 Roberto Sassu <roberto.sassu@huawei.com>
Subject: Re: [PATCH v13 bpf-next 5/6] selftests/bpf: Add tests for filesystem kfuncs
Date: Mon, 27 Nov 2023 09:16:32 -0800	[thread overview]
Message-ID: <CAPhsuW6GhuX_pprU-182vg6D1hRktd0sMoELCe0_uLNwSdhPqA@mail.gmail.com> (raw)
In-Reply-To: <CAADnVQKHTdGiBFh_sVr+jdsA8di8i4HHivp98QCOnHZGoHAW5Q@mail.gmail.com>

On Sun, Nov 26, 2023 at 6:09 PM Alexei Starovoitov
<alexei.starovoitov@gmail.com> wrote:
>
> On Thu, Nov 23, 2023 at 3:40 PM Song Liu <song@kernel.org> wrote:
> >
> > +static const char expected_value[] = "hello";
> > +char value[32];
> > +
> > +SEC("lsm.s/file_open")
> > +int BPF_PROG(test_file_open, struct file *f)
> > +{
> > +       struct bpf_dynptr value_ptr;
> > +       __u32 pid;
> > +       int ret;
> > +
> > +       pid = bpf_get_current_pid_tgid() >> 32;
> > +       if (pid != monitored_pid)
> > +               return 0;
> > +
> > +       bpf_dynptr_from_mem(value, sizeof(value), 0, &value_ptr);
> > +
> > +       ret = bpf_get_file_xattr(f, "user.kfuncs", &value_ptr);
> > +       if (ret != sizeof(expected_value))
> > +               return 0;
> > +       if (bpf_strncmp(value, ret, expected_value))
>
> Hmm. It doesn't work like:
> if (bpf_strncmp(value, ret, "hello"))

This also works. I used expected_value because there is a size
check above. We can also make do something like

if (ret != sizeof("hello"))
             return 0;
if (bpf_strncmp(value, ret, "hello"))
             return 0;

Both of the two work.

Thanks,
Song

  reply	other threads:[~2023-11-27 17:16 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-23 23:39 [PATCH v13 bpf-next 0/6] bpf: File verification with LSM and fsverity Song Liu
2023-11-23 23:39 ` [PATCH v13 bpf-next 1/6] bpf: Add kfunc bpf_get_file_xattr Song Liu
2023-11-24  2:53   ` Song Liu
2023-11-24  8:44   ` Christian Brauner
2023-11-24 17:07     ` Song Liu
2023-11-27 10:50       ` Christian Brauner
2023-11-27 18:05         ` Song Liu
2023-11-27 21:12           ` Song Liu
2023-11-28  9:13           ` Christian Brauner
2023-11-28 14:19             ` Song Liu
2023-11-28 15:10               ` Christian Brauner
2023-11-23 23:39 ` [PATCH v13 bpf-next 2/6] bpf, fsverity: Add kfunc bpf_get_fsverity_digest Song Liu
2023-11-23 23:39 ` [PATCH v13 bpf-next 3/6] Documentation/bpf: Add documentation for filesystem kfuncs Song Liu
2023-11-23 23:39 ` [PATCH v13 bpf-next 4/6] selftests/bpf: Sort config in alphabetic order Song Liu
2023-11-23 23:39 ` [PATCH v13 bpf-next 5/6] selftests/bpf: Add tests for filesystem kfuncs Song Liu
2023-11-27  2:08   ` Alexei Starovoitov
2023-11-27 17:16     ` Song Liu [this message]
2023-11-23 23:39 ` [PATCH v13 bpf-next 6/6] selftests/bpf: Add test that uses fsverity and xattr to sign a file Song Liu
2023-11-24 21:54   ` kernel test robot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAPhsuW6GhuX_pprU-182vg6D1hRktd0sMoELCe0_uLNwSdhPqA@mail.gmail.com \
    --to=song@kernel.org \
    --cc=alexei.starovoitov@gmail.com \
    --cc=amir73il@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=brauner@kernel.org \
    --cc=casey@schaufler-ca.com \
    --cc=daniel@iogearbox.net \
    --cc=ebiggers@kernel.org \
    --cc=fsverity@lists.linux.dev \
    --cc=kpsingh@kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=roberto.sassu@huawei.com \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).