From: Michal Hocko <mhocko@kernel.org>
To: Jann Horn <jannh@google.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
linux-kernel@vger.kernel.org, Rik van Riel <riel@redhat.com>,
"Peter Zijlstra (Intel)" <peterz@infradead.org>,
Kees Cook <keescook@chromium.org>
Subject: Re: [PATCH] fork: don't copy inconsistent signal handler state to child
Date: Mon, 2 Jul 2018 17:13:46 +0200 [thread overview]
Message-ID: <20180702151346.GD19043@dhcp22.suse.cz> (raw)
In-Reply-To: <20180702145108.73189-1-jannh@google.com>
On Mon 02-07-18 16:51:08, Jann Horn wrote:
> Before this change, if a multithreaded process forks while one of its
> threads is changing a signal handler using sigaction(), the memcpy() in
> copy_sighand() can race with the struct assignment in do_sigaction().
> It isn't clear whether this can cause corruption of the userspace signal
> handler pointer, but it definitely can cause inconsistency between
> different fields of struct sigaction.
>
> Take the appropriate spinlock to avoid this.
>
> I have tested that this patch prevents inconsistency between sa_sigaction
> and sa_flags, which is possible before this patch.
Looks sensible to me.
> Signed-off-by: Jann Horn <jannh@google.com>
Acked-by: Michal Hocko <mhocko@suse.com>
> ---
> I haven't added a CC stable line to this patch because I feel that it
> doesn't quite meet the bar; if anyone disagrees, please say so.
>
>
> kernel/fork.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/kernel/fork.c b/kernel/fork.c
> index 9440d61b925c..4c86e8daae53 100644
> --- a/kernel/fork.c
> +++ b/kernel/fork.c
> @@ -1394,7 +1394,9 @@ static int copy_sighand(unsigned long clone_flags, struct task_struct *tsk)
> return -ENOMEM;
>
> atomic_set(&sig->count, 1);
> + spin_lock_irq(¤t->sighand->siglock);
> memcpy(sig->action, current->sighand->action, sizeof(sig->action));
> + spin_unlock_irq(¤t->sighand->siglock);
> return 0;
> }
>
> --
> 2.18.0.399.gad0ab374a1-goog
>
--
Michal Hocko
SUSE Labs
prev parent reply other threads:[~2018-07-02 15:13 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-02 14:51 Jann Horn
2018-07-02 15:13 ` Michal Hocko [this message]
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=20180702151346.GD19043@dhcp22.suse.cz \
--to=mhocko@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=jannh@google.com \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=riel@redhat.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
all inboxes | Powered by JetHome®