linux-um archives
 help / color / mirror / Atom feed
From: subashab@codeaurora.org
To: Richard Weinberger <richard.weinberger@gmail.com>
Cc: Johannes Berg <johannes@sipsolutions.net>,
	linux-um <linux-um@lists.infradead.org>,
	Johannes Berg <johannes.berg@intel.com>
Subject: Re: [PATCH] um: fix stub location calculation
Date: Tue, 13 Jul 2021 16:28:55 -0600	[thread overview]
Message-ID: <5f24730282175fd833f282ff96983e96@codeaurora.org> (raw)
In-Reply-To: <CAFLxGvxuC61cre6hOg2_-qCe6ArRgOYw0E8q-5ECS=mggoqF0g@mail.gmail.com>

On 2021-07-13 16:11, Richard Weinberger wrote:
> On Tue, Jul 13, 2021 at 11:47 PM Johannes Berg
> <johannes@sipsolutions.net> wrote:
>> 
>> From: Johannes Berg <johannes.berg@intel.com>
>> 
>> In commit 9f0b4807a44f ("um: rework userspace stubs to not hard-code
>> stub location") I changed stub_segv_handler() to do a calculation with
>> a pointer to a stack variable to find the data page that we're using
>> for the stack and the rest of the data. This same commit was meant to
>> do it as well for stub_clone_handler(), but the change inadvertently
>> went into commit 84b2789d6115 ("um: separate child and parent errors
>> in clone stub") instead.
>> 
>> This was reported to not be compiled correctly by gcc 5, causing the
>> code to crash here. I'm not sure why, perhaps it's UB because the var
>> isn't initialized? In any case, this trick always seemed bad, so just
>> create a new inline function that does the calculation in assembly.
> 
> My best guess is that gcc 5 sees only local modifications, but no 
> further reads.
> So it treats it as dead store.
> 
>> Reported-by: subashab@codeaurora.org
>> Fixes: 9f0b4807a44f ("um: rework userspace stubs to not hard-code stub 
>> location")
>> Fixes: 84b2789d6115 ("um: separate child and parent errors in clone 
>> stub")
>> Signed-off-by: Johannes Berg <johannes.berg@intel.com>
> 
> BTW: Marking data/f as volatile fixes the problem too.
> That way gcc no longer optimizes data/f away.
> 
> diff --git a/arch/um/kernel/skas/clone.c b/arch/um/kernel/skas/clone.c
> index 592cdb1..6331941 100644
> --- a/arch/um/kernel/skas/clone.c
> +++ b/arch/um/kernel/skas/clone.c
> @@ -25,7 +25,7 @@ void __attribute__ ((__section__ 
> (".__syscall_stub")))
>  stub_clone_handler(void)
>  {
>         int stack;
> -       struct stub_data *data = (void *) ((unsigned long)&stack &
> ~(UM_KERN_PAGE_SIZE - 1));
> +       volatile struct stub_data *data = (void *) ((unsigned
> long)&stack & ~(UM_KERN_PAGE_SIZE - 1));
>         long err;
> 
>         err = stub_syscall2(__NR_clone, CLONE_PARENT | CLONE_FILES | 
> SIGCHLD,
> diff --git a/arch/x86/um/stub_segv.c b/arch/x86/um/stub_segv.c
> index 21836ea..87c3aef 100644
> --- a/arch/x86/um/stub_segv.c
> +++ b/arch/x86/um/stub_segv.c
> @@ -13,7 +13,7 @@ stub_segv_handler(int sig, siginfo_t *info, void *p)
>  {
>         int stack;
>         ucontext_t *uc = p;
> -       struct faultinfo *f = (void *)(((unsigned long)&stack) &
> ~(UM_KERN_PAGE_SIZE - 1));
> +       volatile struct faultinfo *f = (void *)(((unsigned
> long)&stack) & ~(UM_KERN_PAGE_SIZE - 1));
> 
>         GET_FAULTINFO_FROM_MC(*f, &uc->uc_mcontext);
>         trap_myself();

Both of these work for me. Thanks for the help.

Reported-and-tested-by: Subash Abhinov Kasiviswanathan 
<subashab@codeaurora.org>

_______________________________________________
linux-um mailing list
linux-um@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-um


  reply	other threads:[~2021-07-13 22:29 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-13 21:47 [PATCH] um: fix stub location calculation Johannes Berg
2021-07-13 22:11 ` Richard Weinberger
2021-07-13 22:28   ` subashab [this message]
2021-07-13 22:44   ` YiFei Zhu
2021-07-14  6:51     ` Johannes Berg

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=5f24730282175fd833f282ff96983e96@codeaurora.org \
    --to=subashab@codeaurora.org \
    --cc=johannes.berg@intel.com \
    --cc=johannes@sipsolutions.net \
    --cc=linux-um@lists.infradead.org \
    --cc=richard.weinberger@gmail.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