bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrey Ignatov <rdna@fb.com>
To: Ilya Leoshkevich <iii@linux.ibm.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>,
	Alexei Starovoitov <ast@kernel.org>,
	"bpf@vger.kernel.org" <bpf@vger.kernel.org>,
	Heiko Carstens <heiko.carstens@de.ibm.com>,
	Vasily Gorbik <gor@linux.ibm.com>
Subject: Re: [PATCH bpf-next] selftests/bpf: test narrow load from bpf_sysctl.write
Date: Tue, 29 Oct 2019 15:24:23 +0000	[thread overview]
Message-ID: <20191029152422.GB84963@rdna-mbp> (raw)
In-Reply-To: <20191029143027.28681-1-iii@linux.ibm.com>

Ilya Leoshkevich <iii@linux.ibm.com> [Tue, 2019-10-29 07:31 -0700]:
> There are tests for full and narrows loads from bpf_sysctl.file_pos, but
> for bpf_sysctl.write only full load is tested. Add the missing test.
> 
> Suggested-by: Andrey Ignatov <rdna@fb.com>
> Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>

Thank you!

Acked-by: Andrey Ignatov <rdna@fb.com>

> ---
>  tools/testing/selftests/bpf/test_sysctl.c | 23 +++++++++++++++++++++++
>  1 file changed, 23 insertions(+)
> 
> diff --git a/tools/testing/selftests/bpf/test_sysctl.c b/tools/testing/selftests/bpf/test_sysctl.c
> index a320e3844b17..7aff907003d3 100644
> --- a/tools/testing/selftests/bpf/test_sysctl.c
> +++ b/tools/testing/selftests/bpf/test_sysctl.c
> @@ -120,6 +120,29 @@ static struct sysctl_test tests[] = {
>  		.newval = "(none)", /* same as default, should fail anyway */
>  		.result = OP_EPERM,
>  	},
> +	{
> +		.descr = "ctx:write sysctl:write read ok narrow",
> +		.insns = {
> +			/* u64 w = (u16)write & 1; */
> +#if __BYTE_ORDER == __LITTLE_ENDIAN
> +			BPF_LDX_MEM(BPF_H, BPF_REG_7, BPF_REG_1,
> +				    offsetof(struct bpf_sysctl, write)),
> +#else
> +			BPF_LDX_MEM(BPF_H, BPF_REG_7, BPF_REG_1,
> +				    offsetof(struct bpf_sysctl, write) + 2),
> +#endif
> +			BPF_ALU64_IMM(BPF_AND, BPF_REG_7, 1),
> +			/* return 1 - w; */
> +			BPF_MOV64_IMM(BPF_REG_0, 1),
> +			BPF_ALU64_REG(BPF_SUB, BPF_REG_0, BPF_REG_7),
> +			BPF_EXIT_INSN(),
> +		},
> +		.attach_type = BPF_CGROUP_SYSCTL,
> +		.sysctl = "kernel/domainname",
> +		.open_flags = O_WRONLY,
> +		.newval = "(none)", /* same as default, should fail anyway */
> +		.result = OP_EPERM,
> +	},
>  	{
>  		.descr = "ctx:write sysctl:read write reject",
>  		.insns = {
> -- 
> 2.23.0
> 

-- 
Andrey Ignatov

  reply	other threads:[~2019-10-29 15:24 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-29 14:30 [PATCH bpf-next] selftests/bpf: test narrow load from bpf_sysctl.write Ilya Leoshkevich
2019-10-29 15:24 ` Andrey Ignatov [this message]
2019-10-30 15:54 ` Daniel Borkmann

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=20191029152422.GB84963@rdna-mbp \
    --to=rdna@fb.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=gor@linux.ibm.com \
    --cc=heiko.carstens@de.ibm.com \
    --cc=iii@linux.ibm.com \
    /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).