From: Kees Cook <kees@kernel.org>
To: Mark Rutland <mark.rutland@arm.com>
Cc: Vitor Massaru Iha <vitor@massaru.org>,
Brendan Higgins <brendan.higgins@linux.dev>,
David Gow <davidgow@google.com>, Rae Moar <rmoar@google.com>,
"Gustavo A. R. Silva" <gustavoars@kernel.org>,
linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org,
kunit-dev@googlegroups.com, linux-hardening@vger.kernel.org
Subject: Re: [PATCH 1/2] kunit: test: Add vm_mmap() allocation resource manager
Date: Mon, 10 Jun 2024 12:05:54 -0700 [thread overview]
Message-ID: <202406101202.3D887825@keescook> (raw)
In-Reply-To: <ZksX4r0a1EGE_VPl@J2N7QTR9R3>
On Mon, May 20, 2024 at 10:29:06AM +0100, Mark Rutland wrote:
> On Sun, May 19, 2024 at 12:12:52PM -0700, Kees Cook wrote:
> > +/* Create and attach a new mm if it doesn't already exist. */
> > +static int kunit_attach_mm(void)
> > +{
> > + struct vm_area_struct *vma;
> > + struct mm_struct *mm;
> > +
> > + if (current->mm)
> > + return 0;
>
> My tests deliberately created/destroyed the mm for each test; surely we
> don't want to inherit an MM in some arbitrary state? ... or is this just
> so the mm can be allocated lazily upon the first mmap() within a test?
It's for lazily creation and for supporting running the KUnit test as a
module (where a userspace would exist). The old usercopy test worked
against the existing userspace, so I'd want to continue to support that.
>
> > +
> > + mm = mm_alloc();
> > + if (!mm)
> > + return -ENOMEM;
> > +
> > + if (mmap_write_lock_killable(mm))
> > + goto out_free;
> > +
> > + /* Define the task size. */
> > + mm->task_size = TASK_SIZE;
> > +
> > + /* Prepare the base VMA. */
> > + vma = vm_area_alloc(mm);
> > + if (!vma)
> > + goto out_unlock;
> > +
> > + vma_set_anonymous(vma);
> > + vma->vm_start = UBUF_ADDR_BASE;
> > + vma->vm_end = UBUF_ADDR_BASE + PAGE_SIZE;
> > + vm_flags_init(vma, VM_READ | VM_MAYREAD | VM_WRITE | VM_MAYWRITE);
> > + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
> > +
> > + if (insert_vm_struct(mm, vma))
> > + goto out_free_vma;
> > +
> > + mmap_write_unlock(mm);
>
> Why do we need this VMA given you have kunit_vm_mmap()?
When I was originally testing this, it seemed like I couldn't perform a
vm_mmap() without an existing VMA.
> This existed in my uaccess tests because I didn't use vm_mmap(), and I
> wanted complete control over the addresses used.
>
> Given you add kunit_vm_mmap(), I don't think we want this VMA -- it
> doesn't serve any real purpose to tests, and accesses can erroneously
> hit it, which is problematic.
>
> UBUF_ADDR_BASE shouldn't be necessary either with kunit_vm_mmap(),
> unless you want to use fixed addresses. That was just arbitrarily chosen
> to be above NULL and the usual minimum mmap limit.
I'll recheck whether this is needed. I think I had to make some other
changes as well, so maybe something here ended up being redundant
without my noticing it the first time.
Thanks for looking this over!
--
Kees Cook
next prev parent reply other threads:[~2024-06-10 19:05 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-19 19:12 [PATCH 0/2] usercopy: Convert test_user_copy to KUnit test Kees Cook
2024-05-19 19:12 ` [PATCH 1/2] kunit: test: Add vm_mmap() allocation resource manager Kees Cook
2024-05-20 9:29 ` Mark Rutland
2024-06-10 19:05 ` Kees Cook [this message]
2024-06-08 8:44 ` David Gow
2024-06-10 19:27 ` Kees Cook
2024-05-19 19:12 ` [PATCH 2/2] usercopy: Convert test_user_copy to KUnit test Kees Cook
2024-05-29 12:17 ` Ivan Orlov
2024-06-10 19:11 ` Kees Cook
2024-06-08 8:44 ` David Gow
2024-06-10 19:48 ` Kees Cook
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=202406101202.3D887825@keescook \
--to=kees@kernel.org \
--cc=brendan.higgins@linux.dev \
--cc=davidgow@google.com \
--cc=gustavoars@kernel.org \
--cc=kunit-dev@googlegroups.com \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=rmoar@google.com \
--cc=vitor@massaru.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.