bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: KP Singh <kpsingh@kernel.org>
To: Yonghong Song <yhs@fb.com>
Cc: bpf <bpf@vger.kernel.org>, Gilad Reti <gilad.reti@gmail.com>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>,
	Martin KaFai Lau <kafai@fb.com>
Subject: Re: [PATCH bpf v2 1/3] bpf: update local storage test to check handling of null ptrs
Date: Tue, 12 Jan 2021 08:35:39 +0100	[thread overview]
Message-ID: <CACYkzJ4+H1XLF4DW7+0K+zFCFtzkdZQQAzk_UWsj5Bs9HaTa=Q@mail.gmail.com> (raw)
In-Reply-To: <317e2cb6-3774-b343-d93b-5b6f1d41b97e@fb.com>

On Tue, Jan 12, 2021 at 8:25 AM Yonghong Song <yhs@fb.com> wrote:
>
>
>
> On 1/11/21 1:23 PM, KP Singh wrote:
> > It was found in [1] that bpf_inode_storage_get helper did not check
> > the nullness of the passed owner ptr which caused an oops when
> > dereferenced. This change incorporates the example suggested in [1] into
> > the local storage selftest.
> >
> > The test is updated to create a temporary directory instead of just
> > using a tempfile. In order to replicate the issue this copied rm binary
> > is renamed tiggering the inode_rename with a null pointer for the
> > new_inode. The logic to verify the setting and deletion of the inode
> > local storage of the old inode is also moved to this LSM hook.
> >
> > The change also removes the copy_rm function and simply shells out
> > to copy files and recursively delete directories and consolidates the
> > logic of setting the initial inode storage to the bprm_committed_creds
> > hook and removes the file_open hook.
> >
> > [1]: https://lore.kernel.org/bpf/CANaYP3HWkH91SN=wTNO9FL_2ztHfqcXKX38SSE-JJ2voh+vssw@mail.gmail.com
> >
> > Suggested-by: Gilad Reti <gilad.reti@gmail.com>
> > Signed-off-by: KP Singh <kpsingh@kernel.org>
>
> Ack with one nit below.
>
> Acked-by: Yonghong Song <yhs@fb.com>
>
> > ---

[...]

> > @@ -189,18 +136,24 @@ void test_test_local_storage(void)
> >                                     task_fd))
> >               goto close_prog;
> >
> > -     err = copy_rm(tmp_exec_path);
> > -     if (CHECK(err < 0, "copy_rm", "err %d errno %d\n", err, errno))
> > +     mkdtemp(tmp_dir_path);
> > +     if (CHECK(errno < 0, "mkdtemp", "unable to create tmpdir: %d\n", errno))
>
> I think checking mkdtemp return value is more reliable than checking
> errno. It is possible mkdtemp returns 0 and errno is not 0 (inheritted
> from previous syscall).

You are right, I will send in a v3 with this fixed and also add your Acks.
Thanks!

>
> >               goto close_prog;
> >
> > +     snprintf(tmp_exec_path, sizeof(tmp_exec_path), "%s/copy_of_rm",
> > +              tmp_dir_path);
> > +     snprintf(cmd, sizeof(cmd), "cp /bin/rm %s", tmp_exec_path);
> > +     if (CHECK_FAIL(system(cmd)))
> > +             goto close_prog_rmdir;
> > +
> [...]

  reply	other threads:[~2021-01-12  7:36 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-11 21:23 [PATCH bpf v2 0/3] Fix local storage helper OOPs KP Singh
2021-01-11 21:23 ` [PATCH bpf v2 1/3] bpf: update local storage test to check handling of null ptrs KP Singh
2021-01-12  7:24   ` Yonghong Song
2021-01-12  7:35     ` KP Singh [this message]
2021-01-11 21:23 ` [PATCH bpf v2 2/3] bpf: local storage helpers should check nullness of owner ptr passed KP Singh
2021-01-12  7:25   ` Yonghong Song
2021-01-11 21:23 ` [PATCH bpf v2 3/3] bpf: Fix typo in bpf_inode_storage.c KP Singh
2021-01-12  7:26   ` Yonghong Song

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='CACYkzJ4+H1XLF4DW7+0K+zFCFtzkdZQQAzk_UWsj5Bs9HaTa=Q@mail.gmail.com' \
    --to=kpsingh@kernel.org \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=gilad.reti@gmail.com \
    --cc=kafai@fb.com \
    --cc=yhs@fb.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).